ros2 / ros2cli

ROS 2 command line interface tools
Apache License 2.0
173 stars 159 forks source link

Load a message or request from a yaml file (or standard input) #842

Closed ymd-stella closed 1 year ago

ymd-stella commented 1 year ago

Feature request

Feature description

I want to load a message/request from a yaml file, not from the command line. The benefits of this would be similar to #753.

Targets are

In my opinion, it would be neat to be able to do the following

cat foo.yaml | ros2 topic pub <topic_name> <msg_type>

Implementation considerations

This maybe conflicts with the functionality of #753. Similar functionality may be achieved with cat foo.yaml | vipe | tee foo.yaml | ros2 topic pub <topic_name> <msg_type>.

fujitatomoya commented 1 year ago

this sounds reasonable to me. it would be useful.

ymd-stella commented 1 year ago

I noticed that the last argument is optional. For example, the following is valid.

ros2 topic pub foo std_msgs/Empty

Should we add an option like --stdin to keep the default behavior?

cat foo.yaml | ros2 topic pub --stdin <topic_name> <msg_type>
clalancette commented 1 year ago

Should we add an option like --stdin to keep the default behavior?

Yes, definitely.

ymd-stella commented 1 year ago

This maybe conflicts with the functionality of https://github.com/ros2/ros2cli/pull/753. Similar functionality may be achieved with cat foo.yaml | vipe | tee foo.yaml | ros2 topic pub .

Using vscode, this could be achieved with the following command.

export EDITOR="code --wait"
cat foo.yaml | vipe | tee tmp.yaml | ros2 topic pub foo std_msgs/Header --stdin; mv tmp.yaml foo.yaml
jrutgeer commented 1 year ago

Interesting.

I have never used ROS 1, but according to the wiki it seems that rostopic pub supported piped input, but also had a -f flag to read from file:

$ rostopic echo chatter > chatter.bagy
Collect messages, then Ctrl-C
$ rostopic pub -f chatter.bagy bar std_msgs/String

Given the problem statement:

I want to load a message/request from a yaml file, not from the command line.

Would you consider to also add the -f flag to ros2 topic pub?