Help with autopilot
Googfan
Posts: 16
Hi i'm building a souped up boebot and i have a problem, when i·push the autopilot button [noparse][[/noparse]#21 - power] the robot begins roaming, but stops when i let go. I have a place in the code to exit autopilot BUT-- only when button 59 is pushed (mute). From the looks of things, my code should work
It roams using PING))), and well, i dont want to hold the aoutopilot button.
OH, it uses an IR remote, (sony)
······· |
code \/
' {$STAMP BS2}
' {$PBASIC 2.5}
'variables
time········ VAR Word
irPulse····· VAR Word
topservo···· VAR Word
remoteCode·· VAR Byte
pulsecount·· VAR Byte
turncountl·· VAR Nib
turncountr·· VAR Nib
FREQOUT 4,2000,3000
turncountl = 0
turncountr = 0
'Main routine
Main:
DO
· GOSUB getremote
· IF (remoteCode = 2) THEN GOSUB forwardpulse
· IF (remoteCode = 8) THEN GOSUB backpulse
· IF (remoteCode = 4) THEN GOSUB leftpulse
· IF (remoteCode = 6) THEN GOSUB rightpulse
· IF (remoteCode = 21)THEN GOSUB autopilot
· IF (remotecode = 18) THEN topservo = topservo + 100
· IF (remotecode = 19) THEN topservo = topservo - 100
· topservo = topservo MIN 150
· topservo = topservo MAX 1200
· PULSOUT 14, topservo
LOOP
'MajorSubprograms
getremote:
remoteCode = 0
DO
· RCTIME 9, 1, irPulse
LOOP UNTIL irPulse > 1000
··· PULSIN 9, 0, irPulse
· IF irPulse > 500 THEN remoteCode.BIT0 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT1 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT2 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT3 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT4 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT5 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT6 = 1
· IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
· IF (remoteCode = 10) THEN remoteCode = 0
RETURN
autopilot:
DO
· IF (turncountr > 2) AND (turncountl > 2)· THEN
··· turncountl = 0
··· turncountr = 0
· ENDIF
· PULSOUT 15, 5
· PULSIN 15, 1, time
· time = time ** 750
· IF (time < 12) THEN
··· IF (turncountl < 3) THEN
····· GOSUB turnleft
····· turncountl = turncountl + 1
··· ELSE
····· GOSUB turnright
····· turncountr = turncountr + 1
··· ENDIF
· ELSE
··· GOSUB forward
· ENDIF
· GOSUB getremote
· IF (remoteCode = 59) GOTO Main
LOOP
'autop subprograms
forward:
FOR pulsecount = 1 TO 20
· PULSOUT 13,840
· PULSOUT 12,650
· PAUSE 10
NEXT
RETURN
turnleft:
FOR pulsecount = 1 TO 20
· PULSOUT 13,650
· PULSOUT 12,650
· PAUSE 20
NEXT
RETURN
turnright:
FOR pulsecount = 1 TO 20
· PULSOUT 13,840
· PULSOUT 12,840
· PAUSE 20
NEXT
RETURN
backup:
FOR pulsecount = 1 TO 20
· PULSOUT 13,650
· PULSOUT 12,840
· PAUSE 10
NEXT
RETURN
'manual subprograms
leftpulse:
· PULSOUT 13,650
· PULSOUT 12,650
· PAUSE 10
· RETURN
rightpulse:
· PULSOUT 13,840
· PULSOUT 12,840
· PAUSE 10
· RETURN
forwardpulse:
· PULSOUT 13,840
· PULSOUT 12,650
· PAUSE 10
· RETURN
backpulse:
· PULSOUT 13,650
· PULSOUT 12,840
· PAUSE 10
· RETURN
It roams using PING))), and well, i dont want to hold the aoutopilot button.
OH, it uses an IR remote, (sony)
······· |
code \/
' {$STAMP BS2}
' {$PBASIC 2.5}
'variables
time········ VAR Word
irPulse····· VAR Word
topservo···· VAR Word
remoteCode·· VAR Byte
pulsecount·· VAR Byte
turncountl·· VAR Nib
turncountr·· VAR Nib
FREQOUT 4,2000,3000
turncountl = 0
turncountr = 0
'Main routine
Main:
DO
· GOSUB getremote
· IF (remoteCode = 2) THEN GOSUB forwardpulse
· IF (remoteCode = 8) THEN GOSUB backpulse
· IF (remoteCode = 4) THEN GOSUB leftpulse
· IF (remoteCode = 6) THEN GOSUB rightpulse
· IF (remoteCode = 21)THEN GOSUB autopilot
· IF (remotecode = 18) THEN topservo = topservo + 100
· IF (remotecode = 19) THEN topservo = topservo - 100
· topservo = topservo MIN 150
· topservo = topservo MAX 1200
· PULSOUT 14, topservo
LOOP
'MajorSubprograms
getremote:
remoteCode = 0
DO
· RCTIME 9, 1, irPulse
LOOP UNTIL irPulse > 1000
··· PULSIN 9, 0, irPulse
· IF irPulse > 500 THEN remoteCode.BIT0 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT1 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT2 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT3 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT4 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT5 = 1
··· RCTIME 9, 0, irPulse
· IF irPulse > 300 THEN remoteCode.BIT6 = 1
· IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
· IF (remoteCode = 10) THEN remoteCode = 0
RETURN
autopilot:
DO
· IF (turncountr > 2) AND (turncountl > 2)· THEN
··· turncountl = 0
··· turncountr = 0
· ENDIF
· PULSOUT 15, 5
· PULSIN 15, 1, time
· time = time ** 750
· IF (time < 12) THEN
··· IF (turncountl < 3) THEN
····· GOSUB turnleft
····· turncountl = turncountl + 1
··· ELSE
····· GOSUB turnright
····· turncountr = turncountr + 1
··· ENDIF
· ELSE
··· GOSUB forward
· ENDIF
· GOSUB getremote
· IF (remoteCode = 59) GOTO Main
LOOP
'autop subprograms
forward:
FOR pulsecount = 1 TO 20
· PULSOUT 13,840
· PULSOUT 12,650
· PAUSE 10
NEXT
RETURN
turnleft:
FOR pulsecount = 1 TO 20
· PULSOUT 13,650
· PULSOUT 12,650
· PAUSE 20
NEXT
RETURN
turnright:
FOR pulsecount = 1 TO 20
· PULSOUT 13,840
· PULSOUT 12,840
· PAUSE 20
NEXT
RETURN
backup:
FOR pulsecount = 1 TO 20
· PULSOUT 13,650
· PULSOUT 12,840
· PAUSE 10
NEXT
RETURN
'manual subprograms
leftpulse:
· PULSOUT 13,650
· PULSOUT 12,650
· PAUSE 10
· RETURN
rightpulse:
· PULSOUT 13,840
· PULSOUT 12,840
· PAUSE 10
· RETURN
forwardpulse:
· PULSOUT 13,840
· PULSOUT 12,650
· PAUSE 10
· RETURN
backpulse:
· PULSOUT 13,650
· PULSOUT 12,840
· PAUSE 10
· RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later youwill get it RIGHT
thats because autopilot is a loop and will continue forever untill it is exited by·GOTO Main
· IF (remoteCode = 59) GOTO Main
its supposed to be
·
GOSUB getremote
· IF (remoteCode = 59) THEN GOTO Main
it still doesn't work though
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
So, if you're not holding down a button on the remote, you return "zero" to the "top level".
A "zero" for "RemoteCode" does nothing at the top level -- thus your robot stops.
Probably, the default should be 21 "Auto-Pilot".
What did you do?
It's also possible your code is "hanging" in the IR reader -- I'm not sure how it determines when there's NO IR being recieved.
Also, [noparse][[/noparse]totally off topic] i just realized, Boe-Bots and the Erector set make a perfect combo. You can build boving arms and stuff attached to the chassis
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
oh and the remoteCode = 0 is nescessary otherwise the servos go mad.
autopilot:
DO
IF (turncountr > 2) AND (turncountl > 2) THEN
turncountl = 0
turncountr = 0
ENDIF
PULSOUT 15, 5
PULSIN 15, 1, time
time = time ** 750
IF (time < 12) THEN
IF (turncountl < 3) THEN
GOSUB turnleft
turncountl = turncountl + 1
ELSE
GOSUB turnright
turncountr = turncountr + 1
ENDIF
ELSE
GOSUB forward
ENDIF
GOSUB getremote
IF (remoteCode = 59) THEN
RETURN
ENDIF
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
oh and
GOSUB getremote
IF (remoteCode = 59) THEN
RETURN <-- its not a true subrogram in a stack
ENDIF
LOOP
i used GOTO Main to conserve stacking space.
You should remove the DO and LOOP and change the last two lines to:
IF (remoteCode <> 59) GOTO autopilot
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thanks
NosePicker
DO
· RCTIME 9, 1, irPulse
LOOP UNTIL irPulse > 1000
This loop will just sit there and wait until it sees the IR remote. You need to change it to something like this:
Define a variable Counter as a byte.
counter=0
DO
· RCTIME 9, 1, irPulse
· counter = counter + 1
· PAUSE 10
LOOP UNTIL (irPulse > 1000) OR (counter > 20)
You can adjust the Pause statement and the value of counter to get a reasonable operation, although there will always be some hesitation of the robot while its checking to see if the remote is being pressed. I have some similar code and just decided that once I put it into autopilot, I'll chase it down and hit the reset button.
Post Edited (MSDTech) : 7/10/2008 1:37:08 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
or if you can't put a debug in for some reason, put in an infinite loop to stop everything:
If everything stops, you know remoteCode is 59, and that your loop is fine, but the getremote is wrong.
Also note, that a gosub will add to the stack. The goto in "IF (remoteCode = 59) GOTO Main" does not remove the previos gosub from the stack. So you will eventually run out of stack space.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mixing things...
It can be deadly -- Potassium Carbon Nitrogen [noparse][[/noparse]KCN]
It can be fun
·Potassium Nitrogen Oxogen Carbon Sulfer [noparse][[/noparse]KNO3+C+S]
It can be useless - Napkin Butter
wait, what point was I·trying to establish?
·