
Advanced Robotics with the Toddler (Paralax, student guide, v1.3, 2004)
.pdf
Chapter #8: Real-Time Programming with Bumpers and Infrared · Page 169
You have six wires with which to experiment. You only need two good bumpers so don’t worry if the first ones don’t come out quite right. And if you really destroy all of your wires you can call Parallax for a few more.
critical distance not to exceed
Figure 8-2: Wire bending template
Bend wire exactly as shown
Fine Tuning the Wire Tension: Put the 3/8” screw through the center hole of each Twinkle Toes and secure tightly with a nut on top.
Attach the bumper hook ends over the screw you just mounted in the center of each board. The beveled corner goes on the side with the LED. Slip the wire in-between the prongs (two-post header pins) at each end of the board.
The bumper should be touching the pin closest to the front of the board. When pressing the bumper from the front the wire will touch the pin farthest from the front of the board. The pressure should feel very light to trip the bumper and will need to be adjusted until it is lightly springy.
Figure 8-3 shows how to adjust the bumper wire to be less stiff. For a final adjustment, take the bumper off, adjust and retest the tension. Once both sides of the bumper trip with a soft bump, secure with the locking nut. Do not tighten on the wire; the wire needs to be able to move freely around the screw.

Page 170 · Advanced Robotics with the Toddler
Stiff detection |
Soft detection |
Figure 8-3: Bumper |
Tensioning |
Figure 8-4 and Figure 8-5 show the final installation of the Twinkle Toes.
Figure 8-4: Installed
Twinkle Toes

Chapter #8: Real-Time Programming with Bumpers and Infrared · Page 171
Figure 8-5: Twinkle Toes include the pushbutton resistors and bi-color LED.
Mounting Twinkle Toes Disconnect the tilt rods from the Toddler’s left foot (the same side as the power switch). Mount the Twinkle Toes with two 1/4” screws (the third hole is only used if the ankle is mounted to the inside which would block one of the holes).
Make sure the bumper does not extend past the inside edge of the foot. If it does bend the wire or make a new bumper. One way to find out if the bumper is going to touch the opposite foot is to run one of the early basic walking programs in this text.
Reattach the control rod to the foot then mount the right sensor the same way and make sure it also does not extend past the inside edge of the foot. Repeat for the right foot.
Connect the cables Connect the cables from the sensors to X2 and X3 of the Toddler Board making sure the black to black connection (B to B) is maintained.
Testing the Toddler Toes
Let’s test the Toddler Toes circuit before we proceed to do anything else.

Page 172 · Advanced Robotics with the Toddler
'-----[ Title ]-----------------------------------------------------------
'Toddler Program 8.1 Twinkle Toes Test.bs2
'This program tests twinkle toes bumpers
'{$STAMP BS2}
'{$PBASIC 2.5}
'-----[ Constants ]-------------------------------------------------------
ctrlLEDs |
|
CON |
%1111 |
' Define DIRs as constants |
|
prepBumper |
CON |
%1001 |
|
||
bothGreen |
|
CON |
%0110 |
' OUTa register |
|
bothRed |
|
CON |
%1001 |
|
|
rightRed |
|
CON |
%0101 |
|
|
leftRed |
|
CON |
%1010 |
|
|
bothLEDsOff |
CON |
%1001 |
|
||
' |
-----[ |
Main Code |
]------------------------------------------------------- |
|
|
Forward: |
|
|
|
|
|
|
DIRS = |
ctrlLEDs |
|
|
|
|
OUTS = |
bothGreen |
|
|
|
|
PAUSE 20 |
|
|
|
|
Check_Bumpers: |
|
|
|
||
|
DIRS = |
prepBumper |
|
|
|
|
OUTS = |
bothLEDsOff |
|
||
|
DEBUG Home, "Right = ", BIN1 IN1, " Left = ", BIN1 IN2 |
||||
|
IF (IN1 = 0) AND |
(IN2 = 0) THEN BothOn |
|||
|
IF IN1 |
= 0 THEN Right |
|
||
|
IF IN2 |
= 0 THEN Left |
|
GOTO Forward
BothOn:
DIRS = ctrlLEDs
OUTS = bothRed
PAUSE 200
GOTO Forward
Right:
DIRS = ctrlLEDs
OUTS = rightRed
PAUSE 200
GOTO Forward
Left:
DIRS = ctrlLEDs
OUTS = leftRed
PAUSE 200
GOTO Forward

Chapter #8: Real-Time Programming with Bumpers and Infrared · Page 173
Figure 8-6: Toddler Toes Debug Test. Pushing the bumper should result in a “0” on the I/O pin.
If the Toes are properly installed and wired then you will be able to activate them and view the status of each bumper in the Debug Terminal as shown in Figure 8-6. If it works then proceed. If it does not work then double-check your three-conductor wire connectors and the wiring. The Twinkle Toes should flash green unless you press a bumper, then you will see a green-red intermittent flash.
Testing the Toddler Toes and Infrared Object Detection Circuit Together
Now make sure the infrared emitters and detectors are plugged in the front of the Toddler board. Then, run the following program to test the two circuits together.
'-----[ Title ]-----------------------------------------------------------
'Toddler Program 8.2 Infrared and Twinkle Toes Test.bs2
'This program tests infrared sensors and twinkle toes bumpers together
'{$STAMP BS2}
'{$PBASIC 2.5}
'-----[ I/O Definitions ]-------------------------------------------------
TiltServo |
PIN |
13 |
' tilt servo on X7 |
|
StrideServo |
PIN |
12 |
' stride servo on X6 |
|
LeftIRLED |
PIN |
4 |
' left IRLED |
|
RightIRLED |
PIN |
15 |
' right IRLED |
|
LeftIR_Sensor |
PIN |
11 |
' left IR sensor input |
|
RightIR_Sensor |
PIN |
14 |
' right IR sensor input |
|
LeftBumper |
PIN |
2 |
|
|
RightBumper |
PIN |
1 |
|
|
Spkr |
|
PIN |
8 |
' beeper pin |
' ----- |
[ Constants ] |
------------------------------------------------------- |
|
Page 174 · Advanced Robotics with the Toddler |
|
|||
|
|
|
|
|
MoveDelay |
CON |
17 |
' to make up 20 ms servo loop |
|
CenterTilt |
CON |
750 |
|
|
CenterStride |
CON |
750 |
|
|
prepBumper |
CON |
%1001 |
|
|
bothLEDsOff |
CON |
%1001 |
|
|
' |
-----[ Variables ]------------------------------------------------------- |
|
|
|
Counter |
VAR |
Nib |
|
|
Temp |
VAR |
Bit |
|
|
' |
-----[ Initialize ]------------------------------------------------------ |
|
|
|
ResetFeet: |
|
|
|
|
|
FOR Counter = 1 TO 15 |
|
' center feet for .3 sec |
|
|
GOSUB Move_It |
|
' currentMove is only a nibble. |
|
|
PAUSE MoveDelay |
|
' make up 20 ms servo refresh time |
|
|
NEXT |
|
|
|
Test_Speaker: |
|
|
|
|
|
FREQOUT Spkr, 2000, 3000 |
' program start/restart signal. |
||
' |
-----[ Main Code ]------------------------------------------------------- |
|
|
|
Main_Program: |
|
|
|
|
|
DO |
|
|
|
|
FREQOUT LeftIRLED,1,38500 |
' pulse left IRLED. |
||
|
IF (LeftIR_Sensor = |
0) THEN |
' check for IR hit on left |
|
|
DEBUG " |
IR left |
" |
|
|
ELSE |
|
|
|
|
DEBUG " |
|
" |
|
|
ENDIF |
|
|
|
|
FREQOUT RightIRLED,1,38500 |
' repeat for the right IR pair. |
||
|
IF (RightIR_Sensor = 0) THEN |
' check for IR hit on right |
||
|
DEBUG " |
IR Right |
" |
|
|
ELSE |
|
|
|
|
DEBUG " |
|
" |
|
|
ENDIF |
|
|
|
|
FREQOUT RightIRLED,1,38500 |
' repeat for the right IR pair. |
||
Do_Bumpers: |
|
|
|
|
|
DIRS = prepBumper |
|
|
|
|
OUTS = bothLEDsOff |
|
|

|
Chapter #8: Real-Time Programming with Bumpers and Infrared · Page 175 |
||
|
|
|
|
|
IF (LeftBumper = 0) THEN |
' check for bumper hit on left |
|
|
DEBUG " bump left |
" |
|
|
ELSE |
|
|
|
DEBUG " |
" |
|
|
ENDIF |
|
|
|
IF (RightBumper = 0) THEN |
' check for bumper hit on right |
|
|
DEBUG " bump Right ", CR |
|
|
|
ELSE |
|
|
|
DEBUG " |
", CR |
|
|
ENDIF |
|
|
|
LOOP |
|
|
END |
|
|
|
' |
-----[ Subroutines ]----------------------------------------------------- |
|
|
Move_It: |
|
|
|
|
PULSOUT TiltServo, |
CenterTilt |
|
|
PULSOUT StrideServo, CenterStride |
|
|
|
RETURN |
|
|
This program will allow you to test the I/O connections you just made.
Figure 8-7: Toddler Toes and Infrared Debug Test. The sensors that detect an object will be shown in the Debug Terminal.

Page 176 · Advanced Robotics with the Toddler
ACTIVITY #2: FINITE STATE MACHINE REAL-TIME WALKER
Now you are ready to enter and run Program Listing 8.3, “Toddler Program 8.3 Finite State Machine Walker.bs2”. This program also uses an optional four indicator LEDs on P5 – P8. If you connect the LEDs be sure to use four resistors between the BASIC Stamp I/O pin and LED.
'-----[ Title ]-----------------------------------------------------------
'Toddler Program 8.3: Finite State Machine Walker
'Real time servo programming and sensor integration lets Toddler walk
'until infrared or Toddler Toes detect an object. To walk with bumpers
'only simply remove both infrared emitters on P4 and P15.
'{$STAMP BS2}
'{$PBASIC 2.5}
'-----[ I/O Definitions ]-------------------------------------------------
TiltServo |
PIN |
13 |
' tilt servo on X7 |
StrideServo |
PIN |
12 |
' stride servo on X6 |
LeftIRLED |
PIN |
4 |
' left IRLED |
RightIRLED |
PIN |
15 |
' right IRLED |
LeftIRSensor |
PIN |
11 |
' left IR sensor input |
RightIRSensor |
PIN |
14 |
' right IR sensor input |
RightBumper |
PIN |
1 |
|
LeftBumper |
PIN |
2 |
|
LeftVisionLED |
PIN |
5 |
' left vision display LED |
RightVisionLED |
PIN |
6 |
' right vision display LED |
Spkr |
PIN |
8 |
' beeper pin |
' -----[ Constants ]------------------------------------------------------- |
|||
MoveDelay |
CON |
1 |
' code already using 19 ms of 20 |
TiltStep |
CON |
5 |
' TiltServo step size |
StrideStep |
CON |
5 |
' StrideServo step size |
RightTilt |
CON |
610 |
' tilt limits |
CenterTilt |
CON |
750 |
|
LeftTilt |
CON |
880 |
|
RightStride |
CON |
625 |
' stride limits |
CenterStride |
CON |
750 |
|
LeftStride |
CON |
875 |
|
ctrlLEDs |
CON |
%1111 |
' define DIRs as constants to |

|
|
Chapter #8: Real-Time Programming with Bumpers and Infrared · Page 177 |
|
|
|
|
|
prepBumper |
CON |
%1001 |
' simplify LED/bumper setups |
bothGreen |
CON |
%0110 |
' OUTa register sets red/green |
bothRed |
CON |
%1001 |
' status on P0-P3 for Twinkle Toes |
rightRed |
CON |
%0101 |
' object detection states |
leftRed |
CON |
%1010 |
|
bothLEDsOff |
CON |
%1001 |
|
Fwd |
CON |
0 |
' codes to pick movement table |
PivL |
CON |
1 |
' set newMove to one of these |
PivR |
CON |
2 |
' values and New_Movemt will LOOKUP |
BumpL |
CON |
3 |
' the right movement table |
BumpR |
CON |
4 |
|
' -----[ Variables ]------------------------------------------------------- |
|||
doneTiltFlag |
VAR |
Bit |
' flag: 1 = tilt reached new value |
doneMoveFlag |
VAR |
Bit |
' flag: 1 = servos hit new values |
rightIR_Flag |
VAR |
Bit |
' flag: 1 = something on right side |
leftIR_Flag |
VAR |
Bit |
' flag: 1 = something left side |
rightBumpFlag |
VAR |
Bit |
' flag: 1 = bumper hit right side |
leftBumpFlag |
VAR |
Bit |
' flag: 1 = bumper hit left side |
sensors |
VAR |
Nib |
' lower 2 bits of the sensors var |
|
|
|
' used to store IR detector values |
currentMove |
VAR |
Nib |
|
newMove |
VAR |
Nib |
|
Mx |
VAR |
Word |
' index for movement tables |
MxOffset |
VAR |
Byte |
' added to Mx for index |
bMovmnt |
VAR |
Byte |
' table value for lookup movement |
currentTilt |
VAR |
Word |
|
currentStride |
VAR |
Word |
|
newTilt |
VAR |
Word |
|
newStride |
VAR |
Word |
|
'-----[ EEPROM Data ]-----------------------------------------------------
'These are actual values saved in the Basic Movement tables.
TL |
CON |
0 |
' use lower nibble for these |
TC |
CON |
1 |
|
TR |
CON |
2 |
|
SL |
CON |
3 |
|
SC |
CON |
4 |
|
SR |
CON |
5 |
|
xx |
CON |
255 |
' table end code |
' ------ Basic Movement |
Tables ------ |
|
|
' |
|
|
|

Page 178 · Advanced Robotics with the Toddler
'These tables contain Basic Movements consisting of bytes containing
'above Basic Movement Codes to describe movement sequences.
'An xx indicates the end of a list.
'PivotLeft and PivotRight aren't entered at the start of their tables
Forward |
|
DATA |
TR, SL, TL, SR, xx |
PivotLeft |
DATA |
TR, SL, TL, SR |
|
|
|
DATA |
TC, SL, TL, SR, xx |
PivotRight |
DATA |
TR, SL, TL, SR |
|
|
|
DATA |
TR, SL, TC, SR, xx |
RBumper |
|
DATA |
SL, TR, SR, TC, SL, TL, SR, xx |
LBumper |
|
DATA |
SR, TL, SL, TC, SR, TR, SL, TL, SR, xx |
' ----- |
[ Initialize ] |
------------------------------------------------------ |
GOSUB Clr_Vision DIRS = ctrlLEDs OUTS = bothGreen
'reset vision LEDs and flags
'setup green LEDs for Forward
ResetFeet:
newTilt |
= CenterTilt |
|
|
newStride = CenterStride |
|
||
currentTilt = CenterTilt |
|
||
currentStride = |
CenterStride |
|
|
FOR currentMove |
= 1 TO 15 |
' center feet for .3 sec |
|
GOSUB |
Move_It |
|
' currentMove is only a nibble. |
PAUSE |
17 |
|
' make up 20 ms servo refresh time |
NEXT |
|
|
|
'DEBUG "Forward = ", DEC Forward, CR 'DEBUG "PivotLeft = ", DEC PivotLeft, CR, 'DEBUG "PivotRight = ", DEC PivotRight, CR
'DEBUG "RBumper = ", DEC RBumper, cr, "LBumper = ", DEC LBumper, CR
doneTiltFlag = 1 doneMoveFlag = 1 sensors = 0 MxOffset = 0
FREQOUT Spkr, 2000, 3000 |
' program start/restart signal |
||
rightBumpFlag = 0 |
|
|
|
leftBumpFlag = 0 |
|
|
|
currentMove |
= 15 |
' invalid value to assure start |
|
' newMove = |
Fwd |
' for testing |
single moves - |
' newMove = |
PivL |
' comment out |
GOSUBs to vision |
' newMove = |
PivR |
' and bump or |
the value might be |
' newMove = |
BumpL |
' overwritten |
|
' newMove = |
BumpR |
|
|