Chapter 4: Boe-Bot Navigation
· Page 139
NEXT
' Continue forward for 75 pulses.
FOR pulseCount = 1 TO 75 ' Loop sends 75 forward pulses.
PULSOUT 13, 850 ' 1.7 ms pulse to left servo.
PULSOUT 12, 650 ' 1.3 ms pulse to right servo.
PAUSE 20 ' Pause for 20 ms.
NEXT
' Ramp down from going forward to a full stop.
FOR pulseCount = 100 TO 1 ' Loop ramps down for 100 pulses.
PULSOUT 13, 750 + pulseCount ' Pulse = 1.5 ms + pulseCount.
PULSOUT 12, 750 - pulseCount ' Pulse = 1.5 ms - pulseCount.
PAUSE 20 ' Pause for 20 ms.
NEXT
END ' Stop until reset.
Your Turn
You can also create routines to combine ramping up or down with the 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
pulseCount
is subtracted from 750 in the
PULSOUT
13
command, where before
it was added. Likewise,
pulseCount
is added to the value of 750 in the
PULSOUT 12
command, where before it was subtracted.
' Ramp up to full speed going backwards
FOR pulseCount = 1 TO 100
PULSOUT 13, 750 - pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
NEXT
You can also make a routine for ramping into a turn by adding the value of
pulseCount
to 750 in both
PULSOUT
commands. By subtracting
pulseCount
from 750 in both
PULSOUT
commands, you can ramp into a turn the other direction. Here’s an example of
a quarter turn with ramping. The servos don’t get an opportunity to get up to full speed
before they have to slow back down again.