Sync the robot library
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import board
|
import board
|
||||||
import pwmio
|
import pwmio
|
||||||
import pio_encoder
|
import pio_encoder
|
||||||
|
import busio
|
||||||
|
import adafruit_vl53l1x
|
||||||
|
|
||||||
|
|
||||||
motor_A1 = pwmio.PWMOut(board.GP17)
|
motor_A1 = pwmio.PWMOut(board.GP17)
|
||||||
motor_A2 = pwmio.PWMOut(board.GP16)
|
motor_A2 = pwmio.PWMOut(board.GP16)
|
||||||
@@ -13,6 +16,12 @@ left_motor = motor_B1, motor_B2
|
|||||||
right_encoder = pio_encoder.QuadratureEncoder(board.GP20, board.GP21, reversed=True)
|
right_encoder = pio_encoder.QuadratureEncoder(board.GP20, board.GP21, reversed=True)
|
||||||
left_encoder = pio_encoder.QuadratureEncoder(board.GP26, board.GP27)
|
left_encoder = pio_encoder.QuadratureEncoder(board.GP26, board.GP27)
|
||||||
|
|
||||||
|
i2c0 = busio.I2C(sda=board.GP0, scl=board.GP1)
|
||||||
|
i2c1 = busio.I2C(sda=board.GP2, scl=board.GP3)
|
||||||
|
|
||||||
|
left_distance = adafruit_vl53l1x.VL53L1X(i2c0)
|
||||||
|
right_distance = adafruit_vl53l1x.VL53L1X(i2c1)
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
motor_A1.duty_cycle = 0
|
motor_A1.duty_cycle = 0
|
||||||
@@ -21,7 +30,7 @@ def stop():
|
|||||||
motor_B2.duty_cycle = 0
|
motor_B2.duty_cycle = 0
|
||||||
|
|
||||||
|
|
||||||
def set_speed(motor: tuple, speed: float):
|
def set_speed(motor, speed):
|
||||||
# Swap motor pins if we reverse the speed
|
# Swap motor pins if we reverse the speed
|
||||||
if speed < 0:
|
if speed < 0:
|
||||||
direction = motor[1], motor[0]
|
direction = motor[1], motor[0]
|
||||||
@@ -35,9 +44,9 @@ def set_speed(motor: tuple, speed: float):
|
|||||||
direction[1].duty_cycle = 0
|
direction[1].duty_cycle = 0
|
||||||
|
|
||||||
|
|
||||||
def set_left(speed: float):
|
def set_left(speed):
|
||||||
set_speed(left_motor, speed)
|
set_speed(left_motor, speed)
|
||||||
|
|
||||||
|
|
||||||
def set_right(speed: float):
|
def set_right(speed):
|
||||||
set_speed(right_motor, speed)
|
set_speed(right_motor, speed)
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import board
|
import board
|
||||||
import pwmio
|
import pwmio
|
||||||
import pio_encoder
|
import pio_encoder
|
||||||
|
import busio
|
||||||
|
import adafruit_vl53l1x
|
||||||
|
|
||||||
|
|
||||||
motor_A1 = pwmio.PWMOut(board.GP17)
|
motor_A1 = pwmio.PWMOut(board.GP17)
|
||||||
motor_A2 = pwmio.PWMOut(board.GP16)
|
motor_A2 = pwmio.PWMOut(board.GP16)
|
||||||
@@ -13,6 +16,12 @@ left_motor = motor_B1, motor_B2
|
|||||||
right_encoder = pio_encoder.QuadratureEncoder(board.GP20, board.GP21, reversed=True)
|
right_encoder = pio_encoder.QuadratureEncoder(board.GP20, board.GP21, reversed=True)
|
||||||
left_encoder = pio_encoder.QuadratureEncoder(board.GP26, board.GP27)
|
left_encoder = pio_encoder.QuadratureEncoder(board.GP26, board.GP27)
|
||||||
|
|
||||||
|
i2c0 = busio.I2C(sda=board.GP0, scl=board.GP1)
|
||||||
|
i2c1 = busio.I2C(sda=board.GP2, scl=board.GP3)
|
||||||
|
|
||||||
|
left_distance = adafruit_vl53l1x.VL53L1X(i2c0)
|
||||||
|
right_distance = adafruit_vl53l1x.VL53L1X(i2c1)
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
motor_A1.duty_cycle = 0
|
motor_A1.duty_cycle = 0
|
||||||
@@ -21,7 +30,7 @@ def stop():
|
|||||||
motor_B2.duty_cycle = 0
|
motor_B2.duty_cycle = 0
|
||||||
|
|
||||||
|
|
||||||
def set_speed(motor: tuple, speed: float):
|
def set_speed(motor, speed):
|
||||||
# Swap motor pins if we reverse the speed
|
# Swap motor pins if we reverse the speed
|
||||||
if speed < 0:
|
if speed < 0:
|
||||||
direction = motor[1], motor[0]
|
direction = motor[1], motor[0]
|
||||||
@@ -35,9 +44,9 @@ def set_speed(motor: tuple, speed: float):
|
|||||||
direction[1].duty_cycle = 0
|
direction[1].duty_cycle = 0
|
||||||
|
|
||||||
|
|
||||||
def set_left(speed: float):
|
def set_left(speed):
|
||||||
set_speed(left_motor, speed)
|
set_speed(left_motor, speed)
|
||||||
|
|
||||||
|
|
||||||
def set_right(speed: float):
|
def set_right(speed):
|
||||||
set_speed(right_motor, speed)
|
set_speed(right_motor, speed)
|
||||||
|
|||||||
Reference in New Issue
Block a user