Line Follower not working

pending
linefollower

#1

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.
curr=[0]*5


fwd_speed=100
speed_turn = 150
gpg1.set_speed(fwd_speed)



camera = picamera.PiCamera()

slight_turn_speed=int(.5*speed_turn)
turn_speed=int(.7*speed_turn)

line_pos=[0]*5
white_line=line_sensor.get_white_line()
black_line=line_sensor.get_black_line()

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
        else:
            line_pos[i] = 0
    return line_pos

def run_gpg1(curr):

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

        if curr == small_r or curr == small_l or curr == mid or curr == mid1:
            print("Going straight")
            gpg1.set_speed(fwd_speed)
            gpg1.forward()

        # 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)
            gpg1.set_motor_dps(gpg1.MOTOR_RIGHT,fwd_speed)
            gpg1.forward()

        elif curr == left or curr == left1:
            print("turn left")
            gpg1.set_speed(turn_speed)
            gpg1.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)
            gpg1.forward()

        elif curr == right or curr == right1:
            print("turn right")
            gpg1.set_speed(turn_speed)
            gpg1.right()

        elif curr == stop:
            print("Find Line")
            gpg1.backward(fwd_speed)

while True:
    last_val == curr
    curr = absolute_line_pos()
    for i in range (2):
        print(curr)
        time.sleep(0.1)

    if curr == stop1:
        print("All Done Boss")
        for i in range(5):
            run_gpg1(last_val)
        gpg1.stop()
        camera.stop_recording()
        print('Recording Finished')
    else:
        run_gpg1(curr)


#2

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?

Cleo


#3

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 gopigo3_flash_firmware.sh’ 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 dexterindustries.com/update_gopigo3
| bash” and ‘sudo sh -c "curl -kL dexterindustries.com/update_gopigo
| 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


#4

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 dexterindustries.com/update_gopigo | sudo bash
curl -kL dexterindustries.com/update_gopigo3 | sudo bash
curl -kL dexterindustries.com/update_sensors | 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 line_sensor.py. 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!


#5

Hi,
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: -- -- -- -- -- -- -- --

#6

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 line_sensor.py 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!


#7

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

The SHA-1 returned is 0839ce4a5a06679e804d6c6526b501926e91d1eb


#8

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 dexterindustries.com/update_gopigo | sudo bash

Do this and then check with the line follower again.

Thank you!


#9

Still having the same problem, didn’t work


#10

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 line_sensor.py (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 line_sensor.py. What it would be good here is to test it with both versions of the line_sensor.py.

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!