Radio Shack Mobile Robot manual Steering Motor

Page 35

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.

Steering Motor

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

32

Image 35
Contents Assembly and User Guide ARobot Mobile Robot Connectors Basic Stamp II Control Computer IntroductionAbout ARobot What You’ll Need Feature ListTechnical Specifications Precautions Controller Component LocatorGlossary of Terms Glossary of Terms Glossary of Terms Assembly Overview About Screw, nut, and washer sizes PartsQuantity Description Used For Parts Motor Brackets Finish Coat PaintingSanding Paint PrimerHow it Works WhiskersSummary Whisker Detail Full Scale Whisker Wire Pattern Drive Motor and Brackets Encoder Sensor Front Wheel Assembly Steering Motor and Rear Wheels Steering Motor Mounting Wheel and Axle Steering System Controller Board Summary Don’t install batteries yet Battery PackDon’t install batteries yet Body Cable Finishing Up Programming Basic Stamp II InstallationAbout the Controller Board Programming Note Cable to your PCPC Editor/Downloader Software USB PortWander Program WANDER.BS2 Steering Adjustment Program STRAIGHT.BS2Programs Test Program TEST.BS2About the Controller Board Batteries Power On/Off SwitchReset Button Speaker LED indicatorsDrive Motor and Encoder Push Buttons and Jumpers switchesSteering Motor Example !1M11200E7 Coprocessor Command SummaryCoprocessor Communication Rules RC Servo Motor and Steering Motor ControlHexadecimal, Binary, Bytes, Words, etc Pinout Battery Connector J9Body Connector J8 Serial Port J12Voltage 12 volts Maximum Current 500ma Pinout RC Servo Motor Connectors J2-J5Drive Motor Connector J10 Powerful Connector J11Expansion Port RC Servo Motor Signals Expansion Connector J1Expansion Port Circuit Examples Sensor Input Example Switch Input ExampleDigital/Power Output Digital InputsBasic Stamp II light sensor example code Analog InputsCommunications Coprocessor Network ExpansionCabling between ARobot’s controller and another controller Using Other ControllersUsing ARobot’s controller as a coprocessor Suggested Reading Component Suppliers SuperCircuits Sava IndustriesSmall Parts Stock Drive ProductsWeb Sites Internet Robot ResourcesNewsgroup NameDescription Internet News GroupsTroubleshooting Arrick Robotics Warranty InformationRobotics.com