3

Instead of running a package using command line, I made a launch file

Commande line:

rosrun image_view image_saver image:=/the-rgb-image-topic

Launch file:

<launch>
  <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera/rgb/image_raw"/>
  </node>
</launch>

Now I want to do the same for this:

rosrun image_view image_saver image:=/camera/depth/image _encoding:=16UC1

How can I add the argument to the launch file..

I think I should start it like that

<launch>
  <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera/rgb/image_raw"/>

  <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera/depth/image"/>
  </node>
</launch>
Ja_cpp
  • 2,426
  • 7
  • 27
  • 49
  • 1
    have a look to the [roslaunch XML documentation](http://wiki.ros.org/roslaunch/XML) and in particular to the [`` tag](http://wiki.ros.org/roslaunch/XML/arg). – alextoind Jun 22 '16 at 16:05
  • @alextoind: If I understand it correctly, the OP wants to set the argument within the launch-file. The `arg` tag would be used to pass arguments to the launch-file when launching it. – luator Jun 23 '16 at 07:41
  • @luator, yes probably you are right, but you can also use the `default` attribute of the `` tag to provide the default behaviour as in your answer plus an external access to that parameter, if needed. – alextoind Jun 23 '16 at 08:49

1 Answers1

2

To pass arbitrary arguments to nodes in launch-files, you can use the args attribute of the node tag:

<node name="image_saver" pkg="image_view" type="image_saver" args="_encoding:=16UC1" ...>

However, in this specific case there is a better way: _encoding is not just some arbitrary argument but it is a parameter that is handled by the ROS Parameter Server. While it will probably work, using the args attribute, the nicer way is to use the param tag:

<node name="image_saver" pkg="image_view" type="image_saver">
    <remap from="image" to="/camera/depth/image" />
    <param name="encoding" value="16UC1" type="string" />
</node>
luator
  • 4,769
  • 3
  • 30
  • 51