Shop OBEX P1 Docs P2 Docs Learn Events
autonomous lawn mower — Parallax Forums

autonomous lawn mower

epicjr77epicjr77 Posts: 29
edited 2008-08-27 22:52 in Robotics
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

Comments

  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2008-07-17 02:01
    Very cool project. Does it do any determination if the grass is cut (edge detection)? Part of the video didn't appear to have grass getting cut.... or was I just confused?
  • epicjr77epicjr77 Posts: 29
    edited 2008-07-17 02:36
    The grass cutting width is very small 6 inches, and our camera was the best so it is tough to see. It is supposed to detect cut grass but it doesn't work correctly yet. I plan on putting better blades on it and hopefully getting that cut grass sensor to work. Right now I have to write a report and pre-pare my presentation redface.gif
  • WhitWhit Posts: 4,191
    edited 2008-07-18 02:54
    Great project. I love that you included your mini-robot prototype on the video. Thanks for posting your code too!

    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
  • ryan1985ryan1985 Posts: 8
    edited 2008-08-26 18:25
    Thanks for the codes bro [noparse]:)[/noparse]
  • Steve in NMSteve in NM Posts: 54
    edited 2008-08-27 22:52
    Very cool!

    Now it needs GPS so it knows where it's been. At near $4 a gallon, it goes without saying. smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
Sign In or Register to comment.