Know turn behaviour for chapter 12.
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user