autonomous lawn mower
I just finished my project and would like to thank every one here for your help.
Uses a BS2 with a ping and bumper switches
' {$STAMP BS2}
' {$PBASIC 2.5}
Ping PIN 14
PingServo PIN 0
LeftServo PIN 13
RightServo PIN 12
rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte
switch VAR IN15
Ticks VAR Byte
DO
DEBUG ? IN15
DEBUG ? IN9
DEBUG ? IN10
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 1
PULSOUT 0, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
FOR sweepcount = 950 TO 550 STEP 200
FOR x = 0 TO 1
PULSOUT 0, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
IF switch=0 THEN
ticks=ticks + 1 MAX 25
ELSE
ticks=0 ' reset timer
ENDIF
IF ticks=1 THEN ' still open after 1/4 second
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_left
ENDIF
elseIF (IN15 = 1) THEN
PULSOUT 14, 1000 ' grass sensor see grass so open throttle
PAUSE 20
ENDIF
ELSEIF (IN15 = 0) THEN ' grass sensor doesnt see grass so close throttle and back up and turn right
PULSOUT 14, 500
GOSUB Back_Up
GOSUB Back_Up
GOSUB Turn_Right
ENDIF
LOOP
'
Subroutines
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 2200) THEN ' adjust to change distance
IF (sweepcount < 750) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Back_Up
GOSUB Turn_Right
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
Forward_Pulse:
IF (IN10 = 1) THEN ' Left Bumper Contact
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
GOSUB Turn_Right
ELSEIF (IN9 = 1) THEN ' Right Bumper Contact
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_left
GOSUB Turn_Left
ENDIF
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 900
PULSOUT RightServo, 600
PAUSE 20
NEXT
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT LeftServo, 600
PULSOUT RightServo, 600
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20
PULSOUT LeftServo, 900
PULSOUT RightServo, 900
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT LeftServo, 600
PULSOUT RightServo, 900
PAUSE 20
NEXT
FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 600
PULSOUT RightServo, 900
PAUSE 20
NEXT
RETURN
Uses a BS2 with a ping and bumper switches
' {$STAMP BS2}
' {$PBASIC 2.5}
Ping PIN 14
PingServo PIN 0
LeftServo PIN 13
RightServo PIN 12
rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte
switch VAR IN15
Ticks VAR Byte
DO
DEBUG ? IN15
DEBUG ? IN9
DEBUG ? IN10
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 1
PULSOUT 0, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
FOR sweepcount = 950 TO 550 STEP 200
FOR x = 0 TO 1
PULSOUT 0, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
IF switch=0 THEN
ticks=ticks + 1 MAX 25
ELSE
ticks=0 ' reset timer
ENDIF
IF ticks=1 THEN ' still open after 1/4 second
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_left
ENDIF
elseIF (IN15 = 1) THEN
PULSOUT 14, 1000 ' grass sensor see grass so open throttle
PAUSE 20
ENDIF
ELSEIF (IN15 = 0) THEN ' grass sensor doesnt see grass so close throttle and back up and turn right
PULSOUT 14, 500
GOSUB Back_Up
GOSUB Back_Up
GOSUB Turn_Right
ENDIF
LOOP
'
Subroutines
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 2200) THEN ' adjust to change distance
IF (sweepcount < 750) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Back_Up
GOSUB Turn_Right
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
Forward_Pulse:
IF (IN10 = 1) THEN ' Left Bumper Contact
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
GOSUB Turn_Right
ELSEIF (IN9 = 1) THEN ' Right Bumper Contact
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_left
GOSUB Turn_Left
ENDIF
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 900
PULSOUT RightServo, 600
PAUSE 20
NEXT
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT LeftServo, 600
PULSOUT RightServo, 600
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20
PULSOUT LeftServo, 900
PULSOUT RightServo, 900
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT LeftServo, 600
PULSOUT RightServo, 900
PAUSE 20
NEXT
FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 600
PULSOUT RightServo, 900
PAUSE 20
NEXT
RETURN
Comments
Super job.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Whit+
"We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
Now it needs GPS so it knows where it's been. At near $4 a gallon, it goes without saying.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm not a complete idiot! Some of my parts are missing.