Society of Robots - Robot Forum
Software => Software => Topic started by: pomprocker on July 17, 2008, 07:51:28 PM
-
I can't seem to wrap my head around this. When my robot sees something on the right I want it to go left. When it sees something on the left, I want it to go right. When something jumps in front of it, it goes backwards. Don't worry about the values. I just need to know if this is the correct control structure:
while(1) {
scan();
ping();
//Object Avoider
if (PingVal > 8) {
if (sharp_IR_reading > scan_thresh) {
if (scan_angle > 410)
robot_turn_right();
else if (scan_angle < 390)
robot_turn_left();
else
robot_go_back();
} // end if
//object is centered
else
robot_go_straight();
} // end if
else {
while (PingVal < 16) {
robot_go_back();
ping();
}
} // end else
delay_cycles(3200);//a small delay to prevent crazy oscillations -> 400 * 8
} // end while
-
I'm not entirely clear on your setup.
You have a sharp IR as your only sensor, right? I see you included scan_angle, but you have no code to move the sensor . . .
I'd do something like:
IR=get_sensor_value();
//control robot
if (IR > thresh && scan_angle > 410)//sees something on left
turn_right();
else if (IR > thresh && scan_angle < 390)//sees something on right
turn_left();
else if (IR > thresh)//sees something in front
go reverse();//it will oscillate at the threshold here
//control scanner
if (IR < thresh)//doesn't see anything
rotate_left();
else //sees something
rotate_right();
Its a little bit more complicated than this, and you'll have oscillation issues for sure so you'll have to play around with it.
-
I have a parallax ping sonar now too ;D its for when something jumps in front of the robot and the scanner misses it. then it backs up a bit and rescans the area.