Datasheet
Chapter 8 • Robot Control with Distance Detection
262 • Robotics with the BOE Shield-Bot
int ir = digitalRead(irReceiverPin); // IR receiver -> ir variable
delay(1); // Down time before recheck
return ir; // Return 1 no detect, 0 detect
}
void maneuver(int speedLeft, int speedRight, int msTime)
{
// speedLeft, speedRight ranges: Backward Linear Stop Linear Forward
// -200 -100......0......100 200
servoLeft.writeMicroseconds(1500 + speedLeft); // Left servo speed
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
}
Your Turn – Experiment with the Constants
You can adjust the setpoint and proportionality constants to change the shadow BOE Shield-
Bot’s behavior. Use your hand or a piece of paper to lead the shadow BOE Shield-Bot while
doing these exercises:
Try running FollowingShieldBot using other values of
kpr and kpl constants,
ranging from 15 to 100. Note the difference in how responsive the BOE Shield-
Bot is when following an object.
Try making adjustments to the value of the
setpoint constant. Try values from
0 to 4.
You might notice some odd behaviors. For example, if the setpoint is 0, it won’t back up.
Want to figure out why?
Repeat the control loop exercises from Activity #1 with the setpoint at zero. Can
any measured distance cause it to back up with a set point of zero?
Activity 3: What's Next?
Congratulations! You've made it to the end of the book. Now that you've mastered the
basics, you're ready to start exploring and adding capabilities with your BOE Shield-Bot!
Links to these ideas and more are available from the Arduino-Friendly Products page
at www.parallax.com/product/arduino
.
A few BOE Shield-Bot projects are shown on the next two pages.