Datasheet

Navigating with Infrared Headlights • Chapter 7
Robotics with the BOE Shield-Bot 235
}
void turnRight(int time) // Right turn function
{
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}
void backward(int time) // Backward function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}
Activity 5: High-performance IR Navigation
The style of pre-programmed maneuvers from the last activity were fine for whiskers, but
are unnecessarily slow when using the IR detectors. With whiskers, the BOE Shield-Bot had
to make contact and then back up to navigate around obstacles. With infrared, your BOE
Shield-Bot will detect most obstacles before it runs into them, and can just find a clear path
around the obstacle.
Increase the Sampling Rate to Avoid Collisions
You can reduce all your maneuver durations to 20 ms, which means your sketch will check
and recheck for objects almost 50 times per second. (It’s actually a little slower, more like 40
times per second, because the code execution and IR detection all takes time too.) As your
BOE Shield-Bot navigates, it will execute a series of small turns to avoid an obstacle before it
ever runs into it. With that approach, it never turns further than it has to, and it can neatly
find its way around obstacles and successfully navigate more complex courses. After
experimenting with this next sketch, you’ll likely agree that it’s a much better way for the
BOE Shield-Bot to roam.
Example Sketch FastIrRoaming
Create, save, and run the sketch FastIrRoaming, then test it with the same
obstacles you used from the previous activity.
/*
* Robotics with the BOE Shield - FastIrRoaming
* Adaptation of RoamingWithWhiskers with IR object detection instead of
* contact switches
*/
#include <Servo.h> // Include servo library