Shop OBEX P1 Docs P2 Docs Learn Events
Line Following using one photo resistor — Parallax Forums

Line Following using one photo resistor

nab014nab014 Posts: 22
edited 2007-11-12 18:16 in Learn with BlocklyProp
We have a project in class that involves following a black piece of electrical tape on a white board through a course including curves. We are allowed to use only one photo resistor. I wrote the program below but for some reason once the robot goes off the edge of the tape and starts the searching commands, it goes to the right and the left okay but doesn't seem to be testing the photo resistor at the far right like it should.....it only reads after the search left and responds to the reading. I hope that made sense. The project is due tomorrow afternoon.......any suggestions?

' {$STAMP BS2}
' {$PBASIC 2.5}

time VAR Word
pulsecount VAR Byte

DO
GOSUB test_photoresistors
GOSUB navigate
LOOP

test_photoresistors:

HIGH 3
PAUSE 3
RCTIME 3, 1, time

RETURN

navigate:

IF (time > 70) THEN
PULSOUT 13, 800
PULSOUT 12, 700
ELSE
GOSUB searchright
GOSUB searchleft
ENDIF

PAUSE 10

RETURN

searchright:
FOR pulsecount = 0 TO 40
PULSOUT 13, 755
PULSOUT 12, 755
PAUSE 30
GOSUB test_photoresistors
NEXT
RETURN
searchleft:
FOR pulsecount = 0 TO 20
PULSOUT 13, 740
PULSOUT 12, 740
PAUSE 30
GOSUB test_photoresistors
NEXT
RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-11-12 06:32
    I don't see where you use time except in the navigate. The search right and left test for nothing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • nab014nab014 Posts: 22
    edited 2007-11-12 13:24
    Okay.........what can I do to fix it so that the robot will move to the right - test - move to the left - test - on and on until it finds the line? (as soon as it finds the line make it stop and start going forward again)
  • FranklinFranklin Posts: 4,747
    edited 2007-11-12 18:16
    Isn't that what the class is about. Check with your teacher and rewrite the code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.