Page 200 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 200
Amphibionics 05 3/24/03 8:44 AM Page 179
Chapter 5 / Serpentronic: Build Your Own Robotic Snake
infrared calibration routine. This is so that when the program exe-
cution jumps to the calibration routine, it does not immediately
jump back to the main routine because the operator still has the
button pushed.
The main robot snake control program is called serpentronic.bas
and is listed in Program 5.5. The program operates by constantly
moving the snake in a forward direction, monitoring the infrared
sensor and then responding by turning either left or right if an
obstacle was sensed. Compile serpentronic.bas and then program
the PIC 16F84 with the serpentronic.hex file listed in Program 5.6.
The program can be put into the infrared calibration mode by
holding down the push button.
'------------------------------------------------------------------------------------------------------------------------------
PROGRAM 5.5
' Name : Serpentronic.bas
serpentronic.bas
' Compiler : PicBasic Pro - MicroEngineering Labs
program listing
' Notes : Complete control Program for the robot
' : snake. Mode select push-button switch
' : allows the infrared sensor to be easily
' : calibrated. The robot will stop and turn
' : if an obstacle is encountered.
'------------------------------------------------------------------------------------------------------------------------------
' PortA set as outputs
trisa = %00000000
' PortB set as outputs. pins 0-1 inputs
trisb = %00000011
'------------------------------------------------------------------------------------------------------------------------------
' initialize variables
led_left VAR PORTA.2
led_right VAR PORTA.3
piezo VAR PORTA.4
cal_switch VAR PORTB.0
179