Python Line Follower Does Not Work

dexteros
gopigo3
bloxter
#1

The following code works fine in Bloxter, but not in Python. I currently have DexterOS 2.2.2.

import easygopigo3 as easy
import time

gpg = easy.EasyGoPiGo3()

try:
    my_linefollower = gpg.init_line_follower()
    time.sleep(0.1)
except:
    print('Line Follower not responding')
    time.sleep(0.2)
    exit()
my_linefollower.read_position()
my_linefollower.read_position()

"""Describe this function...
"""
def follow_line():
    gpg.set_eye_color((255,0,0))
    gpg.open_eyes()
    gpg.close_eyes()
    if not ((my_linefollower.read_position() == "black") or (my_linefollower.read_position() == "white")):
        gpg.open_eyes()
        gpg.forward()
        while not  (my_linefollower.read_position() == "black") or (my_linefollower.read_position() == "white"):
            if my_linefollower.read_position() == 'center':
                gpg.forward()
            if my_linefollower.read_position() == 'left':
                gpg.left()
            if my_linefollower.read_position() == 'right':
                gpg.right()
        gpg.stop()
        gpg.close_eyes()


# start
while True:
    follow_line()
    time.sleep(0.05) # slowdown

#2

First things first: do you get any errors at all? Or is it just hanging, doing apparently nothing? If it does hang, what happens if you send a SIGINT signal (aka CTRL-C) to it? Do you get any errors if you do that?

Thank you!

#3

It has been fixed in 2.3.0! They updated the function names. Please try the following:

  1. Create a line follower program in Bloxter.
  2. Open the Python drawer on the right, and copy/paste the code into a new Python notebook.
  3. Calibrate the line follower.
  4. Run it, and see if he follows the line.