TR-11 Swapping out G command. Making line sending more compact
This commit is contained in:
@@ -14,7 +14,7 @@ async def motor_speed_loop():
|
|||||||
left_last = left_new
|
left_last = left_new
|
||||||
right_speed = robot.ticks_to_m * (right_new - right_last) / Settings.time_interval
|
right_speed = robot.ticks_to_m * (right_new - right_last) / Settings.time_interval
|
||||||
right_last = right_new
|
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):
|
async def stop_motors_after(seconds):
|
||||||
await asyncio.sleep(seconds)
|
await asyncio.sleep(seconds)
|
||||||
@@ -28,21 +28,22 @@ async def command_handler():
|
|||||||
Settings.speed = float(command[1:])
|
Settings.speed = float(command[1:])
|
||||||
elif command.startswith("T"):
|
elif command.startswith("T"):
|
||||||
Settings.time_interval = float(command[1:])
|
Settings.time_interval = float(command[1:])
|
||||||
elif command == "O":
|
elif command == "G":
|
||||||
robot.stop()
|
robot.stop()
|
||||||
elif command.startswith("O"):
|
elif command.startswith("G"):
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
asyncio.create_task(stop_motors_after(float(command[1:])))
|
asyncio.create_task(stop_motors_after(float(command[1:])))
|
||||||
robot.set_left(Settings.speed)
|
robot.set_left(Settings.speed)
|
||||||
robot.set_right(Settings.speed)
|
robot.set_right(Settings.speed)
|
||||||
elif command.startswith("?"):
|
elif command.startswith("?"):
|
||||||
robot.uart.write(f"M{Settings.speed:.1f}\n".encode())
|
robot.send_line(f"M{Settings.speed:.1f}")
|
||||||
robot.uart.write(f"T{Settings.time_interval:.1f}\n".encode())
|
robot.send_line(f"T{Settings.time_interval:.1f}")
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
asyncio.create_task(motor_speed_loop())
|
motor_task = asyncio.create_task(motor_speed_loop())
|
||||||
asyncio.run(command_handler())
|
asyncio.run(command_handler())
|
||||||
finally:
|
finally:
|
||||||
|
motor_task.cancel()
|
||||||
robot.stop()
|
robot.stop()
|
||||||
|
|||||||
@@ -59,3 +59,6 @@ def set_left(speed):
|
|||||||
|
|
||||||
def set_right(speed):
|
def set_right(speed):
|
||||||
set_speed(right_motor, speed)
|
set_speed(right_motor, speed)
|
||||||
|
|
||||||
|
def send_line(message):
|
||||||
|
uart.write(f"{message}\n".encode())
|
||||||
|
|||||||
Reference in New Issue
Block a user