Page 126 ·
Robotics with the Boe-Bot
This
FOR…NEXT
loop sends 122 sets of pulses to the servos, one each to P13 and P12,
pausing for 20 ms after each set and then returning to the top of the loop.
FOR counter = 1 TO 122
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
PULSOUT 13, 850
causes the left servo to rotate counterclockwise while
PULSOUT 12,
650
causes the right servo to rotate clockwise. Therefore, both wheels will be turning
toward the front end of the Boe-Bot, causing it to drive forward. It takes about 3 seconds
for the
FOR…NEXT
loop to execute 122 times, so the Boe-Bot drives forward for about 3
seconds.
Your Turn – Adjusting Distance and Speed
√
By changing the
FOR…NEXT
loop’s
EndValue
argument from 122 to 61, you can
make the Boe-Bot move forward for half the time. This in turn will make the
Boe-Bot move forward half the distance.
√
Save BoeBotForwardThreeSeconds.bs2 under a new name.
√
Change the
FOR
...
NEXT
loop's
EndValue
from 122 to 61.
√
Run the program and verify that it ran at half the time and covered half the
distance.
√
Try these steps over again, but this time, change the
FOR…NEXT
loop’s
EndValue
to 244.
The
PULSOUT
Duration
arguments of 650 and 850 caused the servos to rotate near their
maximum speed. By bringing each of the
PULSOUT
Duration
arguments closer to the
stay-still value of 750, you can slow down your Boe-Bot.
√
Modify your program with these
PULSOUT
commands:
PULSOUT 13, 780
PULSOUT 12, 720
√
Run the program, and verify that your Boe-Bot moves slower.