Radio Shack Mobile Robot Robotics User Manual


 
Push Buttons and Jumpers (switches)
31
Two general purpose buttons and jumpers (also called switches) are provided on the controller card
which can be read by the Basic Stamp II. Buttons are momentary – after you press them they return to
the off state. Jumpers can be left in the on or off position using the jumper plug or wired to external
switches. Buttons and Jumpers can be use in your program to set certain parameters or modes as
needed. They may be ignored and not used at all. Here is a piece of PBasic example code that reads
them: Notice they are active LOW (LOW=on).
if in12=0 then jmp1on 'If jumper 1 on then jmp1on.
if in13=0 then jmp2on 'If jumper 2 on then jmp2on.
if in14=0 then button1 'If button 1 on then but1on.
if in15=0 then button2 'If button 2 on then but2on.
Drive Motor and Encoder
The drive motor moves the motor forward and backward using the H-Bridge driver circuit (see the con-
troller drawing for location). The H-Bridge is controlled by the coprocessor which receives commands
from the Basic Stamp II using serial I/O commands over the coprocessor network pin – P8. This frees
the Basic Stamp II for other tasks.
An encoder wheel and encoder sensor are used to measure rotation of the drive wheel resulting in dis-
tance measurement. There are 20 encoder slots (counts) per revolution. As it rotates, the slots are de-
tected by the encoder sensor. The drive wheel is about 3-1/2” in diameter, so each count represents
about 1/2” of robot travel – (3.25 x 3.141) / 20. Reading of the encoder is also handled by the coproces-
sor to free up the Basic Stamp II. The count (distance) can be read from the coprocessor by the Basic
Stamp II when needed.
The following PBasic subroutine will show how to control the drive motor through the coprocessor. We
suggest you also study the WANDER and TEST program.
'Drive Motor Control Subroutine.
speed var byte 'Speed variable. '0'-'9', 'A'.
distance var word 'Motor distance variable 0-65535.
direction var byte 'Direction. 1=fwd, 0=rev.
net con 8 'Coprocessor network pin.
baud con 396 'Coprocessor baud rate.
'Subroutine to start drive motor.
'
drivemotor:
serout net,baud,["!1M1", dec1 direction, speed, hex4 distance]
serin net,baud,[char] 'Get "A" back.
return