Файл: Advanced Robotics with the Toddler (Paralax, student guide, v1.3, 2004).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 1926
Скачиваний: 0
Chapter #7: Staying on the Table · Page 151
The Toddler will also attempt to walk along the edge of the table although this is not explicitly built into the program. In theory, if the Toddler walks perpendicular to the edge it will walk to the edge, back up, walk forward and repeat this indefinitely. In practice, this does not occur for two reasons. The first is that the Toddler’s movement is not perfectly repeatable. As it moves forward and backwards, the Toddler turns slightly to the one side or the other. Eventually the IR sensors will detect the difference and the Toddler will turn instead of backing up or moving forward.
The sensors themselves are another area that will cause the Toddler to turn parallel to the edge of the table. This will occur if one sensor is more sensitive than the other. Of course, this difference will work in one direction and may cause the Toddler to take an extra step forward if the detection is handled by the other side. This will not cause the Toddler to walk off the table though since it tries to stay so far away from the edge. An extra step or two will not cause a problem.
One area that can be a problem especially when the IR LEDs and sensors are pointed forward is that the Toddler will have limited peripheral vision. It is possible for the Toddler to turn parallel to an edge and drift towards the edge. In theory, the sensor on that side should detect the edge and the Toddler will turn away from the edge. This problem occurs more often when the edge of the table is irregular. Aiming the IR LEDs and sensors outward slightly can help eliminate the problem if it occurs.
ACTIVITY #3: TODDLER SHADOW WALKER
For one Toddler to follow another, the Toddler that follows, a.k.a. the shadow walker, has to know how far the lead Toddler is ahead. If the shadow Toddler is lagging behind, it has to detect this and speed up. If the shadow Toddler is too close to the lead Toddler, it has to detect this as well and slow down. If it’s the right distance, it can wait until the measurements indicate it’s too far or too close again.
Unlike the Toddler’s sibling the Boe-Bot, the Toddler moves in discrete steps, not small increments using wheels. Whereas the Boe-Bot uses calculated proportional control, the Toddler must be a bit more discrete. It is possible to take proportional steps but the accuracy of the Toddler’s movements minimizes the effect of minor changes to movements. On the other hand, the Boe-Bot can move one or both of its wheels a fraction of an inch in subsecond times. A Toddler step can take as long as a second.
As it turns out, the Toddler’s IR range finders work well for tracking another Toddler. The range results are in discrete values and the number is not large. If it were, then the
Page 152 · Advanced Robotics with the Toddler
values would have to be converted down to this level of gradation that is manageable. It is then simply a matter of choosing the appropriate step type and magnitude.
The Toddler is a difficult target for another Toddler to locate with its many facets. To improve the detection using the IR sensors, the target Toddler should have a white box placed around it. This can be made of paper or cardboard and it can be affixed to the Toddler’s frame using tape or other means. The box should start about where the base of the Toddler’s central body contains the servos and can extend to just above the circuit board. The IR sensors can be angled down slightly so they will detect the central portion of the box at a distance of about a foot. The box should not impede the foot movement or the servos and it can extend out from the Toddler by as much as a few inches. It should not be too heavy or large so as to significantly change the center of gravity forcing adjustments in walking behavior.
Although these changes are not absolutely required for one Toddler to follow another, they will improve the overall system performance. Also, the roaming area needs to be free of obstacles and walls otherwise the Toddler that will be following may detect these obstacles instead. There is no checking in the program to determine if the object detected is remaining stationary although it is possible to modify the program to do so.
Programming the Toddler Shadow Walker
Program Listing 7.3 uses additional branch and lookup statements to adjust the Toddler’s position based on the range finder results. The movements are designed to aim the Toddler at the object it is following, usually another Toddler, and to keep that object at a discrete distance.
Chapter #7: Staying on the Table · Page 153
Your Turn
√Run Program Listing 7.3.
√Point the Toddler at an 8 ½ x 11” sheet of paper held in front of it as though it’s a wall-obstacle. The Toddler should move about trying to maintain an average distance from the object.
√Try moving the paper so it rotates about the Toddler. The Toddler should rotate with it.
√Try using the sheet of paper to lead the Toddler around. The Toddler should follow it.
'-----[ Title ]-----------------------------------------------------------
'Toddler Program 7.3: Shadow Walker
'Follows another Toddler with a piece of paper on his backside
'{$STAMP BS2}
'{$PBASIC 2.5}
'-----[ I/O Definitions ]-------------------------------------------------
StrideServo |
CON |
12 |
' Stride servo on P12 |
|
TiltServo |
CON |
13 |
' Tilt servo on P13 |
|
left_pin |
CON |
4 |
||
right_pin |
CON |
15 |
||
left_in |
VAR |
IN11 |
||
right_in |
VAR |
IN14 |
||
' ----- |
[ Constants ] |
------------------------------------------------------- |
||
MoveDelay |
CON |
25 |
' in micrcoseconds |
|
TiltStep |
CON |
20 |
' TiltServo step size |
|
StrideStep |
CON |
20 |
' StrideServo step size |
|
RightTilt |
CON |
630 |
' Tilt limits |
|
CenterTilt |
CON |
750 |
||
LeftTilt |
CON |
870 |
||
RightStride |
CON |
650 |
' Stride limits |
|
CenterStride |
CON |
750 |
||
LeftStride |
CON |
850 |
||
Page 154 · Advanced Robotics with the Toddler |
|||||
' ----- |
[ Variables ] |
------------------------------------------------------- |
|||
FigureLoop |
VAR |
Nib |
|||
MoveLoop |
VAR |
Byte |
' Loop for repeat movements |
||
MoveLoopLimit |
VAR |
Byte |
|||
SubMoveLoop |
VAR |
Byte |
' Loop for repeat submovements |
||
SubMoveLoopLmt |
VAR |
Byte |
|||
Pulses |
VAR |
Word |
' Pulse |
variable |
|
CurrentTilt |
VAR |
Word |
|||
CurrentStride |
VAR |
Word |
|||
NewValue |
VAR |
Word |
|||
Dx |
VAR |
Pulses |
|||
Mx |
VAR |
Word |
|||
MxCurrent |
VAR |
Word |
|||
Sx |
VAR |
Word |
|||
SxCurrent |
VAR |
Word |
|||
counter |
VAR ... |
Nib |
' For |
next loop index variable. |
|
l_values |
VAR |
Mx |
' store R sensor vals |
||
r_values |
VAR |
Sx |
' store L sensor vals |
||
l_IR_freq |
VAR |
MxCurrent |
' stores L IR frequencies. |
||
r_IR_freq |
VAR |
SxCurrent |
' stores R IR frequencies |
||
'-----[ Movement Support Codes ]------------------------------------------
'The following state tables are lists of movement state numbers.
'A xx indicates the end of a list.
'These are used with the Movement routine.
TL |
CON |
0 |
TC |
CON |
1 |
TR |
CON |
2 |
SL |
CON |
3 |
SC |
CON |
4 |
SR |
CON |
5 |
xx |
CON |
255 |
' -----[ EEPROM Data ]-----------------------------------------------------
'
' ------ Movement Value Tables ------
' These can be used with the Movement routine. ' The tables can contain Basic Movement Codes.
'
Chapter #7: Staying on the Table · Page 155 |
|||
' Note: ALL movement tables must be in this section |
|||
TurnLeftForward |
DATA |
1, bLeftTurn, |
bForward, xx |
TurnRightForward |
DATA |
1, bRightTurn, bForward, xx |
|
PivotLeftForward |
DATA |
1, bPivotLeft, |
bForward, xx |
PivotRightForward |
DATA |
1, bPivotRight, bForward, xx |
|
BackwardPivotLeft |
DATA |
1, bBackward, bPivotLeft, xx |
|
BackwardPivotRight |
DATA |
1, bBackward, bPivotRight, xx |
|
Forward2 |
DATA |
2, bForward, xx |
|
Backward2 |
DATA |
2, bBackward, xx |
|
'------ Basic Movement Codes ------
'Used in Movement tables.
'Referenced below using LOOKUP statement.
bFinish |
CON |
0 |
bForward |
CON |
1 |
bBackward |
CON |
2 |
bLeftTurn |
CON |
3 |
bRightTurn |
CON |
4 |
bPivotLeft |
CON |
5 |
bPivotRight |
CON |
6 |
'------ Basic Movement Tables ------
'These tables can contain Movement Support Codes.
BasicMovements |
CON |
Forward |
|
Nop |
DATA |
1, xx |
|
Forward |
DATA |
1, TR, SL, TL, SR, xx |
|
Backward |
DATA |
1, TR, SR, TL, SL, xx |
|
LeftTurn |
DATA |
1, TL, SR, TC, SL, TL, SR, |
TR, SL, xx |
RightTurn |
DATA |
1, TR, SL, TC, SR, TR, SL, |
TL, SR, xx |
PivotLeft |
DATA |
3, TL, SR, TC, SL, TR, SR, |
TC, SL, xx |
PivotRight |
DATA |
3, TR, SL, TC, SR, TL, SL, |
TC, SR, xx |
Finish |
DATA |
1, TR, SC, TC, xx |
|
'----- Movement |
LOOKUP entries -------------- |
||
' |
|||
' These constants should reference the appropriate |
movement table. |
||
Page 156 · Advanced Robotics with the Toddler
'The constant syntax is lxry where x and y indicate the range from the
'left and right sensor respectively. A zero value indicates nothing
'is within range while a 5 indicates an object is within inches.
'In general, a 3 will be the closest desirable distance.
l0r0 |
CON |
Forward |
l0r1 |
CON |
TurnRightForward |
l0r2 |
CON |
PivotRightForward |
l0r3 |
CON |
PivotRight |
l0r4 |
CON |
RightTurn |
l0r5 |
CON |
BackwardPivotRight |
l1r0 |
CON |
PivotLeftForward |
l1r1 |
CON |
Forward |
l1r2 |
CON |
PivotRightForward |
l1r3 |
CON |
PivotRight |
l1r4 |
CON |
PivotRight |
l1r5 |
CON |
BackwardPivotRight |
l2r0 |
CON |
TurnLeftForward |
l2r1 |
CON |
TurnLeftForward |
l2r2 |
CON |
Forward |
l2r3 |
CON |
Nop |
l2r4 |
CON |
PivotRight |
l2r5 |
CON |
BackwardPivotRight |
l3r0 |
CON |
PivotLeft |
l3r1 |
CON |
PivotLeft |
l3r2 |
CON |
Nop |
l3r3 |
CON |
Nop |
l3r4 |
CON |
Nop |
l3r5 |
CON |
BackwardPivotRight |
l4r0 |
CON |
BackwardPivotLeft |
l4r1 |
CON |
BackwardPivotLeft |
l4r2 |
CON |
PivotLeft |
l4r3 |
CON |
Nop |
l4r4 |
CON |
Backward |
l4r5 |
CON |
Backward |
l5r0 |
CON |
BackwardPivotLeft |
l5r1 |
CON |
BackwardPivotLeft |
l5r2 |
CON |
BackwardPivotLeft |
l5r3 |
CON |
BackwardPivotLeft |
l5r4 |
CON |
Backward |
l5r5 |
CON |
Backward |
'----- Initialization ------------ |
||
OUTPUT |
2 |
' Declare outputs. |
OUTPUT |
left_pin |
|