Using GCA and GCF causes weird stuff to happen when buttons are added.

This commit is contained in:
Danny Staple
2022-11-15 22:34:17 +00:00
parent 1cfd93887b
commit 2c91a42160
9 changed files with 81 additions and 65 deletions
@@ -38,6 +38,9 @@ class Simulation:
finally:
robot.stop()
def send_json(data):
robot.uart.write((json.dumps(data)+"\n").encode())
async def command_handler(simulation):
simulation_task = None
while True:
@@ -51,11 +54,10 @@ async def command_handler(simulation):
continue
# {"command": "arena"}
if request["command"] == "arena":
response = {
send_json({
"arena": arena.boundary_lines,
"target_zone": arena.target_zone,
}
robot.uart.write((json.dumps(response)+"\n").encode())
})
elif request["command"] == "start":
print("Starting simulation")
if simulation_task is None or simulation_task.done():
@@ -66,10 +68,18 @@ async def command_handler(simulation):
simulation_task.cancel()
simulation_task = None
else:
response = {
"poses": simulation.poses.tolist(),
}
robot.uart.write((json.dumps(response)+"\n").encode())
sys_status, gyro, accel, mag = robot.imu.calibration_status
if sys_status != 3:
send_json({"imu_calibration": {
"gyro": gyro,
"accel": accel,
"mag": mag,
"sys": sys_status,
}})
else:
send_json({
"poses": simulation.poses.tolist(),
})
await asyncio.sleep(0.1)
simulation= Simulation()