Know turn behaviour for chapter 12.

This commit is contained in:
Danny Staple
2022-10-09 22:33:18 +01:00
parent 07f3f3c96e
commit 1b8533b459
6 changed files with 264 additions and 25 deletions
+13 -25
View File
@@ -19,8 +19,6 @@ class FaceNorthController:
robot.set_left(control_signal)
robot.set_right(-control_signal)
# control loop
async def control_loop():
controller = FaceNorthController()
last_time = time.monotonic()
@@ -34,30 +32,20 @@ async def control_loop():
controller.update(dt, angle)
robot.uart.write(f"{angle}, 0\n".encode())
# main
async def main():
while not robot.check_imu_status():
await asyncio.sleep(0.1)
robot.uart.write("Ready to go!\n".encode())
# Wait for start signal
while True:
if robot.uart.in_waiting:
command = robot.uart.readline().decode().strip()
if command == "start":
break
await asyncio.sleep(0.1)
await control_loop()
def check_status():
sys_status, gyro, accel, mag = robot.imu.calibration_status
print(f"Sys: {sys_status}, Gyro: {gyro}, Accel: {accel}, Mag: {mag}")
robot.uart.write(f"Sys: {sys_status}, Gyro: {gyro}, Accel: {accel}, Mag: {mag}\n".encode())
return sys_status == 3
while not check_status():
time.sleep(0.1)
print("Ready to go!")
robot.uart.write("Ready to go!\n".encode())
# Wait for start signal
while True:
if robot.uart.in_waiting:
command = robot.uart.readline().decode().strip()
if command == "start":
break
else:
print("Unknown command: {}".format(command))
time.sleep(0.1)
print("Starting")
asyncio.run(main())
+5
View File
@@ -67,3 +67,8 @@ def set_left(speed):
def set_right(speed):
set_speed(right_motor, speed)
def check_imu_status():
sys_status, gyro, accel, mag = imu.calibration_status
uart.write(f"Sys: {sys_status}, Gyro: {gyro}, Accel: {accel}, Mag: {mag}\n".encode())
return sys_status == 3