Ch-10 TR feedback
This commit is contained in:
parent
b2228889e8
commit
45ba981386
@ -14,22 +14,22 @@ class PController:
|
||||
|
||||
|
||||
## We'll set up a single distance sensor, and keep a set distance from an object
|
||||
robot.left_distance.distance_mode = 1
|
||||
robot.left_distance.start_ranging()
|
||||
robot.right_distance.distance_mode = 1
|
||||
robot.right_distance.start_ranging()
|
||||
|
||||
distance_set_point = 10
|
||||
distance_controller = PController(-0.1)
|
||||
|
||||
while True:
|
||||
if robot.left_distance.data_ready:
|
||||
distance = robot.left_distance.distance
|
||||
if robot.right_distance.data_ready:
|
||||
distance = robot.right_distance.distance
|
||||
error = distance_set_point - distance
|
||||
speed = distance_controller.calculate(error)
|
||||
if abs(speed) < 0.2:
|
||||
if abs(speed) < 0.3:
|
||||
speed = 0
|
||||
uart.write(f"{error},{speed}\n".encode())
|
||||
print(f"{error},{speed}")
|
||||
robot.set_left(speed)
|
||||
robot.set_right(speed)
|
||||
robot.left_distance.clear_interrupt()
|
||||
robot.right_distance.clear_interrupt()
|
||||
time.sleep(0.05)
|
||||
|
||||
@ -17,28 +17,28 @@ class PIController:
|
||||
|
||||
|
||||
## We'll set up a single distance sensor, and keep a set distance from an object
|
||||
robot.left_distance.distance_mode = 1
|
||||
robot.left_distance.start_ranging()
|
||||
robot.right_distance.distance_mode = 1
|
||||
robot.right_distance.start_ranging()
|
||||
|
||||
distance_set_point = 10
|
||||
distance_controller = PIController(-0.19, -0.005)
|
||||
|
||||
prev_time = time.monotonic()
|
||||
while True:
|
||||
if robot.left_distance.data_ready:
|
||||
distance = robot.left_distance.distance
|
||||
if robot.right_distance.data_ready:
|
||||
distance = robot.right_distance.distance
|
||||
error = distance_set_point - distance
|
||||
|
||||
current_time = time.monotonic()
|
||||
speed = distance_controller.calculate(error, current_time - prev_time)
|
||||
prev_time = current_time
|
||||
# Control the motors with the speed
|
||||
if abs(speed) < 0.35:
|
||||
if abs(speed) < 0.3:
|
||||
speed = 0
|
||||
uart.write(f"{error},{speed},"
|
||||
f"{distance_controller.integral}\n".encode())
|
||||
print(f"{error},{speed},{distance_controller.integral}")
|
||||
robot.set_left(speed)
|
||||
robot.set_right(speed)
|
||||
robot.left_distance.clear_interrupt()
|
||||
robot.right_distance.clear_interrupt()
|
||||
time.sleep(0.05)
|
||||
|
||||
@ -8,28 +8,28 @@ uart = busio.UART(board.GP12, board.GP13, baudrate=9600)
|
||||
|
||||
|
||||
## We'll set up a single distance sensor, and keep a set distance from an object
|
||||
robot.left_distance.distance_mode = 1
|
||||
robot.left_distance.start_ranging()
|
||||
robot.right_distance.distance_mode = 1
|
||||
robot.right_distance.start_ranging()
|
||||
|
||||
distance_set_point = 10
|
||||
distance_controller = PIDController(-0.09, -0.02, -0.07)
|
||||
|
||||
prev_time = time.monotonic()
|
||||
while True:
|
||||
if robot.left_distance.data_ready:
|
||||
distance = robot.left_distance.distance
|
||||
if robot.right_distance.data_ready:
|
||||
distance = robot.right_distance.distance
|
||||
error = distance_set_point - distance
|
||||
|
||||
current_time = time.monotonic()
|
||||
speed = distance_controller.calculate(error, current_time - prev_time)
|
||||
prev_time = current_time
|
||||
# Control the motors with the speed
|
||||
if abs(speed) < 0.35:
|
||||
if abs(speed) < 0.3:
|
||||
speed = 0
|
||||
uart.write(f"{error},{speed},{distance_controller.integral},{distance_controller.derivative}\n".encode())
|
||||
print(f"{error},{speed},{distance_controller.integral},{distance_controller.derivative}")
|
||||
robot.set_left(speed)
|
||||
robot.set_right(speed)
|
||||
# reset the distance sensor
|
||||
robot.left_distance.clear_interrupt()
|
||||
robot.right_distance.clear_interrupt()
|
||||
time.sleep(0.05)
|
||||
|
||||
@ -25,7 +25,8 @@ while True:
|
||||
current_time = time.monotonic()
|
||||
deflection = distance_controller.calculate(error, current_time - prev_time)
|
||||
prev_time = current_time
|
||||
uart.write(f"{error},{deflection}\n".encode()) # ,{distance_controller.derivative}
|
||||
uart.write(f"{error},{deflection},"
|
||||
f"{distance_controller.derivative}\n".encode())
|
||||
if motors_active:
|
||||
robot.set_left(speed - deflection)
|
||||
robot.set_right(speed + deflection)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user