TR-11 Swapping out G command. Making line sending more compact

This commit is contained in:
Danny Staple
2023-01-02 12:04:49 +00:00
parent a137464ced
commit 92e3f85094
2 changed files with 10 additions and 6 deletions
+7 -6
View File
@@ -14,7 +14,7 @@ async def motor_speed_loop():
left_last = left_new
right_speed = robot.ticks_to_m * (right_new - right_last) / Settings.time_interval
right_last = right_new
robot.uart.write(f"{left_speed:.3f},{right_speed:.3f},0\n".encode())
robot.send_line(f"{left_speed:.2f},{right_speed:.2f},0")
async def stop_motors_after(seconds):
await asyncio.sleep(seconds)
@@ -28,21 +28,22 @@ async def command_handler():
Settings.speed = float(command[1:])
elif command.startswith("T"):
Settings.time_interval = float(command[1:])
elif command == "O":
elif command == "G":
robot.stop()
elif command.startswith("O"):
elif command.startswith("G"):
await asyncio.sleep(5)
asyncio.create_task(stop_motors_after(float(command[1:])))
robot.set_left(Settings.speed)
robot.set_right(Settings.speed)
elif command.startswith("?"):
robot.uart.write(f"M{Settings.speed:.1f}\n".encode())
robot.uart.write(f"T{Settings.time_interval:.1f}\n".encode())
robot.send_line(f"M{Settings.speed:.1f}")
robot.send_line(f"T{Settings.time_interval:.1f}")
await asyncio.sleep(3)
await asyncio.sleep(0)
try:
asyncio.create_task(motor_speed_loop())
motor_task = asyncio.create_task(motor_speed_loop())
asyncio.run(command_handler())
finally:
motor_task.cancel()
robot.stop()
+3
View File
@@ -59,3 +59,6 @@ def set_left(speed):
def set_right(speed):
set_speed(right_motor, speed)
def send_line(message):
uart.write(f"{message}\n".encode())