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)