Name: Anonymous 2010-12-01 23:38
So I'm making a robot follow a line using an IR sensor.
This is the main part of the program, every other function is listed in their own voids.
I can't test it out because the robots aren't available yet. Are there any like "OH SHIT NIGGER WHAT ARE YOU DOING" errors?
PROGRAM:
void GoForward() //Self Explainatory
{
mav(0,300);
mav(3,300);
}
void SeekLeft()
{
mav(0,-200);
mav(3,200);
sleep(0.8);
}
void SeekRight()
{
mav(0,200);
mav(3,-200);
sleep(0.8);
}
void ReturnLeft()
{
SeekRight();
}
void ReturnRight()//SeekLeft, SeekRight, ReturnLeft, and ReturnRight are used to correct the robot if it goes off of the line
{
SeekLeft();
}
void FinalAttempt() //The robot flails around to the left endlessly
{
mav(0,500);
mav(3,-500);
}
void FollowLine()
{
while(1) //Makes the program always happen
{
GoForward(); //It moves forward until
}
if(analog(3)<180) //The sensor shows a value of <180 (light) meaning it has moved off of the tape, then it will
{
SeekLeft(); //Turn to the left very briefly
if(analog(3)>180)//If the sensor shows a value of >180 (dark) meaning it is back on the tape, it will
{
printf("Line found; Curving to the left.\n"); //Display this on the screen
return; //go back to main, which makes it go forward again
}
ReturnLeft();//If turning right fails, it will center itself again, and then
SeekRight();
if(analog(3)>180)
{
printf("Line found; Curving to the Right.\n");
return; //Same thing as before. However, if it fails to detect the line a second time after turning,
}
ReturnRight(); //It centers itself, and then
FinalAttempt(); //Flails around trying to find some sort of line
if(analog(3)>180)
{
printf("Line Found on Final Attempt. WARNING: Robot is probably following line in opposite direction.\n");
return;
}
ao(); //If that fails, which shouldn't happen, then it will just shut off.
printf("Error: Line lost. Write a better program!/n");
}
}
int main()
{
FollowLine(); //Runs the FollowLine program. Just a way of making things simple in the main.
}
This is the main part of the program, every other function is listed in their own voids.
I can't test it out because the robots aren't available yet. Are there any like "OH SHIT NIGGER WHAT ARE YOU DOING" errors?
PROGRAM:
void GoForward() //Self Explainatory
{
mav(0,300);
mav(3,300);
}
void SeekLeft()
{
mav(0,-200);
mav(3,200);
sleep(0.8);
}
void SeekRight()
{
mav(0,200);
mav(3,-200);
sleep(0.8);
}
void ReturnLeft()
{
SeekRight();
}
void ReturnRight()//SeekLeft, SeekRight, ReturnLeft, and ReturnRight are used to correct the robot if it goes off of the line
{
SeekLeft();
}
void FinalAttempt() //The robot flails around to the left endlessly
{
mav(0,500);
mav(3,-500);
}
void FollowLine()
{
while(1) //Makes the program always happen
{
GoForward(); //It moves forward until
}
if(analog(3)<180) //The sensor shows a value of <180 (light) meaning it has moved off of the tape, then it will
{
SeekLeft(); //Turn to the left very briefly
if(analog(3)>180)//If the sensor shows a value of >180 (dark) meaning it is back on the tape, it will
{
printf("Line found; Curving to the left.\n"); //Display this on the screen
return; //go back to main, which makes it go forward again
}
ReturnLeft();//If turning right fails, it will center itself again, and then
SeekRight();
if(analog(3)>180)
{
printf("Line found; Curving to the Right.\n");
return; //Same thing as before. However, if it fails to detect the line a second time after turning,
}
ReturnRight(); //It centers itself, and then
FinalAttempt(); //Flails around trying to find some sort of line
if(analog(3)>180)
{
printf("Line Found on Final Attempt. WARNING: Robot is probably following line in opposite direction.\n");
return;
}
ao(); //If that fails, which shouldn't happen, then it will just shut off.
printf("Error: Line lost. Write a better program!/n");
}
}
int main()
{
FollowLine(); //Runs the FollowLine program. Just a way of making things simple in the main.
}