Enable straming now takes robot name
Build Docs / build (push) Failing after 52s Details

This commit is contained in:
Alex Davies 2024-11-14 13:46:50 -04:00
parent 10d6bd0c8b
commit cb290395aa
2 changed files with 9 additions and 9 deletions

View File

@ -151,7 +151,7 @@ class Robot:
ui.label(f"""Sysid: {self.sysid}""") ui.label(f"""Sysid: {self.sysid}""")
ui.button("Start", on_click=self.async_start).classes("m-2") ui.button("Start", on_click=self.async_start).classes("m-2")
ui.button("Stop", on_click=self.async_stop).classes("m-2") ui.button("Stop", on_click=self.async_stop).classes("m-2")
self.video_button = EnableStreamingButton(sysid=self.sysid).classes( self.video_button = EnableStreamingButton(robot_name=self.robot_name).classes(
"m-2" "m-2"
) )

View File

@ -4,13 +4,13 @@ from loguru import logger
import os import os
GZ_TOPIC_INFO = ["gz", "topic", "-i", "-t"] GZ_TOPIC_INFO = ["gz", "topic", "-i", "-t"]
ENABLE_STREAMING_TOPIC = "/world/{world_name}/model/spiri-{sysid}/link/pitch_link/sensor/camera/image/enable_streaming" ENABLE_STREAMING_TOPIC = "/world/{world_name}/model/{robot_name}/link/pitch_link/sensor/camera/image/enable_streaming"
class EnableStreamingButton(ui.element): class EnableStreamingButton(ui.element):
def __init__(self, sysid, state: bool = False) -> None: def __init__(self, robot_name, state: bool = False) -> None:
super().__init__() super().__init__()
self.sysid = sysid self.robot_name = robot_name
self._state = state self._state = state
self.button = None self.button = None
with self.classes(): with self.classes():
@ -24,7 +24,7 @@ class EnableStreamingButton(ui.element):
async def on_click(self) -> None: async def on_click(self) -> None:
spinner = ui.spinner(size="lg") spinner = ui.spinner(size="lg")
# So we don't block UI # So we don't block UI
result = await run.cpu_bound(self.enable_streaming, self.sysid, not self._state) result = await run.cpu_bound(self.enable_streaming, self.robot_name, not self._state)
if result: if result:
ui.notify("Success", type="positive]") ui.notify("Success", type="positive]")
self.set_state(state=not self._state) self.set_state(state=not self._state)
@ -43,17 +43,17 @@ class EnableStreamingButton(ui.element):
def stop_video(self): def stop_video(self):
if self._state != False: if self._state != False:
self.enable_streaming(sysid=self.sysid, is_streaming=False) self.enable_streaming(robot_name=self.robot_name, is_streaming=False)
self.set_state(state=False) self.set_state(state=False)
@staticmethod @staticmethod
def enable_streaming(sysid: int, is_streaming: bool) -> bool: def enable_streaming(robot_name: str, is_streaming: bool) -> bool:
world_name = os.environ["WORLD_NAME"] world_name = os.environ["WORLD_NAME"]
# Check if this topic has any subscribers i.e. model is up # Check if this topic has any subscribers i.e. model is up
gz_topic_list_proc = subprocess.Popen( gz_topic_list_proc = subprocess.Popen(
GZ_TOPIC_INFO GZ_TOPIC_INFO
+ [ENABLE_STREAMING_TOPIC.format(world_name=world_name, sysid=sysid)], + [ENABLE_STREAMING_TOPIC.format(world_name=world_name, robot_name=robot_name)],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
@ -72,7 +72,7 @@ class EnableStreamingButton(ui.element):
"gz", "gz",
"topic", "topic",
"-t", "-t",
ENABLE_STREAMING_TOPIC.format(world_name=world_name, sysid=sysid), ENABLE_STREAMING_TOPIC.format(world_name=world_name, robot_name=robot_name),
"-m", "-m",
"gz.msgs.Boolean", "gz.msgs.Boolean",
"-p", "-p",