Page 206 - Robots Androids and Animatrons : 12 Incredible Projects You Can Build
P. 206

Program 2
                                       ‘Microcontroller 2
                                       b4   150   ‘Initialize servo to midposition
                                       start:
                                       peek 6, b1  ‘Read communication from microcontroller 1
                                       let b0   b1 & 7  ‘Mask out except first 3 bits
                                       if b0   0 then slp  ‘Time to sleep
                                       if b0   1 then rt  ‘Turn right
                                       if b0   2 then lt  ‘Turn left
                                       if b0   3 then fw  ‘Move forward
                                       if b0   4 then avoid  ‘Avoid mode
                                       goto start
                                       slp:
                                       low 4: low 5  ‘Turn off motor
                                       pulsout 3, b4  ‘Maintain servo motor
                                       pause 18  ‘Timing for servo motor
                                       goto start  ‘Read microcontroller 1
                                       rt:   ‘Turn right
                                       high 4: low 5  ‘Move forward
                                              if b4 > 200 then rt1:  ‘Is servo at maximum right?
                                              b4 = b4 + 1  ‘No
                                                                                                          185
                                              rt1:  ‘Yes
                                       pulsout 3, b4  ‘Turn servo
                                       pause 18  ‘Adjust timing (55 Hz)
                                       goto start  ‘Read microcontroller 1
                                       lt:   ‘Turn left
                                       high 4: low 5  ‘Move forward
                                              if b4 < 100 then lt1:  ‘Is servo at maximum left?
                                              b4 = b4  1  ‘No
                                              lt1:  ‘Yes
                                       pulsout 3, b4  ‘Turn servo
                                       pause 18  ‘Adjust timing (55 Hz)
                                       goto start  ‘Read microcontroller 1
                                       fw:   ‘Forward
                                       high 4: low 5  ‘Move forward
                                       pulsout 3, b4  ‘Turn servo
                                       pause 18  ‘Adjust timing (55 Hz)
                                       goto start  ‘Read microcontroller 1
                                       avoid:
                                       low 4: high 5  ‘Move backward
                                       if b4 > 150 then vr  ‘Check steering, veer right?
                                       if b4 <= 150 then vl  ‘Check steering, veer left?
                                       vr:   ‘Veer right
                                                       Team LRN
                                                   Behavioral-based robotics, neural networks, nervous nets, and subsumption architecture
   201   202   203   204   205   206   207   208   209   210   211