feature/multiple-compose #10

Merged
traverseda merged 9 commits from feature/multiple-compose into master 2024-11-15 11:17:55 -04:00
2 changed files with 9 additions and 9 deletions
Showing only changes of commit cb290395aa - Show all commits

View File

@ -151,7 +151,7 @@ class Robot:
ui.label(f"""Sysid: {self.sysid}""")
ui.button("Start", on_click=self.async_start).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"
)

View File

@ -4,13 +4,13 @@ from loguru import logger
import os
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):
def __init__(self, sysid, state: bool = False) -> None:
def __init__(self, robot_name, state: bool = False) -> None:
super().__init__()
self.sysid = sysid
self.robot_name = robot_name
self._state = state
self.button = None
with self.classes():
@ -24,7 +24,7 @@ class EnableStreamingButton(ui.element):
async def on_click(self) -> None:
spinner = ui.spinner(size="lg")
# 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:
ui.notify("Success", type="positive]")
self.set_state(state=not self._state)
@ -43,17 +43,17 @@ class EnableStreamingButton(ui.element):
def stop_video(self):
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)
@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"]
# Check if this topic has any subscribers i.e. model is up
gz_topic_list_proc = subprocess.Popen(
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,
stderr=subprocess.PIPE,
text=True,
@ -72,7 +72,7 @@ class EnableStreamingButton(ui.element):
"gz",
"topic",
"-t",
ENABLE_STREAMING_TOPIC.format(world_name=world_name, sysid=sysid),
ENABLE_STREAMING_TOPIC.format(world_name=world_name, robot_name=robot_name),
"-m",
"gz.msgs.Boolean",
"-p",