Line Follower not working

Hi, I’m having difficulty with my line follower, when i run the line follower calibration it reads back correct values for black and white when on a line i.e {0,0,1,0,0} but after running an update the values are no longer grabbed by my program. Any Assistance would be appreciated. My code is underneath

from __future__ import print_function
from __future__ import division
from builtins import input

import picamera
import time
import line_sensor
import easygopigo3 as easy

gpg1 = easy.EasyGoPiGo3()

last_val=[0]*5						# An array to keep track of the previous values.

speed_turn = 150

camera = picamera.PiCamera()



range_sensor= line_sensor.get_range()
threshold=[a+b/2 for a,b in zip(white_line,range_sensor)]

mid 	=[0,0,1,0,0]	# Middle Position.
mid1	=[0,1,1,1,0]	# Middle Position.
small_r	=[0,1,1,0,0]	# Slightly to the right.
small_r1=[0,1,0,0,0]	# Slightly to the right.
small_l	=[0,0,1,1,0]	# Slightly to the left.
small_l1=[0,0,0,1,0]	# Slightly to the left.
right	=[1,1,0,0,0]	# Strong to the right.
right1	=[1,0,0,0,0]	# Strong to the right.
left	=[0,0,0,1,1]	# Sensor reads strongly to the left.
left1	=[0,0,0,0,1]	# Sensor reads strongly to the left.
stop	=[1,1,1,1,1]	# Sensor reads stop.
stop1	=[0,0,0,0,0]	# Sensor reads stop.

def absolute_line_pos():
    raw_vals = line_sensor.get_sensorval()
    for i in range(5):
        if raw_vals[i] > threshold[i]:
            line_pos[i] = 1
            line_pos[i] = 0
    return line_pos

def run_gpg1(curr):

    while curr != stop1:
        camera.resolution = (1080  , 720)
        print('Recording Starting')

        if curr == small_r or curr == small_l or curr == mid or curr == mid1:
            print("Going straight")

        # If the line is towards the slight left, turn slight right
        elif curr == small_l1:
            print("adjust right")
            gpg1.set_motor_dps(gpg1.MOTOR_LEFT, slight_turn_speed)

        elif curr == left or curr == left1:
            print("turn left")

        # If the line is towards the slight right, turn slightleft
        elif curr == small_r1:
            print("adjust left")
            gpg1.set_motor_dps(gpg1.MOTOR_LEFT, fwd_speed)
            gpg1.set_motor_dps(gpg1.MOTOR_RIGHT, slight_turn_speed)

        elif curr == right or curr == right1:
            print("turn right")

        elif curr == stop:
            print("Find Line")

while True:
    last_val == curr
    curr = absolute_line_pos()
    for i in range (2):

    if curr == stop1:
        print("All Done Boss")
        for i in range(5):
        print('Recording Finished')

Hello @dalysean,

can you tell us a bit more?
What did you update exactly, and what do you mean by “the values are no longer grabbed by my program”.
Are you getting any error messages?


The Camera was not being found so i used the DI update to update the GoPiGo3 , however this caused the line follower to become unusable so i used ‘sudo’ to try to get the firmware back to a state where the line follower worked.
When it did not i used a command found on another form ‘sudo rpi-update 52241088c1da59a359110d39c1875cda56496764’ to update it to a former version.
Afterwards i used the “sudo sh -c “curl -kL
| bash” and ‘sudo sh -c "curl -kL
| bash” as i found on a forum these had to be done to get it fully functioning again.
But After this my code returned a ‘import error: mutex not found’ so i used the ‘sudo pip3 uninstall gopigo -y’ and the ‘sudo pip uninstall gopigo -y’ in order to fix that error and the a sudo apt-get upgrade when the gopigo gave me an error of it having 0.3.4 firmware

After all this my code does not return any errors however while the line calibration program on the robot shows that the line follower can tell the difference between black and white by returning correct values, when the white_line/black_line function call is made by my code above the only reading ever returned is 0,0,0,0,0 regardless of whether it is on white or black surface.
Before i done any of these commands above the code which i submitted above worked perfectly with the robot driving following the black line and reading in values from the called functions correctly

I am confused as to why my code can no longer read in correct values from the white_line/black_line functions imported from the line_sensor module but the line follower calibration program preinstalled on the robot returns correct values.
Any help would be appreciated

Hi @dalysean,

There are so many variables in your case that’s almost impossible to reproduce it over here.

The GUI interface for the line follower uses the exact same module called line_sensor, so maybe you’re running a different version of Python that’s different than the one the GUI uses. The GUI uses the python executable so I wonder if you’re using python3 or something else.
I’m thinking that maybe on one version of Python you have a working library installed, whereas on the other one you don’t.

There may be another thing you could do: uninstall all python packages related to our products, even though it’s kind of extreme. Use pip list and pip3 list to find those such as GoPiGo, GoPiGo3 and DI-Sensors and then uninstall them.
After you do that, reinstall them with the following commands:

curl -kL | sudo bash
curl -kL | sudo bash
curl -kL | sudo bash

Do that and then give the line follower another try in a Python interpreter.

By the way, you may be interested in seeing the source code for the You can use those couple of functions to try out the sensor:

Let us know how far you have got with all these.

Thank you!

I’ve tried all you have said but none of it worked.
However i have discovered that when calling the get_sensorval() function from the line_sensor import , it returns -1,-1,-1,-1,-1 values into my program. This is causing the code to always believe it is on all white as the raw_vals variable always is less than the threshold variable in my code above.

pi@dex:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- 06 -- 08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Hi @dalysean,

That looks as if the bug we had the previous autumn still manifests on your machine. Can you tell us if in your script you have the following import:

If you don’t have it, then for some reason, the update didn’t go through and hence you’re still stuck with that bug.
It would also be useful to give us the commit SHA-1. You can do this by going to /home/pi/Dexter/GrovePi repo and then typing in git rev-parse HEAD.

Thank you!

The file in the GoPiGo folder does contain the import.
However in the GoPiGo3 folder the file does not contain the import and my code is located inside a file in the GoPiGo3 folder.

The SHA-1 returned is 0839ce4a5a06679e804d6c6526b501926e91d1eb

Hi @dalysean,

Okay, I checked here and your SHA-1 is not in our tree, which means you don’t have what we have on our official repo. For some reason. I checked mine for instance and it’s pointing at the last one, which is good.
I mean, it’s not even a valid reference point and that’s only if you made a clone of our repo or if you made some commits.

I would ask you to delete the GoPiGo folder that’s in /home/pi/Dexter and then run the installer command for the GoPiGo:

curl -kL | sudo bash

Do this and then check with the line follower again.

Thank you!

Still having the same problem, didn’t work

Hi @dalysean,

I’ve been thinking of what else we can try so here it is:

  1. Try out with the other version of the (the one from the GoPiGo3). Just so you know, the one on the GoPiGo is the good one which was bug-fixed not long ago.

  2. Can you tell us on which distribution are you doing this? If it’s on a Stretch, then can you give it a test on a Jessie?

  3. This might be silly, but can you run sudo rpi-update 52241088c1da59a359110d39c1875cda56496764 on yours? This will downgrade the linux kernel to an older version - like 4.4.50-v7+. This was the last version of it that worked with the old version of What it would be good here is to test it with both versions of the

Unless there was a recent change into how the linux’s I2C protocol works, then there’s no reason for the line follower not to function. And we tested it recently and it was all good.

Thank you!