Vous êtes sur la page 1sur 7

Sub Project 8

ETEE 3285
By:
Brandon Maciel
Sub-Project #8

The purpose of this project was to create a library that will instruct the 3Pi to to carry out

specific functions. This can be useful when writing a large program by streamlining the code to

avoid mistakes in writing repetitive code. The library created for this project will enable the 3 Pi

to perform right and left angle turn, or 90 degree turns.

First, the program had to be compiled in AVR Studio 4 in order to verify that no mistakes

were made in writing the right and left angle turns. The program used is shown below in Figure

1.

/*my3piesLib.c*/
#include <pololu/3pi.h>
#include <pololu/analog.h>
#include <pololu/buzzer.h>
#include <pololu/time.h>
#include <pololu/motors.h>
#include <pololu/lcd.h>
#include <pololu/leds.h>
#include <pololu/pushbuttons.h>
#include <pololu/serial.h>

void left_angle_turn();
//void right_angle_turn();

void left_angle_turn()
{

set_motors(-25.23,25.23);
delay_ms(866);
}
void right_angle_turn()
{
set_motors(25.23,-25.23);
delay_ms(866);
}

Figure 1: Library Functions Code


The next step was to build the program in AVR Studio 4, and the print screen is shown below in

Figure 2. Although there was an error, it was just a reference error to the fact that there was

no reference to int main(), which means that there was no actual program made.

Figure 2: Successful Build of Library Functions

The next step was to create an object file for the code shown in Figure 1. This was done by

using the command prompt feature in Microsoft Windows. The command used was avr-gcc –

Os –g –Wall –c omg.c. –Os was a command that created a optimization level, -g was a

command that added debugging information, -Wall was a command that created a warning

level, and –c created the object file from the c file. The C file that contained the functions was

named omg. Because the functions contain functions in other pololu libraries, the pololu

functions. motor (which control the set_motors) and time (which control the delay_ms) were

converted to obj. files using the same method.


Next, the omg.o, motors.o, and delay.o files were written into a archive file. This was done

by using the command prompt. The command to execute this was avr-ar rvs omg.a omg.o

motors.o delay.o. The r was used to replace older o. files with updated ones, the v or “verbose”

displayed the operations on the command prompt screen, and the s created a symbol table

necessary for the gcc. The screenshot of the successful command prompt build of the archive

file is shown below in Figure 3.

Figure 3: Command Prompt Window After the Build of the Archive File

Next, a C header file was made for the archive file. The code is shown below in Figure 4.

#ifndef _omg_h
#define _omg_h

void left_angle_turn();
void right_angle_turn();

#endif

Figure 4: Header File


The next step was to add the archive file in the C:\WinAVR-20100110\avr\lib directory. This

is the actual library, and it was put directly in the WinAVR file for efficiency and ease of finding

it when making programs. Next, the header file was put in the C:\WinAVR-

20100110\avr\include\pololu directory. This was also done for efficiency and ease of locating

it. The library was then ready to be used the 3 Pi program. An example of the use of this library

is shown below in Figure 5.

#include "pololu/omg.h"

#include "pololu/3pi.h"

int main (void)

while(1)

right_angle_turn();

Figure 5: Example of Program using the Library File


Next, I made another library; but without any external library dependencies. I made a

function for adding two numbers and another one for subtracting two numbers. I named the

adding function add.c, and the subtraction function subt.c. The C code is shown below in Figure

6.

int add(int a, int b)


{
int x;
x = a + b;
return x;
}

int subt(int a, int b)


{
int x;
x = a - b;
return x;
}

Figure 6: Add/Subt. C-code

After building the code in Microsoft Visual C++, I put the two files in a folder. Then I made a

header for the two functions, shown in Figure 7.

#ifndef _bzlib_h
#define _bzlib_h

void add();
void subt();

#endif

Figure 7: Add/Subt. Header File

Next, I converted the two .c files into .o files using the same procedure as before. I also did the

same to create an archive file as I did for the right and left turn library. The screenshots of the

command prompt is shown below in Figure 8.


Figure 8: Command Prompt Screen for Add/Subt Conversions to .o and .a Files

Vous aimerez peut-être aussi