[URGENT] I need help with line follower


#1

Hey peoples,
Im programming my bot to turn (RIGHT) every 5 lines.
But it seems that line following device is not working right.
Lines are 2cm thin an are horizontaly.

Example: mBot%20forum

Stage / Area is like this (Every line is 2cm thin) mBot%20Stage

Code:


ps Sorry if I didn’t provide enough information.


#2

Are you using the line follower sensor that comes with the mBot or the line follower array that is purchased separately?


#3

No, Im using the one included from the package.


#4

In my book, A Gentle Introduction to Robotics (link), I captured the value of the line follower reporter block into a variable and tested against the four possible values to determine what to do.

Try saving the values of each of the reads into variables and testing the values of those variables. Since you are essentially calling the same function the previous value is been overwritten because it is not saved anywhere.

For what it’s worth, if you choose to just assign the value of the line follower [port] block to a variable, the values for the sensor are:

Value Meaning
0 Both sensors over black line
1 Left sensor is over black line, right sensor is not
2 Right sensor is over black line, left sensor is not
3 Neither sensor is over the line

#5

I already know these, but this doesn’t work.


#6

Try this logic:

# initialize counter to zero
set counter = 0
                 
forever
    # capture the value of the line follower sensor
    set val to (line follower [port 2])

    # test to see if both sensors detect a line
    if (val = 0)
        # if both sensors detect a line, increment the counter
        change counter by 1

   # if the counter exceeds 3 (remember 0-3 means 3 is actually 4)
   # then execute the turn and reset the counter
    if (counter > 3)
        turn right at speed 100
        wait .9 seconds
        turn right at speed 0
        set counter = 0
    run forward at speed 255

    # wait .25 seconds between readings to avoid multiple reads
    # of the same line
    wait .25 seconds

You may need to fiddle with the value of the last wait statement to get one that works for you.

Another option that might be more flexible than using a second wait would be to not accept a “hit” (value 0) until after the sensor registers a “miss” (non-zero value, preferably a 3).


#7

Maybe try to drive forward a bit slower


#8

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.