simple newbie question: line-following robot
This ought to be easy but I don't see it.· I want to program (pbasic 2.5) a robot to follow a white path between two black lines.· This is similar to the parallax demo program for Scribbler except rather than following a black line, I want·to to follow a white line between two black lines.· The code below seems to detect the lines correctly- the LEDs and DEBUG do the correct things when I hold line patterns under a robot while held static. But when I let the robot move with motors, it totally ignores the lines.· It doesn't seem to matter if the robot moves fast or slow or how thick the lines are.· I'm wondering if there is a timing thing or some trick to combining sensors and motors (e.g. I notice that the parallax demo source code is simple and understandable when the line sensor controls LEDs, but when it controls the motors, the program uses all kinds of stored constants, etc).
Anyway: this doesn't work and I'd appreciate comments.
'· {$STAMP BS2}
'· {$PBASIC 2.5}
' I/O Declarations
' I/O Declarations
LineEnable··· PIN 3
LineRight···· PIN 4
LineLeft····· PIN 5
LedRight····· PIN 8
LedCenter···· PIN 9
LedLeft······ PIN 10
MotorRight··· PIN 12
MotorLeft···· PIN 13
DEBUG "starting"
'Variables
moveLeft VAR Word
moveRight VAR Word
LOW MotorRight
LOW MotorLeft
LOW LedRight
LOW LedLeft
LOW LedCenter
PAUSE 100
'Turn on the Line Sensor IR LEDs
·· HIGH LineEnable
DO
·· IF (LineRight=0 AND LineLeft=0) THEN············· 'both detectors on white
····· moveLeft=2500
····· moveRight=2500
····· HIGH LedCenter
···· DEBUG "white/white"
····· GOSUB MotorDrive
·· ELSEIF (LineRight=1 AND LineLeft=0) THEN············· 'black on right, white on left
····· moveLeft=1800
····· moveRight=1500
····· HIGH LedRight
····· DEBUG "white/black"
···· GOSUB MotorDrive
· ELSEIF (LineLeft=1 AND LineRight=0)· THEN··········· 'black on left, white on right
··· moveLeft=1500
··· moveRight=1800
··· HIGH LedLeft
··· DEBUG "black/white"
··· GOSUB MotorDrive
· ELSEIF (LineRight=1 AND LineLeft=1) THEN········· 'both detectors on black
···· moveLeft=1500
···· moveRight=1500
···· DEBUG "black/black"
···· GOSUB MotorDrive
· ENDIF
DEBUG HOME
· LOW LedRight
· LOW LedLeft
· LOW LedCenter
LOOP
LOW LineEnable
MotorDrive:
···· PULSOUT MotorLeft, moveLeft
···· PULSOUT MotorRight, moveRight
RETURN
END
Anyway: this doesn't work and I'd appreciate comments.
'· {$STAMP BS2}
'· {$PBASIC 2.5}
' I/O Declarations
' I/O Declarations
LineEnable··· PIN 3
LineRight···· PIN 4
LineLeft····· PIN 5
LedRight····· PIN 8
LedCenter···· PIN 9
LedLeft······ PIN 10
MotorRight··· PIN 12
MotorLeft···· PIN 13
DEBUG "starting"
'Variables
moveLeft VAR Word
moveRight VAR Word
LOW MotorRight
LOW MotorLeft
LOW LedRight
LOW LedLeft
LOW LedCenter
PAUSE 100
'Turn on the Line Sensor IR LEDs
·· HIGH LineEnable
DO
·· IF (LineRight=0 AND LineLeft=0) THEN············· 'both detectors on white
····· moveLeft=2500
····· moveRight=2500
····· HIGH LedCenter
···· DEBUG "white/white"
····· GOSUB MotorDrive
·· ELSEIF (LineRight=1 AND LineLeft=0) THEN············· 'black on right, white on left
····· moveLeft=1800
····· moveRight=1500
····· HIGH LedRight
····· DEBUG "white/black"
···· GOSUB MotorDrive
· ELSEIF (LineLeft=1 AND LineRight=0)· THEN··········· 'black on left, white on right
··· moveLeft=1500
··· moveRight=1800
··· HIGH LedLeft
··· DEBUG "black/white"
··· GOSUB MotorDrive
· ELSEIF (LineRight=1 AND LineLeft=1) THEN········· 'both detectors on black
···· moveLeft=1500
···· moveRight=1500
···· DEBUG "black/black"
···· GOSUB MotorDrive
· ENDIF
DEBUG HOME
· LOW LedRight
· LOW LedLeft
· LOW LedCenter
LOOP
LOW LineEnable
MotorDrive:
···· PULSOUT MotorLeft, moveLeft
···· PULSOUT MotorRight, moveRight
RETURN
END
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
If you're looking at LineFollowScribbler.bs2, the constants that this program contains relate to the GUI interface of the Scribbler. I would recommend taking the original program you were working with (either LineFollowScribbler.bs2 or default.bs2, they're both attached for your convenience) and just changing the values to follow the white line. If that works then you can work on cutting down the code to only do what you want it to. There may be preset GUI variables that are causing your program to skip your line following IF...THEN statements.
Hope this helps!
Jessica
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax, Inc.
Secondly, I'm having trouble understanding the code- there are many, many variables, some seem to get their values "magically" (probably just means I don't understand ;-) ).· It also seems to count lines- I don't see why.· Is there documentation anywhere for the code?- I don't understand it well enough to try to modify it· (help, please!)
Thicker lines could be causing a problem. The code is tailored to a fixed width since each IR LED are in a fixed position. With thicker lines, it will take longer to detect a black line, and you'll have to tweak the Scribbler's turn code for when it tries to right itself. Also, the reason there are so many variables is that these programs were written in the Scribbler GUI and need most of those variables to interface and get calibration values from the Scribber IDE.
I've attached a new program, LineFollowScribbler_WithComments.bs2, which I hope will help you better understand what the program is doing.
Happy Developing!
Jessica
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax, Inc.