Skip to content
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

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

Open
Ryanf55 opened this issue Jul 24, 2024 · 7 comments · May be fixed by #925
Open

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

Ryanf55 opened this issue Jul 24, 2024 · 7 comments · May be fixed by #925
Labels
help wanted Extra attention is needed

Comments

@Ryanf55
Copy link

Ryanf55 commented Jul 24, 2024

Feature request

Feature description

I want to use ros2 topic echo, copy the contents of a message in CLI, and run ros2 topic pub to publish the data without having to reformat it.

Currently, you can echo a topic like this:

$ ros2 topic echo /geo_path --once
header:
  stamp:
    sec: 0
    nanosec: 0
  frame_id: ''
poses:
- header:
    stamp:
      sec: 0
      nanosec: 0
    frame_id: ''
  pose:
    position:
      latitude: 1.0
      longitude: 2.0
      altitude: 3.0
    orientation:
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
- header:
    stamp:
      sec: 0
      nanosec: 0
    frame_id: ''
  pose:
    position:
      latitude: 4.0
      longitude: 5.0
      altitude: 6.0
    orientation:
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
---

Then, you need to tediously reformat it like this to publish:

$ ros2 topic pub /geo_path geographic_msgs/msg/GeoPath '{poses: [{pose: {position: {latitude: 1.0, longitude: 2.0, altitude: 3.0}}}, {pose: {position: {latitude: 4.0, longitude: 5.0, altitude: 6.0}}}]}'

Implementation considerations

Proposal: Allow publishing by yaml file like so:
ros2 topic pub /geo_path geographic_msgs/msg/GeoPath --yaml my_message.yaml

Where my_message.yaml is the direct YAML from ros2 topic echo.

I'm open to other alternatives such as cat operation on the yaml file and piping it to xargs.
cat my_message.yaml | xargs -I{} ros2 topic pub /geo_path geographic_msgs/msg/GeoPath {}

@clalancette
Copy link
Contributor

Does the --flow-style parameter to ros2 topic echo do what you want?

@Ryanf55
Copy link
Author

Ryanf55 commented Jul 24, 2024

Yea, looks like it does.

ros2 topic echo /geo_path --flow-style
header:
  stamp:
    sec: 0
    nanosec: 0
  frame_id: ''
poses: [{header: {stamp: {sec: 0, nanosec: 0}, frame_id: ''}, pose: {position: {latitude: 1.0, longitude: 2.0, altitude: 3.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}, {header: {stamp: {sec: 0, nanosec: 0}, frame_id: ''}, pose: {position: {latitude: 4.0, longitude: 5.0, altitude: 6.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}]
---

Then, copy the content, type the command, add quotes for the message, and paste it in.


ros2 topic pub /geo_path geographic_msgs/msg/GeoPath "header:
  stamp:
    sec: 0
    nanosec: 0
  frame_id: ''
poses: [{header: {stamp: {sec: 0, nanosec: 0}, frame_id: ''}, pose: {position: {latitude: 1.0, longitude: 2.0, altitude: 3.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}, {header: {stamp: {sec: 0, nanosec: 0}, frame_id: ''}, pose: {position: {latitude: 4.0, longitude: 5.0, altitude: 6.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}]"

If this is the intent of flow-style, perhaps the docs could make that clearer?

@clalancette
Copy link
Contributor

If this is the intent of flow-style, perhaps the docs could make that clearer?

I'm not totally sure what the original intent of it was, but certainly an update to the documentation would be welcome.

@fujitatomoya
Copy link
Collaborator

i think --flow-stype only helps the collection arrays in the block style,

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub /tf_static tf2_msgs/msg/TFMessage "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 echo --once /tf_static
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 echo --once --flow-style /tf_static
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}}}]
---

but it does not help if that is not the collection arrays,

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic echo --once /turtle1/cmd_vel
linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.8
---
root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic echo --once --flow-style /turtle1/cmd_vel
linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.8
---

If this is the intent of flow-style, perhaps the docs could make that clearer?

so probably not for this use case...

Then, copy the content, type the command, add quotes for the message, and paste it in.

this works even without --flow-style is specified,

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.8
"
publisher: beginning loop
publishing #1: geometry_msgs.msg.Twist(linear=geometry_msgs.msg.Vector3(x=2.0, y=0.0, z=0.0), angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=1.8))

publishing #2: geometry_msgs.msg.Twist(linear=geometry_msgs.msg.Vector3(x=2.0, y=0.0, z=0.0), angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=1.8))

maybe we can add some suggestion about --flow-style for collection data,

Proposal: Allow publishing by yaml file like so: ros2 topic pub /geo_path geographic_msgs/msg/GeoPath --yaml my_message.yaml

i think this is useful new feature during development and debugging, we can easily modify the certain data amount to play back by yaml file. we could use rosbag2 but that requires us to modify the backend data base to modify the data contents.

@mjcarroll
Copy link
Member

Discussion from maintenance triage: It was agreed that --flow-style is insufficient for what you are trying to accomplish. This would be a very helpful feature for the reasons that you stated above. There isn't any maintainer bandwidth to support creating these changes, but a PR would be happily accepted/reviewed.

@mjcarroll mjcarroll added the help wanted Extra attention is needed label Aug 22, 2024
@fujitatomoya fujitatomoya linked a pull request Aug 30, 2024 that will close this issue
@fujitatomoya
Copy link
Collaborator

@Ryanf55 i got some spare time to develop this, if you can try #925, that would be appreciated!

@Ryanf55
Copy link
Author

Ryanf55 commented Aug 31, 2024

Neat, I'm off on holiday weekend, but will review this when I get back Tuesday. Thanks for working on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants