Académique Documents
Professionnel Documents
Culture Documents
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
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 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.
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
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
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
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
#include "pololu/omg.h"
#include "pololu/3pi.h"
while(1)
right_angle_turn();
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.
After building the code in Microsoft Visual C++, I put the two files in a folder. Then I made a
#ifndef _bzlib_h
#define _bzlib_h
void add();
void subt();
#endif
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