Justin Ratliff's ping robot article
6
a VAR Byte
PING CON 7 'PING sonar port
LEFT CON 3 'left wheel port
RIGHT CON 1 'right wheel port
NECK CON 2 'neck servo port
SPKR CON 8 'speaker port
LED CON 10 'LED mouth, this is not standard on all J2's
'These are for the servo routines
SACT CON 5 'times through act routine
drive VAR Word 'wheel command combo
ldrive VAR drive.BYTE1 'left wheel command
rdrive VAR drive.BYTE0 'right wheel command
aDur VAR Nib 'duration of pulsout
'normal list follows
rv CON $6432 'forward
fd CON $3264 'reverse
st CON $4d4d 'stop
tr CON $324d 'turn right
tl CON $4d64 'turn left
rl CON $6464 'rotate right
rr CON $3232 'rotate left
bl CON $644d 'backup turning left
'wander values
wDir VAR Word 'wander value
wDur VAR Byte 'wander duration
'avoid states and vars
avDir VAR Word 'direction
avDur VAR Nib 'duration
'bumper vars and constants
bumper VAR IN6 'bumper io pin
bstate VAR Nib 'bumper FSM state
bDir VAR Word 'bumper direction holder
bDur VAR Byte 'duration in that direction
'set up for running
wDur = 0 'clear wander duration
aDur = 0 'clear act loop counter
bDur = 1 'clear bumper duration, may need to change back to 0
bstate = 0
drive = st 'stop servo motors - not really needed
LOW LED
main: 'subsumption architecture
GOSUB wander 'random wander instinct is lowest priority
GOSUB avoid 'avoid running into stuff