Refinements - ensure gca/gcf are gone.
This commit is contained in:
parent
66a49b4ec3
commit
97018fc119
@ -11,6 +11,7 @@ class RobotDisplay:
|
||||
self.line = ""
|
||||
self.arena = {}
|
||||
self.display_closed = False
|
||||
self.fig, self.ax = plt.subplots()
|
||||
|
||||
def handle_close(self, _):
|
||||
self.display_closed = True
|
||||
@ -43,12 +44,11 @@ class RobotDisplay:
|
||||
async def main(self):
|
||||
plt.ion()
|
||||
await self.ble_connection.connect()
|
||||
self.fig, self.ax = plt.subplots()
|
||||
try:
|
||||
request = json.dumps({"command": "arena"}).encode()
|
||||
print(f"Sending request for arena: {request}")
|
||||
await self.ble_connection.send_uart_data(request)
|
||||
plt.gcf().canvas.mpl_connect("close_event", self.handle_close)
|
||||
self.fig.canvas.mpl_connect("close_event", self.handle_close)
|
||||
|
||||
while not self.display_closed:
|
||||
self.draw()
|
||||
|
||||
@ -19,7 +19,9 @@ class BleConnection:
|
||||
|
||||
async def connect(self):
|
||||
print("Scanning for devices...")
|
||||
devices = await bleak.BleakScanner.discover(service_uuids=[self.ble_uuid])
|
||||
devices = await bleak.BleakScanner.discover(
|
||||
service_uuids=[self.ble_uuid]
|
||||
)
|
||||
print(f"Found {len(devices)} devices")
|
||||
print([device.name for device in devices])
|
||||
ble_device_info = [device for device in devices if device.name==self.ble_name][0]
|
||||
|
||||
@ -4,6 +4,9 @@ import json
|
||||
import arena
|
||||
import robot
|
||||
|
||||
def send_json(data):
|
||||
robot.uart.write((json.dumps(data)+"\n").encode())
|
||||
|
||||
|
||||
async def command_handler():
|
||||
while True:
|
||||
@ -17,11 +20,10 @@ async def command_handler():
|
||||
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())
|
||||
})
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
asyncio.run(command_handler())
|
||||
|
||||
@ -12,6 +12,7 @@ class RobotDisplay:
|
||||
self.line = ""
|
||||
self.arena = {}
|
||||
self.display_closed = False
|
||||
self.fig, self.ax = plt.subplots()
|
||||
self.pose_coords = []
|
||||
self.pose_uv = []
|
||||
|
||||
@ -55,12 +56,11 @@ class RobotDisplay:
|
||||
async def main(self):
|
||||
plt.ion()
|
||||
await self.ble_connection.connect()
|
||||
self.fig, self.ax = plt.subplots()
|
||||
try:
|
||||
request = json.dumps({"command": "arena"}).encode()
|
||||
print(f"Sending request for arena: {request}")
|
||||
await self.ble_connection.send_uart_data(request)
|
||||
plt.gcf().canvas.mpl_connect("close_event", self.handle_close)
|
||||
self.fig.canvas.mpl_connect("close_event", self.handle_close)
|
||||
|
||||
while not self.display_closed:
|
||||
self.draw()
|
||||
|
||||
@ -13,6 +13,7 @@ class RobotDisplay:
|
||||
self.line = ""
|
||||
self.arena = {}
|
||||
self.display_closed = False
|
||||
self.fig, self.ax = plt.subplots()
|
||||
self.pose_coords = []
|
||||
self.pose_uv = []
|
||||
|
||||
@ -67,7 +68,6 @@ class RobotDisplay:
|
||||
async def main(self):
|
||||
plt.ion()
|
||||
await self.ble_connection.connect()
|
||||
self.fig, self.ax = plt.subplots()
|
||||
try:
|
||||
await self.send_command("arena")
|
||||
self.fig.canvas.mpl_connect("close_event", self.handle_close)
|
||||
|
||||
@ -13,6 +13,7 @@ class RobotDisplay:
|
||||
self.line = ""
|
||||
self.arena = {}
|
||||
self.display_closed = False
|
||||
self.fig, self.ax = plt.subplots()
|
||||
self.pose_coords = []
|
||||
self.pose_uv = []
|
||||
|
||||
@ -67,7 +68,6 @@ class RobotDisplay:
|
||||
async def main(self):
|
||||
plt.ion()
|
||||
await self.ble_connection.connect()
|
||||
self.fig, self.ax = plt.subplots()
|
||||
try:
|
||||
await self.send_command("arena")
|
||||
self.fig.canvas.mpl_connect("close_event", self.handle_close)
|
||||
|
||||
@ -13,6 +13,7 @@ class RobotDisplay:
|
||||
self.line = ""
|
||||
self.arena = {}
|
||||
self.display_closed = False
|
||||
self.fig, self.ax = plt.subplots()
|
||||
self.pose_coords = []
|
||||
self.pose_uv = []
|
||||
|
||||
@ -67,7 +68,6 @@ class RobotDisplay:
|
||||
async def main(self):
|
||||
plt.ion()
|
||||
await self.ble_connection.connect()
|
||||
self.fig, self.ax = plt.subplots()
|
||||
try:
|
||||
await self.send_command("arena")
|
||||
self.fig.canvas.mpl_connect("close_event", self.handle_close)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user