// PONG TEAM B
//programming by Chris Paxton, Ron McNeil, Ryan Wnuk-Fink
//special thanks to Mr. Moldonato and Mr. Kaisler
//
//2/5/04
//This program should be able to follow a line, and reverse direction
//when it hits something. We have to see how it performs with a robot.
//We have the program working, but it is going in a loop.
//We need to change things.
//---MOTORS---
#define RIGHT_MOTOR A
#define LEFT_MOTOR C
//---SENSORS---
#define LIGHT_SENSOR 3
#define TOUCH_BACK 2
#define TOUCH_FRONT 1
//this (^) is for ease of use later, so when the builders mess things up
//and change the ports, we don't have to go back through the program
//to fix it
//
// Calibrate
// # Arguments: 0
// Arguments: N/A
// Returns: a calibration value
//
// This function calibrates the sensor using a test
// track.
//
int calibrate(int s)
{
int Dark = 0;
int Light = 0;
//defining variables
// Measure dark
printf("Put on Dark Line and press stop\n");
beep();
sleep(3.0);
while (stop_button() != 1) {}
Dark = light(LIGHT_SENSOR);
printf("Dark = %d\n", Dark);
sleep(3.0);
// measure light (just not in inches)
printf("Put on white surface and press stop\n");
beep();// alerts the user
//keep reading until stop button is pushed (The robot, not you!!!!)
while (stop_button() != 1) {}
//read the sensor and display value
Light = light(LIGHT_SENSOR);
printf("Light = %d\n", Light);
sleep(3.0);
//returns calibrated value
return((Dark+Light)/2);
}
//Main:
//Primary function of the program.
//This is the main driver for the whole program.
//It includes the line follow and reverse abitilies.
void main()
{
//variables
int Dark = 0;
int Light = 0;
int Average = 0;
//calibrate the light sensor
Average = calibrate(LIGHT_SENSOR);
// to take over the world, press "ctrl + alt + delete" twice while
//you have alot of vital files that are unsaved
printf("average = %d\n", Average);
sleep(3.0);
//print comment (no,not with a printer) "place bot on dark"
printf("Place bot on dark.");
beep();
sleep(3.0);
//This loop is the primary control loop for our robot
//It makes the robot move along a line, and makes it reverse when
//it hits something (like a brick, tree, other robot, pieces of itself(!), or a meteor stuck in the ground)
while (stop_button() == 0)
{
//while we do not encounter an obstacle... (except for a table edge... crunch!)
while (touch(TOUCH_FRONT) == 0)
{
//read sensor (dark or light) (No, "Sensor" is not the name of a book)
if (light(LIGHT_SENSOR)>= Average)
{
// if dark, go forward left
fd (LEFT_MOTOR), off (RIGHT_MOTOR);//line 98
}
else//if analog (LIGHT_SENSOR) < Average
{
// if light, go fd right
fd (RIGHT_MOTOR), off (LEFT_MOTOR);
//loop to read sensor (No, the robot doesn't travel in a loop)
}
}
//while not encountering any obstacle in reverse (except a cliff or falling meteor)...
while (touch(TOUCH_BACK) == 0)
{
//read light sensor
if (light(LIGHT_SENSOR)>= Average)
{
// reverse to the right (Yes, Ninny, That Way)
bk (LEFT_MOTOR), off (RIGHT_MOTOR);
}
else//if analog(LIGHT_SENSOR) < Average
{
//reverse to the left (no, idiot, the OTHER LEFT!)
bk (RIGHT_MOTOR), off (LEFT_MOTOR);
}
}
}
}