Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions config/unitree_go2_autonomy_sim.json5
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
},
},
agent_actions: [
{
name: "move_go2_autonomy",
llm_label: "move",
connector: "unitree_sdk_advance",
},
// {
// name: "move_go2_autonomy",
// llm_label: "move",
// connector: "unitree_sdk_advance",
// },
Comment on lines +41 to +45
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

{
name: "speak",
llm_label: "speak",
Expand All @@ -69,5 +69,14 @@
{
type: "UnitreeGo2State",
},
{
type: "WelcomeStatusPublisher",
config: {
ros2_topic: "om/welcome",
zenoh_topic: "om/welcome",
message: "welcome mode",
interval: 1.0,
},
},
],
}
127 changes: 127 additions & 0 deletions src/backgrounds/plugins/welcome_status_publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import logging

from pydantic import Field

from backgrounds.base import Background, BackgroundConfig

try:
from providers.ros2_publisher_provider import ROS2PublisherProvider
except Exception:
ROS2PublisherProvider = None
Comment on lines +7 to +10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it


try:
import zenoh
except Exception:
zenoh = None

try:
from zenoh_msgs import String, open_zenoh_session
except Exception:
String = None
open_zenoh_session = None
Comment on lines +12 to +21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please import it directly



class WelcomeStatusPublisherConfig(BackgroundConfig):
"""Configuration for welcome status publisher."""

ros2_topic: str = Field(
default="om/welcome",
description="ROS2 topic name to publish to (if ROS2 available)",
)
zenoh_topic: str = Field(
default="om/welcome", description="Zenoh topic name to publish to (fallback)"
)
message: str = Field(
default="welcome mode", description="Status message to publish"
)
interval: float = Field(default=1.0, description="Seconds between publishes")


class WelcomeStatusPublisher(Background[WelcomeStatusPublisherConfig]):
"""
Background that periodically publishes a simple status message.

Attempts to use the ROS2 publisher provider (`ROS2PublisherProvider`) if
available so a standard ROS2 node can subscribe. If ROS2 isn't available
in the environment, falls back to publishing a `zenoh_msgs.String` on the
configured Zenoh topic.
"""

def __init__(self, config: WelcomeStatusPublisherConfig):
super().__init__(config)

self.ros2_provider = None
self.zenoh_session = None
self.zenoh_pub = None

# Try ROS2 provider
if ROS2PublisherProvider is not None:
try:
self.ros2_provider = ROS2PublisherProvider(topic=self.config.ros2_topic)
try:
self.ros2_provider.start()
except Exception:
# start may already have been called elsewhere
pass
Comment on lines +63 to +65
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently catching all exceptions when calling start() makes it difficult to distinguish between 'already started' and actual errors. Consider checking a provider state flag or catching a more specific exception type if the provider raises one for 'already started' scenarios.

Suggested change
except Exception:
# start may already have been called elsewhere
pass
except Exception as e:
# start may already have been called elsewhere; log for diagnostics
logging.debug("WelcomeStatusPublisher: ROS2 provider start() failed (may already be started): %s", e)

Copilot uses AI. Check for mistakes.
logging.info(
"WelcomeStatusPublisher: using ROS2 publisher on %s",
self.config.ros2_topic,
)
except Exception as e:
logging.warning("Could not initialize ROS2 publisher provider: %s", e)

# If ROS2 not available or failed, try zenoh
if (
self.ros2_provider is None
and zenoh is not None
and open_zenoh_session is not None
and String is not None
):
try:
self.zenoh_session = open_zenoh_session()
self.zenoh_pub = self.zenoh_session.declare_publisher(
self.config.zenoh_topic
)
logging.info(
"WelcomeStatusPublisher: using Zenoh publisher on %s",
self.config.zenoh_topic,
)
except Exception as e:
logging.warning("Could not initialize Zenoh publisher: %s", e)

def run(self) -> None:
"""Main execution loop for publisher."""
if self.should_stop():
return

text = self.config.message

# Prefer ROS2
if self.ros2_provider is not None:
try:
self.ros2_provider.add_pending_message(text)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The add_pending_message method is being passed a plain string, but the ROS2PublisherProvider may expect a specific message type. Verify that ROS2PublisherProvider correctly handles string messages, or consider using a standard ROS2 String message type to ensure compatibility with ROS2 subscribers.

Copilot uses AI. Check for mistakes.
logging.debug("Published welcome message via ROS2: %s", text)
except Exception as e:
logging.warning("Failed to publish via ROS2 provider: %s", e)

# Fallback to Zenoh
elif self.zenoh_pub is not None and String is not None:
try:
msg = String(text)
# Some msg types expect .serialize()
try:
payload = msg.serialize()
except Exception:
# fallback to sending raw string bytes
payload = str(text).encode("utf-8")

self.zenoh_pub.put(payload)
logging.debug("Published welcome message via Zenoh: %s", text)
except Exception as e:
logging.warning("Failed to publish via Zenoh: %s", e)

else:
logging.debug("No publisher available for WelcomeStatusPublisher")

# Sleep until next publish or until stopped
self.sleep(self.config.interval)
Loading