Datasheet
Chapter 7 • Navigating with Infrared Headlights
242 • Robotics with the BOE Shield-Bot
servoRight.detach();
}
delay(msTime); // Delay for msTime
}
How AvoidTableEdge Works
Since AvoidTableEdge is just FastIrRoaming with a modified if…else if…else statement in
its
loop function, let’s look at the two statements side by side.
// From FastIrRoaming
if((irLeft == 0) && (irRight == 0))
{
maneuver(-200, -200, 20);
}
else if(irLeft == 0)
{
maneuver(200, -200, 20);
}
else if(irRight == 0)
{
maneuver(-200, 200, 20);
}
else
{
maneuver(200, 200, 20);
}
//From AvoidTableEdge
if((irLeft == 0) && (irRight == 0))
{
maneuver(200, 200, 20);
}
else if(irLeft == 0)
{
maneuver(-200, 200, 375);
}
else if(irRight == 0)
{
maneuver(200, -200, 375);
}
else
{
maneuver(-200, -200, 250);
}
}
In response to
if((irLeft == 0) && (irRight == 0)), FastIrRoaming backs up
with
maneuver(-200, -200, 20) because both IR detectors see an obstacle. In contrast,
AvoidTableEdge goes forward with
maneuver(200, 200, 20) because both IR detectors
see the table, which means it’s safe to move forward for another 20 ms.
In response to else
if(irLeft == 0), FastIrRoaming turns right for 20 ms, taking a step
toward avoiding an obstacle on the left with
maneuver(200, -200, 20). AvoidTableEdge
instead turns away from a drop-off that must be on its right. That’s because the
first
if statement where both IR detectors could see the table was not true. If it was, the
if…else if…else
statement would not have made it to this else if condition. It means