Hi everyone.I'm new to microcontrollers (and programming for that matter) and am having some difficulty with a project from John Iovine's "Pic Robotics".
The project is a reproduction of William Gray Walter's turtle robot.My issue is more than likely a simple one( and will reveal to you how little I know about this once I get the answer).When looking at the program, I noticed it was
written for the PicBasic Pro.I Have Picbasic.The problem I'm having seems to begin with the definition of variables.Here's the code.
v1 var byte
v2 var byte
s1 var byte
s2 var word
rv var byte
s1 = 150
rv = 10
ct var byte
'drive servomotor**continuous rotation information
'connected to pin portb.**variable pulse width numbers
'157 forward * 165 slow forward
'167 stop
'169 slow backward * 177 backward
start:
pot portb.2,255,v1 'Read resistance of CDS # 1 photocell
pot portb.3,255,v2 'read resistance of CDS # 2 photocell
'Check bumper switch "did I hit something?"
if porta.0 = 0 then avoid 'hit obstacle go into avoid mode
'is it sleepy time?
if v1 <= 230 then skp 'is it dark enough to sleep?
if v2 > 230 then slp 'yes.
'Is it too bright to see?
skp: 'no sleep--keep moving
if v1 >= 12 then skip2 'Is it too bright to live?
if v2 < 12 then avoid 'yes.
'Which way do I go?
skip2: 'Not so bright--should i steer?
if v1 = v2 then straight ' light is equal.go straight.
IF V1 > V2 THEN greater 'check light intensity to turn right
if v1 < v2 then lesser 'check light intensity to turn left
straight: 'Go forward in the direction your facing
pulsout portb 6, s1 'Don't move steering
pulsout portb 7, 157 'Go forward
goto start
greater:
v3 = v1 - v2 'Check numerical difference between Cds cells
if v3 > rv then right 'If more than rv turn right
goto straight 'if not go straight
lesser:
v3 = v2 - v1 'Check numerical difference between CDS cells
if v3 > rv then left 'If more than rv turn left
goto straight 'If not go straight
right: 'Turn right
s1 = s1 + 1 'Increment variable sl to turn right
if sl > 225 then s1 = 225 'limit sl to 225
pulsout portb 6, s1 'move steering servomotor
pulsout portb 7, 165 'Go forward slowly
goto start
slp: 'Go asleep
pulsout portb 6, s1 'Don't move steering
pulsout portb 7, 167 'stop drive servomotor
goto start
avoid: 'avoid mode,send
random s2 'randomize s2
s1 = s2 / 256 'reduce range of s1 to 1 to 255
if s1 < 65 then s1 = 65 'set lower limit
if s1 > 225 then s1 = 225 'set upper limit
for ct = 1 to 125 'start counter
pulsout portb 6, s1 'steer in a random direction
pulsout portb 7, 177 'Reverse drive motor(slow)
pause 18 'Pause to send instructions at 50 Hz
next ct 'loop
s1 = 150 'steer back to center
goto start
...Let me stress that I am not an engineer in any sense of the word.I am actually a special effects artist that is interested in using the pic for servo control.If I could get some input to assist me over what I'm sure is a minor obstacle, I would greatly appreciate it.Thanks
Shawn
Bookmarks