Help! following a black line in a white background

hey guys im a first semester programming student, im trying to figure out how make my robot run on a black line thats about 4 inches wide. my robot tends to run from side to side and not really straight, and when it goes around corners it tends to either go out of the track or make a 180 degree turn back around. were using the sample code that was downloaded from the site, pololu.com/docs/0J21/7.b

any suggestions on how to modify this code to make our robot work more efficiently?
any help would be greatly appreciat :smiley: ed.

Hello.

The code you are using is designed for lines that are much less wide. If you place the 3pi in the middle of a 4in-wide line, all of its reflectance sensors will all read the same value. When a robot is getting the same value on every sensor, it is hard for it to make any useful decisions. If you cannot change the width of the line, you could try writing an line following program that tries to follow the transition between white and black.

- Ryan

thanks for the response man it is greatly appreciated, but unfortunately the assignment that was given to us does not let us modify the track at all :frowning: … so what would you recommend we modify in the code to make the robot work better?

I recommend that you replace the read_line() function with your own code that detects the edge between the black and white and gives it a score between 0 and 2000 representing where the edge is underneath the 3pi.

-Ryan