CIS 1.5 (Science Section)

Brooklyn College

Professor Langsam

 

Assignment #3-Robot Exercises

 

 

Programming the Lego RCX ™ Robot using the BrickOS C++ development system consists of using the BrickOS functions (defined in several libraries) together with the standard C++ language. In this assignment you will write several simple programs to control the robot.

 

A Quick Reference Guide to the BrickOS C++ may be found here: http://eilat.sci.brooklyn.cuny.edu/cis1_5/brickos_reference.pdf. We will be using only a small portion of the many functions described in the guide.

 

The following libraries should be included at the top of your programs:

 

#include <conio.h>

#include <unistd.h>

#include <dmotor.h>

 

You will be using the following BrickOS functions in your programs:

 

cls();

cputs(“string”);

motor_x_dir(fwd);

motor_x_dir(rev);

motor_x_dir(off);

motor_x_speed(power)

msleep(time);

sleep(time);

Write individual functions to perform the following tasks:

 

1.      moveFoward(int time, int power) -
The robot should move forward for time seconds at power level power  and then stop.

2.      moveBackwards(int time, int power) –
The robot should move backwards for time seconds at power level power and then stop.

3.      spinRight(int time, int power) –
The robot should spin to the right for time seconds and then stop (The motors should spin in opposite directions.)

4.      spinLeft(int time, int power) –
The robot should spin to the left for time seconds and then stop

5.      uneven(int time, int leftPower, int rightPower) –
The robot should move forward with its left motor on forward at power level leftPower and its right motor on forward at power level rightPower for time seconds and then stop.

 

Have your main program do the following:

 

1.      Call moveFoward followed by moveBackwards. Repeat this 5 times. Use time = 5 seconds and power = 128. Display the direction of travel on the LCD.

2.      Do the same for spinRight and spinLeft.

3.      Call uneven with its left motor on forward at power level 64 and its right motor with power level 32. It should move for 8 seconds and then stop.

4.      When the robot is finished have it display “DONE” on the LCD.

 

 

Test your program using the BrickEMU in the CPlusVEBot system. Submit a printout of your program. Be sure to use meaningful variables, proper style and to comment your program as described in class.