Datasheet

Chapter 4 • BOE Shield-Bot Navigation
116Robotics with the BOE Shield-Bot
s
ms
speedrobot
distanceobotr
timerunservoms
1000
×=
Modify ForwardOneSecond to make your BOE Shield-Bot travel forward the
amount of time that you determined, and try it out. How close does it come?
Encoders: Increase the accuracy of your BOE Shield-Bot distances with devices called encoders
which count the holes in the BOE Shield-Bot’s wheels as they pass.
Activity 4: Ramping Maneuvers
Ramping is a way to gradually increase or decrease the speed of the servos instead of
abruptly starting or stopping. This technique can increase the life expectancy of both your
BOE Shield-Bot’s batteries and your servos.
Programming for Ramping
The diagram below shows an example of how to ramp up to full speed. The for loop
declares an
int variable named speed, and uses it to repeat the loop 100 times. With each
repetition of the loop, the value of
speed increases by 2 because of the speed+=2 expression
in the
for loop’s increment parameter. Since the speed variable is in
each
writeMicroseconds call’s us parameter, it affects the value each time the for loop
repeats. With the 20 ms delay between each repetition, the loop repeats at about 50 times
per second. That means it takes
speed 1 second to get to 100 in steps of 2, and at that point,
both servos will be going about full speed.
for(int speed = 0; speed <= 100; speed+=2)
{
servoLeft.writeMicroseconds(1500+speed);
servoRight.writeMicroseconds(1500-speed);
delay(20);
}
Let’s take a closer look at the trips through the for loop from this diagram:
First trip:
speed is 0, so both writeMicroseconds calls end up
with
us parameters of 1500.
Second trip:
speed is 2, so we have servoLeft.writeMicroseconds(1502)
and
servoRight.writeMicroseconds(1498).
Third trip:
speed is 4, so we have servoLeft.writeMicroseconds(1504)
and
servoRight.writeMicroseconds(1496).