Hepl with PING))
I bought a Boe-Bot with a Rev J chip and I've had the hardest time getting the PING)) programs to work properly. First, the program to run the PING)) with encoders wouldn't work properly until I changed the advanceForward subroutine by adding a pause 30. Now I am trying to run the RoamingWithPing program with my IR sensors and it wont got forward, it just turns either the right or left. I need help please!!!!
Comments
' RoamingWithPING.bs2
' Roam And Scan Using PING))) Mounting Bracket
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ I/O Definitions ]
Piezo PIN 4
RightServo PIN 12
LeftServo PIN 13
PingServo PIN 14
Ping PIN 15
'
[ Variables ]
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
distance VAR Word
oldDistance VAR Word
counter VAR Word
task VAR Nib
'
[ Initialization ]
FREQOUT Piezo, 2000, 3000
'
[ Program Code ]
Main:
DO
FREQOUT 8, 1, 38500
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Ping_Around
ELSEIF (irDetectLeft = 0) THEN
GOSUB Ping_Around
ELSEIF (irDetectRight = 0) THEN
GOSUB Ping_Around
ENDIF
counter = counter + 1
IF counter > 10 THEN
GOSUB Ping_Out
ENDIF
IF (distance > 30) THEN
GOSUB Forward_Pulse
ELSE
GOSUB Ping_Around
ENDIF
LOOP
'
[ Subroutines ]
Forward_Pulse:
PULSOUT PingServo, 750
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 20
RETURN
Turn_Left:
FOR pulseCount = 0 TO 7
PULSOUT PingServo, 750
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 7
PULSOUT PingServo, 750
PULSOUT LeftServo, 850
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT PingServo, 750
PULSOUT LeftServo, 650
PULSOUT RightServo, 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, 1085
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, 850
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, 400
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, 225
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
That code has some issues, I tried running it on one of my bots just to see if it would work, and no joy! Run this code, and you will be roaming around your house in no time!
http://www.parallax.com/Portals/0/Downloads/src/prod/RoamingWithPING-Simple-V1.0.zip
-Nick
Thank you that program worked great!!!!!
LAZach