2009-10-13, 11:36 PM
[COLOR="Red"]Hi guys. In my robot building to take over the world class, my group had to build a robot that follows a tape path. Now, it seemed that the robot followed the code I had in mind, but then started to do weird things. Since the competition is now over, I would like to know where I erred with my code.
This was the normalizing code that translated the light sensor readings into power for the motors:
Now this was the code that was running:
What I wanted the robot to do was to follow the tape path. When both the sensors didn't sense the tape, I wanted the robot to turn left, check for tape, and finding no tape, to turn right and check for tape there.
This went well for the first couple of turns, but then the robot stopped checking left and went straight to right. That is where the problem occurred as the robot then went back to the beginning of the maze.
So, did the robot get stuck in an "if" loop, or what exactly happened? I'm only on my first semester of coding anything so I don't know where I went wrong. This code is in interactive C, which is basically C minus the extra compiling and some other stuff that needs to happen.
Any thoughts?
The winning team had their code being one sensor on and one off, and if the off one sensed the tape to correct itself by turning.
The second place team had both of theirs off, and if either sensed light to avoid it.
Our group got 3rd, which isn't bad, but first would have been nice too.
[/COLOR]
This was the normalizing code that translated the light sensor readings into power for the motors:
Code:
/* normal.c */
/* converts light sensor readings to 0-to-100 motor power levels */
int normalize(int light) {
int MAX_LIGHT= 10;
int MIN_LIGHT= 200;
int LEFT_MOTOR= 0;
int RIGHT_MOTOR= 2;
int RIGHT_EYE= 3;
int LEFT_EYE= 5;
int output= 115 - ((light - MAX_LIGHT ) *100)/ (MIN_LIGHT - MAX_LIGHT);
if (output < 0 ) output= 0;
if (output > 100) output = 100;
return output;
}Now this was the code that was running:
Code:
#include "normal.ic"
void main() {
int MAX_LIGHT= 10;
int MIN_LIGHT= 200;
int LEFT_MOTOR= 0;
int RIGHT_MOTOR= 2;
int RIGHT_EYE= 3;
int LEFT_EYE= 5;
while (1) {
if(normalize(analog(RIGHT_EYE))<20 && normalize(analog(LEFT_EYE)) <20)
{fd(RIGHT_MOTOR);
bk(LEFT_MOTOR);
if(normalize(analog(RIGHT_EYE)) >75 || normalize(analog(LEFT_EYE)) >75)
{fd(LEFT_MOTOR);
fd(RIGHT_MOTOR);}
sleep(0.6);
if(normalize(analog(RIGHT_EYE)) <20 && normalize(analog(LEFT_EYE)) <20)
{fd(LEFT_MOTOR);
bk(RIGHT_MOTOR);
if(normalize(analog(RIGHT_EYE)) >75 || normalize(analog(LEFT_EYE)) >75)
{fd(LEFT_MOTOR);
fd(RIGHT_MOTOR);}
sleep(0.8);} }
motor(LEFT_MOTOR, normalize(analog(RIGHT_EYE)));
motor(RIGHT_MOTOR, normalize(analog(LEFT_EYE)));
printf("Like a robot boss!\n");
}}What I wanted the robot to do was to follow the tape path. When both the sensors didn't sense the tape, I wanted the robot to turn left, check for tape, and finding no tape, to turn right and check for tape there.
This went well for the first couple of turns, but then the robot stopped checking left and went straight to right. That is where the problem occurred as the robot then went back to the beginning of the maze.
So, did the robot get stuck in an "if" loop, or what exactly happened? I'm only on my first semester of coding anything so I don't know where I went wrong. This code is in interactive C, which is basically C minus the extra compiling and some other stuff that needs to happen.
Any thoughts?
The winning team had their code being one sensor on and one off, and if the off one sensed the tape to correct itself by turning.
The second place team had both of theirs off, and if either sensed light to avoid it.
Our group got 3rd, which isn't bad, but first would have been nice too.
[/COLOR]
