Файл: Advanced Robotics with the Toddler (Paralax, student guide, v1.3, 2004).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 1916
Скачиваний: 0
Page 36 · Advanced Robotics with the Toddler
ACTIVITY #1: BASIC WALKING MOVEMENTS: BRUTE FORCE
The Toddler is a walking robot so getting it moving is a good starting point. Figure 2-2 shows a possible order of operation for taking a few steps forward.
Movement 0: |
Movement 1: |
Movement 2: |
Starting Position |
Lean Right from Start |
Lean Right; Left Forward |
Movement 3: |
Movement 4: |
Movement 5: |
Lean Left, Right Back |
Lean Left, Right Forward |
Lean Right, Left Back |
Movement 6:
Lean Right, Left Forward
Figure 2-2: First Steps Movement Patterns
Chapter #2: Taking Your First Steps · Page 37
Once the Toddler has walked Movements 0, 1 and 2 the process of Movements 3, 4, 5 and 6 can repeat to walk in a straight line. The code to perform the first three movements is shown in the following pages. Movements 1 and 2 are almost identical except that one adjusts the tilt and the other the stride. Movements 1, 3 and 5 would use the same code with different values. The same is true for movements 2, 4 and 6.
The M0 routine is unique. It is designed to place the feet of the Toddler on the ground and next to each other regardless of where feet are when the routine starts. This can result in a jerking motion if the legs are not already in or close to this point.
The M1 and M2 routines are representative examples of all the other movement routines in the program. The M1 movement tilts the Toddler to the right. To do so, it sends pulses to both servos. It sends the same pulse width to the stride motor so it remains stationary and the feet do not move forward or backwards. The tilt servo is sent pulses that progressively change in width causing the tilt servo to rotate which in turn causes the Toddler to lean.
The M2 routine does the same thing but in this case the tilt servo is held stationary while the stride servo is driven by a set of different width pulses causing one leg to move ahead of the other.
The program uses constant named definitions for the range of servo pulse width limit values while the examples with small snippets of code use numeric constant values. The effect is the same but the named constants minimize changes to the program when experimenting with different values.
The FOR...NEXT loop uses a STEP modifier in the following pictorial examples. This STEP does not refer to the number of physical Toddler steps taken in the routine, but an increment to the pulse sent to the servo to send it through the desired range of motion.
Page 38 · Advanced Robotics with the Toddler
Starting Position |
Ending Position |
Movement 0 BASIC Stamp Code
M0:
FOR Pulses = 1 TO 100 STEP 5
PULSOUT TiltServo, 750
PULSOUT StrideServo, 750
PAUSE 25
NEXT
Movement 0 Timing Diagram
TiltServo |
1500 us |
1500 us |
1500 us |
1500 us |
1500 us |
+ 5 VDC |
|||||
0 VDC |
|||||
25 ms |
25 ms |
25 ms |
|||
first pulse |
last pulse |
||||
StrideServo |
1500 us |
1500 us |
1500 us |
1500 us |
1500 us |
+ 5 VDC |
|||||
0 VDC |
|||||
25 ms |
25 ms |
25 ms |
|||
first pulse |
last pulse |
Figure 2-3: Movement 0 Example
Chapter #2: Taking Your First Steps · Page 39
Starting Position |
Ending Position |
Movement 1 BASIC Stamp Code
M1:
FOR Pulses = 750 TO 620 STEP 5
PULSOUT TiltServo, Pulses
PULSOUT StrideServo, 750
PAUSE 25
NEXT
Movement 1 Timing Diagram
TiltServo |
1500 us |
1490 us |
1480 us |
1250 us |
1240 us |
+ 5 VDC |
|||||
0 VDC |
|||||
25 ms |
25 ms |
25 ms |
|||
first pulse |
last pulse |
||||
StrideServo |
1500 us |
1500 us |
1500 us |
1500 us |
1500 us |
+ 5 VDC |
|||||
0 VDC |
|||||
25 ms |
25 ms |
25 ms |
|||
first pulse |
last pulse |
Figure 2-4: Movement 1 Example
Page 40 · Advanced Robotics with the Toddler
Starting Position |
Ending Position |
Movement 2 BASIC Stamp Code
M2:
FOR Pulses = 750 TO 850 STEP 5
PULSOUT TiltServo, 620
PULSOUT StrideServo, Pulses
PAUSE 25
NEXT
Movement 2 Timing Diagram
TiltServo |
1240 us |
1240 us |
1240 us |
1240 us |
1240 us |
+ 5 VDC |
|||||
0 VDC |
|||||
25 ms |
25 ms |
25 ms |
|||
first pulse |
last pulse |
||||
StrideServo |
1500 us |
1510 us |
1520 us |
1690 us |
1700 us |
+ 5 VDC |
|||||
0 VDC |
|||||
25 ms |
25 ms |
25 ms |
|||
first pulse |
last pulse |
Figure 2-5: Movement 2 Example
Chapter #2: Taking Your First Steps · Page 41
An example program that performs all the movements for walking forward is shown is shown below. It is possible to adjust the different constants in the program to make the robot walk faster or take bigger steps. Be careful of large changes because the Toddler can fall over. More on that later.
This program also cleans up its movement so both feet are centered and flat on the floor when it is done. This makes starting other programs easier since the feet are in a known position.
'-----[ Title ]-----------------------------------------------------------
'Toddler Program 2.1 - First Steps Forward.bs2
'Run Movement Patters M0 to M8 to take several steps
'{$STAMP BS2}
'{$PBASIC 2.5}
'-----[ Declarations ]----------------------------------------------------
TiltStep |
CON |
5 |
' TiltServo step size |
StrideStep |
CON |
5 |
' StrideServo step size |
MoveDelay |
CON |
25 |
' in micrcoseconds |
RightTilt |
CON |
620 |
' Tilt limits |
CenterTilt |
CON |
750 |
|
LeftTilt |
CON |
880 |
|
RightForward |
CON |
650 |
' Stride limits |
StrideCenter |
CON |
750 |
|
LeftForward |
CON |
850 |
|
StrideServo |
CON |
12 |
' Stride servo on P12 |
TiltServo |
CON |
13 |
' Tilt servo on P13 |
MoveLoop |
VAR |
Nib |
' Repeat movements |
Pulses |
VAR |
Word |
' Pulse variable |
'-----[ Initialization ]
'-----[ Main Routine ]----------------------------------------------------
'Take three full steps. --------------------------------------------------
Main_Program: |
||
GOSUB |
M0 |
' center servos |
GOSUB |
M1 |
' tilt right |
GOSUB |
M2 |
' step left |
FOR |
MoveLoop = 1 to 3 |
|
GOSUB M3 |
' tilt left |
|
GOSUB M4 |
' step right |
|
Page 42 · Advanced Robotics with the Toddler |
||
GOSUB M5 |
' tilt right |
|
GOSUB M6 |
' step left |
|
NEXT |
||
GOSUB M3 |
' tilt left |
|
GOSUB M7 |
' center feet |
|
GOSUB M8 |
' center servos |
|
END |
||
' |
-----[ Subroutines ]----------------------------------------------------- |
|
M0:
FOR Pulses = 1 TO 100 STEP StrideStep
PULSOUT TiltServo, CenterTilt
PULSOUT StrideServo, StrideCenter
PAUSE MoveDelay
NEXT
RETURN
M1:
FOR Pulses = CenterTilt TO RightTilt STEP TiltStep
PULSOUT TiltServo, Pulses
PULSOUT StrideServo, StrideCenter
PAUSE MoveDelay
NEXT
RETURN
M2:
FOR Pulses = StrideCenter TO LeftForward STEP StrideStep
PULSOUT TiltServo, RightTilt
PULSOUT StrideServo, Pulses
PAUSE MoveDelay
NEXT
RETURN
M3:
FOR Pulses = RightTilt TO LeftTilt STEP TiltStep
PULSOUT TiltServo,Pulses
PULSOUT StrideServo, LeftForward
PAUSE MoveDelay
NEXT
RETURN
M4:
FOR Pulses = LeftForward TO RightForward STEP StrideStep
PULSOUT TiltServo,LeftTilt
PULSOUT StrideServo, Pulses
PAUSE MoveDelay
NEXT
RETURN
M5:
Chapter #2: Taking Your First Steps · Page 43
FOR Pulses = LeftTilt TO RightTilt STEP TiltStep
PULSOUT TiltServo,Pulses
PULSOUT StrideServo, RightForward
PAUSE MoveDelay
NEXT
RETURN
M6:
FOR Pulses = RightForward TO LeftForward STEP StrideStep
PULSOUT TiltServo,RightTilt
PULSOUT StrideServo, Pulses
PAUSE MoveDelay
NEXT
RETURN
M7:
FOR Pulses = LeftForward TO StrideCenter STEP StrideStep
PULSOUT TiltServo,LeftTilt
PULSOUT StrideServo, Pulses
PAUSE MoveDelay
NEXT
RETURN
M8:
FOR Pulses = LeftTilt TO CenterTilt STEP TiltStep
PULSOUT TiltServo,Pulses
PULSOUT StrideServo, StrideCenter
PAUSE MoveDelay
NEXT
RETURN
Note that the program is downloaded to the Toddler using the serial cable with the power switch in either the download (1) or run (2) position. The cable can remain connected to the Toddler while it is walking if there is sufficient length to allow it to move freely about the PC. You may want to hold the cable near the Toddler as it does make it slightly less stable. The power on the Toddler should be turned off when disconnecting the cable. The Toddler can then walk on its own when the power is turned on since the program is downloaded into non-volatile memory. You can also program the Toddler with the switch in Position 1, hold the reset button and move it to Position 2 so it will walk.
Three constants could be modified to make it walk quicker: MoveDelay and TiltStep and StrideStep. Decreasing MoveDelay means there will be less pause between the servo pulses. Increasing TiltStep and StrideStep means the servo pulse width changes will be larger (making for fewer pulses to complete the step).