Skip to main content

Sigue líneas

Vamos a crear un programa SIGUE LÍNEAS

Ese es programa

from arduino_alvik import ArduinoAlvik
from time import sleep
import sys

alvik = ArduinoAlvik()
alvik.begin()
sleep(5)

#Variable constants to set and adjust wheel speed changes
base_speed = 20
strength = 0.1 #Percentage of speed change, calculated in adjustment
adjustment = base_speed * strength

while True:
    try:
        ir_left, ir_center, ir_right = alvik.get_line_sensors()
        print(ir_left, ir_center, ir_right)
        sleep(0.01)
        
        #Conditions to check and adjust position on black line
        if ir_center > 300:
            alvik.set_wheels_speed(base_speed, base_speed)
        elif ir_left > 300:
            alvik.set_wheels_speed(0, base_speed + adjustment)
        elif ir_right > 300:
            alvik.set_wheels_speed(base_speed + adjustment, 0)
        else:
            alvik.set_wheels_speed(0, 0)
    
    except KeyboardInterrupt as e:
        print('over')
        alvik.stop()
        sys.exit()