Ping))) programming with Boe-Bot
Miltos
Posts: 16
Can some one help me and give me details about each line of code regarding Boe-Bot's navigation with ping below?
' {$STAMP BS2}
' {$PBASIC 2.5}
Ping PIN 15
PingServo PIN 14
LeftServo PIN 13
RightServo PIN 12
rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte
Main:
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
FOR sweepcount = 950 TO 350 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
GOTO Main
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
Forward_Pulse:
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Left:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 850
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 3
PULSOUT LeftServo, 750
PULSOUT RightServo, 750
PAUSE 20
NEXT
FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 650
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Especially this:
FOR sweepcount = 950 TO 350 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
GOTO Main
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
' {$STAMP BS2}
' {$PBASIC 2.5}
Ping PIN 15
PingServo PIN 14
LeftServo PIN 13
RightServo PIN 12
rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte
Main:
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
FOR sweepcount = 950 TO 350 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
GOTO Main
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
Forward_Pulse:
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Left:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 850
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 3
PULSOUT LeftServo, 750
PULSOUT RightServo, 750
PAUSE 20
NEXT
FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 650
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Especially this:
FOR sweepcount = 950 TO 350 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
GOTO Main
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
Comments
Meanwhile, have a look at http://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/248/Default.aspx?txtSearch=roaming+with+ping and look at all the well-commented programs under
Downloads & Resources:
Ping))) Mounting Bracket Documentation v2.0 (.pdf)
Roaming with the PING))) - Simple (.bs2)
Roaming with the PING))) - Advanced (.bs2)
Boe-Bot robot Roaming with PING))) (.wmv)
Boe-Bot robot Roaming with PING))) High Resolution (.wmv)
All good, my young Padawan?