Skip to content

support ros2 topic pub yaml file input#925

Merged
ahcorde merged 4 commits intorollingfrom
fujitatomoya/support-ros2-topic-pub-yaml-file
Feb 7, 2025
Merged

support ros2 topic pub yaml file input#925
ahcorde merged 4 commits intorollingfrom
fujitatomoya/support-ros2-topic-pub-yaml-file

Conversation

@fujitatomoya
Copy link
Copy Markdown
Collaborator

closes #919

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
Copy link
Copy Markdown
Collaborator Author

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

This enables the following command line option with ros2 topic pub.

Note that yaml files are saved with ros2 topic echo > xxx.yaml.

root@tomoyafujita:~/ros2_ws/colcon_ws# cat chatter.yaml
---
data: 'Hello ROS Users'
---
---
data: Hello ROS Developers
---
data: Hello ROS Developers
---
---
data: 'Hello ROS Users'

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub /chatter std_msgs/msg/String --yaml-file chatter.yaml
publisher: beginning loop
publishing #1: std_msgs.msg.String(data='Hello ROS Users')

publishing #2: std_msgs.msg.String(data='Hello ROS Developers')

publishing #3: std_msgs.msg.String(data='Hello ROS Developers')

publishing #4: std_msgs.msg.String(data='Hello ROS Users')

root@tomoyafujita:~/ros2_ws/colcon_ws# cat tf2.yaml
transforms:
- header:
    stamp:
      sec: 1721935886
      nanosec: 528868866
    frame_id: foo
  child_frame_id: bar
  transform:
    translation:
      x: 1.0
      y: 2.0
      z: 3.0
    rotation:
      x: -0.4747921762038255
      y: -0.07596622270177095
      z: 0.24006245183344296
      w: 0.8433098728485138
---
transforms:
- header:
    stamp:
      sec: 1721935886
      nanosec: 528868866
    frame_id: foo
  child_frame_id: bar
  transform:
    translation:
      x: 1.0
      y: 2.0
      z: 3.0
    rotation:
      x: -0.4747921762038255
      y: -0.07596622270177095
      z: 0.24006245183344296
      w: 0.8433098728485138

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub /tf_static tf2_msgs/msg/TFMessage --yaml-file tf2.yaml
publisher: beginning loop
publishing #1: tf2_msgs.msg.TFMessage(transforms=[geometry_msgs.msg.TransformStamped(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=1721935886, nanosec=528868866), frame_id='foo'), child_frame_id='bar', transform=geometry_msgs.msg.Transform(translation=geometry_msgs.msg.Vector3(x=1.0, y=2.0, z=3.0), rotation=geometry_msgs.msg.Quaternion(x=-0.4747921762038255, y=-0.07596622270177095, z=0.24006245183344296, w=0.8433098728485138)))])

publishing #2: tf2_msgs.msg.TFMessage(transforms=[geometry_msgs.msg.TransformStamped(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=1721935886, nanosec=528868866), frame_id='foo'), child_frame_id='bar', transform=geometry_msgs.msg.Transform(translation=geometry_msgs.msg.Vector3(x=1.0, y=2.0, z=3.0), rotation=geometry_msgs.msg.Quaternion(x=-0.4747921762038255, y=-0.07596622270177095, z=0.24006245183344296, w=0.8433098728485138)))])

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

@mjcarroll @clalancette @sloretz what do you think? this can be useful for test and development.

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

CC: @ahcorde if you have time, can you take a look?

Copy link
Copy Markdown
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

This is a simplification of a rosbag, not sure about this feature, let's see what other people thing about it

Comment thread ros2topic/ros2topic/verb/pub.py Outdated
Comment thread ros2topic/ros2topic/verb/pub.py Outdated
@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

This is a simplification of a rosbag, not sure about this feature, let's see what other people thing about it

yeah that is true.

the difference what i think of is, probably much easier to use and modify the data contents that are saved as yaml via ros2 topic echo. we have a chat about this in triage meeting, #919 (comment) but yes lets get more feedback for this feature. see usage for #925 (review)

CC: @Ryanf55 @mjcarroll @clalancette

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

@clalancette @sloretz what do you think about this option? it would be really easier for user to update the data contents and publish it compared to rosbag2.

Copy link
Copy Markdown

@Ryanf55 Ryanf55 left a comment

Choose a reason for hiding this comment

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

Sorry, I realized I never submitted my review. This functions exactly as I requested. I'm a big fan of this feature and would love to see it merged.

I think it's a much more usable way to publish messages and be able to edit the contents in a human readable way.

Currently, I would write a shell script with `ros2 topic pub /my_topic my_pkg/mytype
"{
and: [manually_formatted_yaml, in_a_shell_script]
}"

Where it's easy to mess up the syntax in a shell script without yaml syntax in my editor. This PR represents a significant improvement in readability and helps me document in README's example messages to publish to affect the state of my robotic system.

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

We talked about this feature a bit in ROS PMC meeting today. after all feature makes sense, so i will keep this open for review.

@MichaelOrlov i do not think of the necessity to use rosbag2_py APIs here, what do you think?

Comment thread ros2topic/ros2topic/verb/pub.py Outdated
Comment thread ros2topic/ros2topic/verb/pub.py Outdated
@ros-discourse
Copy link
Copy Markdown

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/ros-pmc-meeting-minutes-2024-12-03/40941/1

Copy link
Copy Markdown

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

Hi @fujitatomoya, Conceptually, it looks good to me. However, I didn't do a thorough review.

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

@MichaelOrlov @clalancette thanks for the review and comments, i will address them soon.

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

Pulls: #925
Gist: https://gist.githubusercontent.com/fujitatomoya/5a498ad800e7b1dfa97f49c29afd8b27/raw/08a9f35c751b73a5ed630c8df618acf0fa32743b/ros2.repos
BUILD args: --packages-above-and-dependencies ros2topic
TEST args: --packages-above ros2topic
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/14926

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

…--stdin`.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya fujitatomoya force-pushed the fujitatomoya/support-ros2-topic-pub-yaml-file branch from 853e7f2 to b03cf8a Compare December 9, 2024 21:02
@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

Pulls: #925
Gist: https://gist.githubusercontent.com/fujitatomoya/76ff99794019cd2719103d04a39aac40/raw/08a9f35c751b73a5ed630c8df618acf0fa32743b/ros2.repos
BUILD args: --packages-above-and-dependencies ros2topic
TEST args: --packages-above ros2topic
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/14927

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

@clalancette i have addressed your comments, and all tests are passing locally. can i have your approval?

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

@clalancette @ahcorde can i have an approval either of you?

@ahcorde
Copy link
Copy Markdown
Contributor

ahcorde commented Feb 7, 2025

Pulls: #925
Gist: https://gist.githubusercontent.com/ahcorde/c7c617a575741538b5c0c5fa6ecb7ade/raw/f2d5d6ad5b722461450f91d2aecf19b59310172b/ros2.repos
BUILD args: --packages-up-to ros2topic --packages-above-and-dependencies ros2topic
TEST args: --packages-select ros2topic --packages-above ros2topic
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15135

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

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.

Allow ros2 topic echo output to be used in ros2 topic pub

7 participants