Radio Shack Mobile Robot Robotics User Manual


 
32
The steering is an RC (remote control) style servo motor that is commonly used on model race cars and
airplanes. The coprocessor can control 4 RC servo motors - #1 is used for steering. When the Basic
Stamp II needs to control an RC servo motor, it simply sends a command to the coprocessor which han-
dles the task. This frees up the Basic Stamp II for other tasks.
Here is a subroutine that can be used to control all 4 RC servo motors including the steering motor #1.
Study the WANDER and TEST programs for additional insight.
'Constants and Variables.
net con 8 'coprocessor network pin.
baud con 396 'coprocessor baud rate.
position var byte 'Position of motor.
motor var byte 'Motor #.
'Subroutine to control RC servo motors.
'Motor # 1-4.
'Position = 1-255, 0=off, 128=center.
'The servo is moved to the desired position for 500 ms
'then turned off to conserve power.
'
rcservo:
serout net,baud,["!1R", dec1 motor, hex2 position] 'Move Motor.
serin net,baud,[charn] 'Get A.
pause 500 'Wait for servo to turn.
serout net,baud,["!1R", dec1 motor, "00"] 'Motor off.
serin net,baud,[charn] 'Get A.
return
If you need your RC servo motor to resist movement after it has turned to the desired position, don’t turn
Steering Motor
Drive Motor and Encoder
continued
The previous subroutine will START the drive motor. You can monitor the progress of the drive wheel
by reading the encoder counter from the coprocessor. Here is example code that will read the encoder.
ec var word 'Encoder count.
serout net,baud,["!1E1"] 'Ask for encoder count.
serin net,baud,[hex4, ec] 'Get encoder count into ec.
You can use this code within a loop to wait until the desired distance is completed. Put a 100 ms delay
between reads using a pause 100 command.