Need help w/ boe-bot code
im trying to make my boe-bot contolled thru the serial port, and when i hit a key, it goes into autonamous mode, then when i hit the same kay again, or another key, it goes back into tethered control. i have accomplished the first·2 things easily, but the third im not sure of how to do. my code is below
' {$STAMP BS2}
' {$PBASIC 2.5}
'
Variables
MyVar················ VAR·· Nib
InPutVar············· VAR·· Nib
pulseCOUNT·········VAR·· Byte
counter············· ·VAR·· Nib
old7··················· VAR·· Nib
old5··················· VAR·· Nib
'
Declarations
counter = 1
old7 = 0
old5 = 1
'
Pins
Right_Servo_Wheel· PIN 12
Left_Servo_Wheel·· PIN 13
'
Constants
CRMid····················CON 750
CRDeviation··········· CON 225
CRMax·················· CON CRMid + CRDeviation
CRMin·················· CON CRMid - CRDeviation
CRHMid················ CON CRMid + 200
CRLMid················· CON CRMid - 200
CLMid··················· CON 750
CLDeviation··········· CON 225
CLMax·················· CON CLMid + CLDeviation
CLMin··················· CON CLMid - CLDeviation
CLHMid················· CON CLMid + 200
CLLMid·················· CON CLMid - 200
Stopped················ CON 0
Forward················ CON 5
back···················· CON 2
Turn_Right_Sharp··· CON 3
Turn_Left_Sharp··· CON 1
Autopilot············· CON 6
'
'
Manual Operation code
'
DO
· DEBUG CLS
··· InPutVar = Stopped
· SERIN 16, $4054, 30,LoopBegin,[noparse][[/noparse]InPutVar]
· LoopBegin:
··· myvar = InPutVar
· SELECT myvar
·· CASE = Stopped
······ PULSOUT Right_Servo_Wheel, CRMid
······ PULSOUT Left_Servo_Wheel , CLMid
·· CASE = Forward
······ PULSOUT Right_Servo_Wheel, CRMin
······ PULSOUT Left_Servo_Wheel , CLMax
·· CASE = Back
······ PULSOUT Right_Servo_Wheel, CRMax
······ PULSOUT Left_Servo_Wheel , CLMin
·· CASE = Turn_Right_Sharp
······ PULSOUT Right_Servo_Wheel, CRMax
······ PULSOUT Left_Servo_Wheel , CLMax
·· CASE = Turn_Left_Sharp
······ PULSOUT Right_Servo_Wheel, CRMin
······ PULSOUT Left_Servo_Wheel , CLMin
'
END MANUAL OPERATION
;
'
ENTER AUTOPILOT
·· CASE Autopilot
······· DO
········· IF (IN7 <> IN5) THEN
············ IF (old7 <> IN7) AND (old5 <> IN7) THEN
·············· counter = counter + 1
·············· old7 = IN7
·············· old5 = IN5
················· IF (counter > 4) THEN
···················· counter = 1
···················· GOSUB Back_Up
···················· GOSUB Turn_Left
···················· GOSUB Turn_Left
················· ENDIF
············· ELSE
················· counter = 1
·········· ENDIF
········ ENDIF
········· IF (IN5 = 0) AND (IN7 = 0) THEN
············ HIGH 15
············ HIGH 1
············ FREQOUT 4, 250, 3550
············ FREQOUT 4, 200, 3550
············ GOSUB Back_Up
············ GOSUB Turn_Left
············ GOSUB Turn_Left
········· ELSEIF (IN5 = 0) THEN
············ HIGH 15
············ FREQOUT 4, 200, 3575
············ GOSUB Back_Up
············ GOSUB Turn_Right
········· ELSEIF (IN7 = 0) THEN
············ HIGH 1
············ FREQOUT 4, 200, 3575
············ GOSUB Back_Up
············ GOSUB Turn_Left
········· ELSE
············ LOW 15
············ LOW 1
············ GOSUB Forward_Pulse
········· ENDIF
····· LOOP
····· Forward_Pulse:
········· PULSOUT 13, 850
········· PULSOUT 12, 650
········· PAUSE 20
······· RETURN
····· Turn_Left:
······· FOR pulseCount = 0 TO 20
········· PULSOUT 13, 650
········· PULSOUT 12, 650
········· PAUSE 20
······· NEXT
······· RETURN
····· Turn_Right:
······· FOR pulseCount = 0 TO 20
········· PULSOUT 13, 850
········· PULSOUT 12, 850
········· PAUSE 20
······· NEXT
······· RETURN
····· Back_Up:
······· FOR pulseCount = 0 TO 20
········· PULSOUT 13, 650
········· PULSOUT 12, 850
········· PAUSE 20
······· NEXT
······· RETURN
'
END AUTOPILOT
'
'
'
ENTER MANUAL OPERATION
·· CASE ELSE
······ PULSOUT Right_Servo_Wheel, CRMid
······ PULSOUT Left_Servo_Wheel , CLMid
ENDSELECT
LOOP
Post Edited (HavoKane) : 9/20/2005 9:44:04 PM GMT
' {$STAMP BS2}
' {$PBASIC 2.5}
'
Variables
MyVar················ VAR·· Nib
InPutVar············· VAR·· Nib
pulseCOUNT·········VAR·· Byte
counter············· ·VAR·· Nib
old7··················· VAR·· Nib
old5··················· VAR·· Nib
'
Declarations
counter = 1
old7 = 0
old5 = 1
'
Pins
Right_Servo_Wheel· PIN 12
Left_Servo_Wheel·· PIN 13
'
Constants
CRMid····················CON 750
CRDeviation··········· CON 225
CRMax·················· CON CRMid + CRDeviation
CRMin·················· CON CRMid - CRDeviation
CRHMid················ CON CRMid + 200
CRLMid················· CON CRMid - 200
CLMid··················· CON 750
CLDeviation··········· CON 225
CLMax·················· CON CLMid + CLDeviation
CLMin··················· CON CLMid - CLDeviation
CLHMid················· CON CLMid + 200
CLLMid·················· CON CLMid - 200
Stopped················ CON 0
Forward················ CON 5
back···················· CON 2
Turn_Right_Sharp··· CON 3
Turn_Left_Sharp··· CON 1
Autopilot············· CON 6
'
'
Manual Operation code
'
DO
· DEBUG CLS
··· InPutVar = Stopped
· SERIN 16, $4054, 30,LoopBegin,[noparse][[/noparse]InPutVar]
· LoopBegin:
··· myvar = InPutVar
· SELECT myvar
·· CASE = Stopped
······ PULSOUT Right_Servo_Wheel, CRMid
······ PULSOUT Left_Servo_Wheel , CLMid
·· CASE = Forward
······ PULSOUT Right_Servo_Wheel, CRMin
······ PULSOUT Left_Servo_Wheel , CLMax
·· CASE = Back
······ PULSOUT Right_Servo_Wheel, CRMax
······ PULSOUT Left_Servo_Wheel , CLMin
·· CASE = Turn_Right_Sharp
······ PULSOUT Right_Servo_Wheel, CRMax
······ PULSOUT Left_Servo_Wheel , CLMax
·· CASE = Turn_Left_Sharp
······ PULSOUT Right_Servo_Wheel, CRMin
······ PULSOUT Left_Servo_Wheel , CLMin
'
END MANUAL OPERATION
;
'
ENTER AUTOPILOT
·· CASE Autopilot
······· DO
········· IF (IN7 <> IN5) THEN
············ IF (old7 <> IN7) AND (old5 <> IN7) THEN
·············· counter = counter + 1
·············· old7 = IN7
·············· old5 = IN5
················· IF (counter > 4) THEN
···················· counter = 1
···················· GOSUB Back_Up
···················· GOSUB Turn_Left
···················· GOSUB Turn_Left
················· ENDIF
············· ELSE
················· counter = 1
·········· ENDIF
········ ENDIF
········· IF (IN5 = 0) AND (IN7 = 0) THEN
············ HIGH 15
············ HIGH 1
············ FREQOUT 4, 250, 3550
············ FREQOUT 4, 200, 3550
············ GOSUB Back_Up
············ GOSUB Turn_Left
············ GOSUB Turn_Left
········· ELSEIF (IN5 = 0) THEN
············ HIGH 15
············ FREQOUT 4, 200, 3575
············ GOSUB Back_Up
············ GOSUB Turn_Right
········· ELSEIF (IN7 = 0) THEN
············ HIGH 1
············ FREQOUT 4, 200, 3575
············ GOSUB Back_Up
············ GOSUB Turn_Left
········· ELSE
············ LOW 15
············ LOW 1
············ GOSUB Forward_Pulse
········· ENDIF
····· LOOP
····· Forward_Pulse:
········· PULSOUT 13, 850
········· PULSOUT 12, 650
········· PAUSE 20
······· RETURN
····· Turn_Left:
······· FOR pulseCount = 0 TO 20
········· PULSOUT 13, 650
········· PULSOUT 12, 650
········· PAUSE 20
······· NEXT
······· RETURN
····· Turn_Right:
······· FOR pulseCount = 0 TO 20
········· PULSOUT 13, 850
········· PULSOUT 12, 850
········· PAUSE 20
······· NEXT
······· RETURN
····· Back_Up:
······· FOR pulseCount = 0 TO 20
········· PULSOUT 13, 650
········· PULSOUT 12, 850
········· PAUSE 20
······· NEXT
······· RETURN
'
END AUTOPILOT
'
'
'
ENTER MANUAL OPERATION
·· CASE ELSE
······ PULSOUT Right_Servo_Wheel, CRMid
······ PULSOUT Left_Servo_Wheel , CLMid
ENDSELECT
LOOP
Post Edited (HavoKane) : 9/20/2005 9:44:04 PM GMT
Comments
It appears to me that once you enter the Autopilot loop, you never go back to check for any new input from the keypad. The proof of this is that there is only one SERIN statement, and it has no label before it, thus there is no way (short of a reset) to get back to it.
While you are in the Autopilot routine you need to see if there is any new input, by doing another SERIN, and responding accordingly. If there is none, continue on with the Autopilot routine, as before.
Regards,
Bruce Bates
You need a check subroutine in order to enable the bot to exit the autopilot...
Friendly, Provas
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Rule your Destiny-
--Be Good. Be Bad. Be Provas--
once i get the time and money, i plan on making it wireles and adding a webcam on top.
i might make it so i can control it over my wireless network, so i can drive and see around my house from·my laptop while im up in my room. and since i have stairs,i'll make a custom chassis and·i'll probobly pick up 2 tread kits, and·2 more servos so i can make it long enough to do the stairs. but, all this is in the very distant future....
Post Edited (HavoKane) : 9/20/2005 9:49:00 PM GMT
After you have modified your program so that servo pulses are only delivered in one place, you can replace the PAUSE 20 with a SERIN command.· If you have other subroutines that call this one,·they can use the exitFlag bit variable (see example below) to keep returning·upward·until your program gets back to·the main routine.·
NavigateModified:
· FOR counter = 1 to pulseCount
··· PULSOUT 13, pulseLeft
··· PULSOUT 12, pulseRight
··· SERIN 16, $4054, 20,KeepGoing,[noparse][[/noparse]InPutVar]
··· IF inputVar = "q" THEN
····· exitFlag = 1
····· EXIT
··· ELSE
····· exitFlag = 0
··· ENDIF
··· KeepGoing:
· NEXT
RETURN·
Incidentally, I don't think this routine will work perfectly as written.· For example, the exitFlag variable should be set to zero after the KeepGoing label.· Also, InputVar·might not·be the best one to use at this part of the program.·
I would·start with a simple program that just does a repeated maneuver, and make sure you can interrupt the maneuver with a message from your keyboard.· Then add the other features, one by one, until you've built back up to the program you posted to this thread.
Post Edited (Andy Lindsay (Parallax)) : 9/20/2005 10:44:07 PM GMT