Datasheet
Chapter 4 • BOE Shield-Bot Navigation
118 • Robotics with the BOE Shield-Bot
Your Turn – Add Ramping to Other Maneuvers
You can also create routines to combine ramping with other maneuvers. Here’s an example
of how to ramp up to full speed going backward instead of forward. The only difference
between this routine and the forward ramping routine is that the value of
speed starts at
zero and counts to –100.
for(int speed = 0; speed >= -100; speed -= 2)// Ramp stop to reverse
{
servoLeft.writeMicroseconds(1500+speed); // us = 1500...1400
servoRight.writeMicroseconds(1500-speed); // us = 1500...1600
delay(20); // 20 ms at each speed
}
You can also make a routine for ramping into and out of a turn. Here is a right-turn ramping
example. Notice that instead of
1500+speed for one wheel and 1500–speed for the other,
now they are both
1500+speed. For left-turn ramping, they would both be 1500–speed.
for(int speed = 0; speed <= 100; speed += 2) // Ramp stop to right turn
{
servoLeft.writeMicroseconds(1500+speed); // us = 1500...1600
servoRight.writeMicroseconds(1500+speed); // us = 1500...1600
delay(20); // 20 ms at each speed
}
for(int speed = 100; speed >= 0; speed -= 2)// right turn to stop
{
servoLeft.writeMicroseconds(1500+speed); // us = 1600...1500
servoRight.writeMicroseconds(1500+speed); // us = 1600...1500
delay(20); // 20 ms at each speed
}
Open the sketch ForwardLeftRightBackward and save it as
ForwardLeftRightBackwardRamping.
Modify the new sketch so your BOE Shield-Bot will ramp into and out of each
maneuver. Hint: you might use the code snippets above, and similar snippets
from StartAndStopWithRamping.
Activity 5: Simplify Navigation with Functions
One convenient way to execute pre-programmed maneuvers is with functions. In the next
chapter, your BOE Shield-Bot will have to perform maneuvers to avoid obstacles, and a key
ingredient for avoiding obstacles is executing pre-programmed maneuvers.
The
setup and loop functions are built into the Arduino language, but you can add more
functions that do specific tasks for your sketch. This activity introduces how to add more