GIGA Ping Roaming program
I developed a Giga roaming program that uses traits from RoamingWithThePing, and FastIrRoaming.· Now, if the Boe-Bot rolls close to a wall at a tight angle, instead of doing a pan scan, it will just turn out of the way, making it much more faster.· Now it dosn't have to pan-scan at every little object it detects.· However, I has some problems.· When it would·send a pulse to turn, the weel that should turn backward, would just click and stay still.· I put the single pulses into·some subroutines, Click_Left and Click_Right.· Now it just clicks backward at least.· But for dodging small objects quickly, it's fine.· You·might have·to add your own servo pulse values for it to work properly.··
Here's the program: (Note: I could not upload the file, because it said it could not upload msword documents).
' Robotics with the Boe-Bot - GIGARoamingProgram.bs2
' Boe-Bot uses elements from FastIrRoaming and RoamingWithThePing, for an even more
' higher preformance roaming routine.
·
' {$STAMP BS2}······················································· ' Stamp directive.
' {$PBASIC 2.5}························································ ' PBASIC directive.
·
DEBUG "Program Running!"
·
Piezo············ PIN···· 4·································· ············' I/O Definitions.
Ping············· PIN···· 11
PingServo····· PIN···· 14
·
oldDistance··· VAR···· Word······································· ' Variables.
distance········ VAR···· Word
irDetectLeft···· VAR···· Bit
irDetectRight·· VAR···· Bit
counter·········· VAR···· Word
pulseCount···· VAR···· Byte
task·············· VAR···· Nib
·
FREQOUT Piezo, 2000, 3000····································· ' Signal program start.
·
DO··········································································· ' Start.
·
· FREQOUT 8, 1, 38500············································· ' Send pulse.
· irDetectLeft = IN9···················································· ' Store output.
· FREQOUT 2, 1, 38500············································· ' Send pulse.
· irDetectRight = IN0·················································· ' Store output.
·
· IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN···· ' If both sensers detect somthing.
··· GOSUB Ping_Around············································ ' Could mean a wall, so Ping around.
· ELSEIF (irDetectLeft = 0) THEN······························· ' If Left senser detects somthing.
··· GOSUB Click_Right································ ·············' Could mean a wall, so click right.
· ELSEIF (irDetectRight = 0) THEN···························· ' If Right senser detects somthing.
··· GOSUB Click_Left················································ ' Could mean a wall, so click left.
· ELSE···································································· ' If coast is clear.
··· PULSOUT PingServo, 755····································· ' Go forward.
··· PULSOUT 13, 820
··· PULSOUT 12, 650
··· PAUSE 15
· ENDIF
·
· counter = counter + 1·············································· ' Increase passive counter
·
· IF counter > 9 THEN··············································· ' Wait for nine servo pulses
··· GOSUB Ping_Out················································ ' and activate PING))).
· ENDIF
·
· IF (distance > 30) THEN········································· ' If distance is greater then 30
··· PULSOUT 13, 820··············································· ' go forward.
··· PULSOUT 12, 650
··· PAUSE 15
· ELSE·················· ·················································' If not
··· GOSUB Ping_Around·········································· ' Ping around.
· ENDIF
·
LOOP···································································· ' Repeat forever.
·
Click_Right:···························································· ' Subroutines
· FOR pulseCount = 0 TO 1
··· PULSOUT PingServo, 755
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·
Click_Left:
· FOR pulseCount = 0 TO 1
··· PULSOUT PingServo, 755
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
·
Turn_Left:
· FOR pulseCount = 0 TO 7
··· PULSOUT PingServo, 755
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
·
Turn_Right:
· FOR pulseCount = 0 TO 7
··· PULSOUT PingServo, 755
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·
Ping_Out:
· counter = 0
· LOW Ping
· PULSOUT Ping, 5
· PULSIN· Ping, 1, distance
· distance = distance ** 2257
· RETURN
·
Ping_Around:
· counter = 0
· oldDistance = 30
· task = 0
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 1210
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 1
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 950
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 2
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 490
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 3
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 300
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 4
· ENDIF
·
· ON task GOSUB Task0, Task1, Task2, Task3, Task4
·
· distance = 50
·
· RETURN
·
Task0:
· GOSUB Turn_Right
· GOSUB Turn_Right
· GOSUB Turn_Right
· GOSUB Turn_Right
· RETURN
·
Task1:
· GOSUB Turn_Left
· GOSUB Turn_Left
· RETURN
·
Task2:
· GOSUB Turn_Left
· RETURN
·
Task3:
· GOSUB Turn_Right
· RETURN
·
Task4:
· GOSUB Turn_Right
· GOSUB Turn_Right
· RETURN
What do you think?
Here's the program: (Note: I could not upload the file, because it said it could not upload msword documents).
' Robotics with the Boe-Bot - GIGARoamingProgram.bs2
' Boe-Bot uses elements from FastIrRoaming and RoamingWithThePing, for an even more
' higher preformance roaming routine.
·
' {$STAMP BS2}······················································· ' Stamp directive.
' {$PBASIC 2.5}························································ ' PBASIC directive.
·
DEBUG "Program Running!"
·
Piezo············ PIN···· 4·································· ············' I/O Definitions.
Ping············· PIN···· 11
PingServo····· PIN···· 14
·
oldDistance··· VAR···· Word······································· ' Variables.
distance········ VAR···· Word
irDetectLeft···· VAR···· Bit
irDetectRight·· VAR···· Bit
counter·········· VAR···· Word
pulseCount···· VAR···· Byte
task·············· VAR···· Nib
·
FREQOUT Piezo, 2000, 3000····································· ' Signal program start.
·
DO··········································································· ' Start.
·
· FREQOUT 8, 1, 38500············································· ' Send pulse.
· irDetectLeft = IN9···················································· ' Store output.
· FREQOUT 2, 1, 38500············································· ' Send pulse.
· irDetectRight = IN0·················································· ' Store output.
·
· IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN···· ' If both sensers detect somthing.
··· GOSUB Ping_Around············································ ' Could mean a wall, so Ping around.
· ELSEIF (irDetectLeft = 0) THEN······························· ' If Left senser detects somthing.
··· GOSUB Click_Right································ ·············' Could mean a wall, so click right.
· ELSEIF (irDetectRight = 0) THEN···························· ' If Right senser detects somthing.
··· GOSUB Click_Left················································ ' Could mean a wall, so click left.
· ELSE···································································· ' If coast is clear.
··· PULSOUT PingServo, 755····································· ' Go forward.
··· PULSOUT 13, 820
··· PULSOUT 12, 650
··· PAUSE 15
· ENDIF
·
· counter = counter + 1·············································· ' Increase passive counter
·
· IF counter > 9 THEN··············································· ' Wait for nine servo pulses
··· GOSUB Ping_Out················································ ' and activate PING))).
· ENDIF
·
· IF (distance > 30) THEN········································· ' If distance is greater then 30
··· PULSOUT 13, 820··············································· ' go forward.
··· PULSOUT 12, 650
··· PAUSE 15
· ELSE·················· ·················································' If not
··· GOSUB Ping_Around·········································· ' Ping around.
· ENDIF
·
LOOP···································································· ' Repeat forever.
·
Click_Right:···························································· ' Subroutines
· FOR pulseCount = 0 TO 1
··· PULSOUT PingServo, 755
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·
Click_Left:
· FOR pulseCount = 0 TO 1
··· PULSOUT PingServo, 755
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
·
Turn_Left:
· FOR pulseCount = 0 TO 7
··· PULSOUT PingServo, 755
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
·
Turn_Right:
· FOR pulseCount = 0 TO 7
··· PULSOUT PingServo, 755
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·
Ping_Out:
· counter = 0
· LOW Ping
· PULSOUT Ping, 5
· PULSIN· Ping, 1, distance
· distance = distance ** 2257
· RETURN
·
Ping_Around:
· counter = 0
· oldDistance = 30
· task = 0
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 1210
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 1
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 950
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 2
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 490
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 3
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 300
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 4
· ENDIF
·
· ON task GOSUB Task0, Task1, Task2, Task3, Task4
·
· distance = 50
·
· RETURN
·
Task0:
· GOSUB Turn_Right
· GOSUB Turn_Right
· GOSUB Turn_Right
· GOSUB Turn_Right
· RETURN
·
Task1:
· GOSUB Turn_Left
· GOSUB Turn_Left
· RETURN
·
Task2:
· GOSUB Turn_Left
· RETURN
·
Task3:
· GOSUB Turn_Right
· RETURN
·
Task4:
· GOSUB Turn_Right
· GOSUB Turn_Right
· RETURN
What do you think?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I'll post updates as I clean up the code. This code only needs the PING))) and the PING))) bracket. (Sans IR).
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 3/17/2006 10:51:20 PM GMT
Post Edited (SciTech02) : 3/19/2006 10:05:10 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
You can also work with the distance of detection by changing the value of the condition to turn.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
I'm having a bit of trouble controlling the servo with the ping mounted on it. I can't get the roaming program or a program that I have written myself working right. I've been away from my BS2sx for a while and know I'm missing something easy and I can't find anything in the group that relates to my problem. here a sample:
' {$STAMP BS2sx}
' {$PBASIC 2.5}
PULSOUT 10, 1300 'move to position a
PAUSE 2000 'wait 2 sec.
PULSOUT 10, 2700 'move to position b
PAUSE 2000 'wait 2 sec.
END
simple right?
this code is working very oddly, when I delete the position b part of the code it works fine moving the servo to the desired spot. but as soon as I use the whole code the servo moves to the a position and then stops and twitches once like it wants to go to the b position but it then stops. I added some debug line to see what was going on and I get weird output. I also have to hit reset twice quickly for it to work as mentioned. I don't think it's the stamp because I can run other programs on it with no problems. I have tried other i/o lines I have had it powered from the stamp and from a battery with similar results. i have also tried a different servo. I have also verified the position for the roaming software but it behaves wierd also.
What am I missing here? could someone send me some sample code or tell me what I'm doing wrong. I'm at a loss.
Thanks for your help and time
Dave
Although I didn't stop to calculate it, it sounds like 2700 is beyond the end range of the servo.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
·
·· You should start a new post for your question.· Bruce, for the BS2sx that value is in range for the servo, since it uses .8 uS resolution rather than 2 uS resolution.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
thanks for the help.
new topic... sorry meant to start a new thread.