-
Notifications
You must be signed in to change notification settings - Fork 976
OM1 publish welcome mode to ROS2 #2014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6920aff
99a49fc
c30e710
fc60199
0dd651a
6a80560
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||
| 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
AI
Jan 30, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this.