Page 71 - The Definitive Guide to Building Java Robots
P. 71
Preston_5564C03.fm Page 52 Wednesday, October 5, 2005 7:21 AM
52 CHAPTER 3 ■ MOTION
In an SSC, you have anywhere from 8–32 servos you can control. You can digitally position
them with byte accuracy (0–255) where 0 would be full Clockwise (CW) and 255 would be full
Counter Clockwise (CCW).
In an ESC, the same digital ranges (0–255) represent the speed of a DC motor forward or
backward. So, depending on how you have the terminals connected, 0 could represent full
speed forward, 255 could be full speed backward, and 127 could signify stopped.
While you can control servos by sending PWM signals via a microcontroller, you are limited
in the number of servos you can control at once usually because you will want to take sensor
readings, make decisions on what way to go, or which actions to take next, and so on. If you
don’t have a servo controller, you can write a BASIC Stamp program that will simulate a servo
controller, but I strongly recommend you get one for Chapter 7.
In Example 3-1, the program will loop in 10-millisecond intervals if nothing is received
from the serial in (SERIN) it moves to old. Because the old values have not been overwritten,
the program sends the old pulsout values to the old pin and pos. This example only works for
one pin at a time.
Example 3-1. servo.bs2
'{$STAMP BS2}
'{$PORT COM1}
pin VAR Byte
oldPin VAR Byte
pos VAR Byte
oldPos VAR Byte
pulse VAR Word
main:
SERIN 16,16468,old,10,[WAIT(255), pin, pos]
pulse = (pos/255)*750
pulsout pin,750+pulse
oldPin = pin
oldPos = pos
GOTO main
old:
pulse = (oldPos/255)*750
pulsout oldPin,750+pulse
GOTO main
This chapter contains 21 Java class examples and the previous BASIC Stamp example. The
first of these will handle access to servo controllers, followed by examples of wheeled robots,
robot arms, and legged robots.
Figure 3-2 shows two continuous rotation servos from Parallax and one Scott Edwards
MiniSSC-II servo controller.
97022d2480fe4a63cfdfa123a6e70098