Skip to content

Conversation

@maciejmajek
Copy link
Member

@maciejmajek maciejmajek commented Dec 19, 2025

Purpose

Reducing boilerplate:

from rai.communication.ros2 import ROS2Connector, ROS2Context, ROS2Message

# before
with ROS2Context():
    connector = ROS2Connector()
    connector.send_message(
        target="/test",
        message=ROS2Message(payload={"data": "Hello, ROS2!"}),
        msg_type="std_msgs/msg/String",
    )

from std_msgs.msg import String

# after
with ROS2Context():
    connector = ROS2Connector()
    connector.send_message(target="/test", message= String(data="Hello, ROS2!"))

Proposed Changes

Allow passing IROS2Message into send_message method. Msg cls validation by rosidl_runtime_py

Issues

TBD: Implementation for messages is easy, implementation for services and actions is hard. We are currently passing a dictionary and msg_type e.g. "std_srvs/srv/SetBool". Then we use the msg_type to create a Request cls and fill it with the passed dictionary.

A simpler api, coherent with new send_messages should allow:

connector.service_call(target='/my_service', message=SetBool.Request(data=True))

But to create a service client we also need to know the underlying base class (SetBool, not a SetBool.Request). Since SetBool.Request is not linked to SetBool, we will either need to keep passing msg_type via a string/cls or hack our way out with some magic.

Testing

Extended test suite

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.53%. Comparing base (074af8e) to head (864f99c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
+ Coverage   65.34%   65.53%   +0.18%     
==========================================
  Files          78       78              
  Lines        3388     3406      +18     
==========================================
+ Hits         2214     2232      +18     
  Misses       1174     1174              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants