Datasheet
Navigating with Infrared Headlights • Chapter 7
Robotics with the BOE Shield-Bot • 237
servoRight.writeMicroseconds(1500 - speedRight); // Right servo speed
if(msTime==-1) // If msTime = -1
{
servoLeft.detach(); // Stop servo signals
servoRight.detach();
}
delay(msTime); // Delay for msTime
}
How FastIrRoaming Works
This sketch uses the maneuver function from the TestManeuverFunction sketch.
The
maneuver function expects three parameters: speedLeft, speedRight, and msTime.
Recall that both speed parameters use 200 for full speed forward, -200 for full speed
backward, and values between -100 and +100 for linear speed control. Also,
remember
msTime values are 20, so each maneuver executes for 20 ms before returning to
the
loop function.
void loop() // Main loop auto-repeats
{
int irLeft = irDetect(9, 10, 38000); // Check for object on left
int irRight = irDetect(2, 3, 38000); // Check for object on right
if((irLeft == 0) && (irRight == 0)) // If both sides detect
{
maneuver(-200, -200, 20); // Backward 20 milliseconds
}
else if(irLeft == 0) // If only left side detects
{
maneuver(200, -200, 20); // Right for 20 ms
}
else if(irRight == 0) // If only right side detects
{
maneuver(-200, 200, 20); // Left for 20 ms
}
else // Otherwise, no IR detects
{
maneuver(200, 200, 20); // Backward 20 ms
}
}