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

Servo sweep program
                                       The demonstration program will sweep the servo rotator left to
                                       right and back again like a radar dish antenna. The schematic is
                                       shown in Fig. 6.26. Here is the PICBASIC compiler program:
                                       ‘Servo motor sweep program
                                       ‘PICBASIC Compiler
                                       ‘Programs sweeps left to right and back again
                                       b0 = 100  ‘Initialize at left position
                                       sweep:   ‘Sweep routine
                                       pulsout 0,b0  ‘Send pulse to servo motor
                                       pause 18  ‘Wait 18 ms (50 to 60 Hz)
                                       b0 = b0 + 1  ‘Increment pulse width
                                       if b0 > 200 then sweepback  ‘End of sweep?
                                       goto sweep  ‘No, continue sweeping
                                       sweepback:  ‘Sweepback routine
                                       b0 = b0 — 1  ‘Decrement pulse width
                                       pulsout 0, b0  ‘Send pulse to servo motor
                                       pause 18  ‘Delay to send 50 to 60 Hz
                                       if b0 < 100 then sweep  ‘End of sweepback
                                       goto sweepback  ‘No
                                       The PICBASIC Pro compiler program is as follows:
                                                                                                          127
                                       ‘Servo motor sweep program
                                       ‘PICBASIC Pro Compiler
                                       ‘Programs sweeps left to right and back again
                                       b0 var byte
                                       b0 = 100  ‘Initialize at left position
                                       sweep:   ‘Sweep routine
                                       pulsout portb.0,b0  ‘Send pulse to servo motor
                                       pause 18  ‘Wait 18 ms (50 to 60 Hz)
                                       b0 = b0 + 1  ‘Increment pulse width
                                       if b0 > 200 then sweepback  ‘End of sweep?
                                       goto sweep  ‘No, continue sweeping
                                       sweepback:  ‘Sweepback routine
                                       b0 = b0 — 1  ‘Decrement pulse width
                                       pulsout portb.0, b0  ‘Send pulse to servo motor
                                       pause 18  ‘Delay to send 50 to 60 Hz
                                       if b0 < 100 then sweep  ‘End of sweepback
                                       goto sweepback  ‘No
                               Fuzzy logic and neural sensors

                                       We are presented with a few interesting possibilities regarding the
                                       interpretation of sensor readings. We can have the microcontroller
                                       mimic the function of neural and/or fuzzy logic devices.
                                                       Team LRN                                      Intelligence
   143   144   145   146   147   148   149   150   151   152   153