ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to combine string args in launch file?

asked 2017-07-21 07:32:46 -0500

marcoresk gravatar image

updated 2017-07-21 07:33:18 -0500

This is my starting .launch file

  <launch>
<!-- usb webcam video0 -->
  <node name="usb_cam0" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video0" />
  </node>
 </launch>

Now I would like to pass that zero as an argument by a command like

roslaunch mypackage mylauncher.launch N:=0

so I thought

  <launch>
<arg name="N"/>
<!-- usb webcam video number N as indicated in the argument -->
  <node name="usb_cam0" pkg="usb_cam" type="usb_cam_node" output="screen" >
   <param name="video_device" value="/dev/video$(arg N)" />
  </node>
 </launch>

Of course it does not work. I'm not an axpert at all of xml-like files... maybe the error is the combination of the string? Or there is a way to do this better?

My final purpose is to allow the access to any video source with inputs in the launchfile

dev/video0
dev/video1
dev/video2

etc.

Thank you in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-07-21 08:30:07 -0500

gvdhoorn gravatar image

updated 2017-07-21 08:30:55 -0500

Of course it does not work

can you tell us what you see, if it does not work?

This:

<launch>
  <arg name="n" />
  <param name="something" value="/dev/video$(arg n)"/>
</launch>

started as roslaunch my_pkg test.launch n:=4 result in:

something: /dev/video4

on my system.

See wiki/roslaunch/XML/arg and wiki/roslaunch/XML/param.

edit flag offensive delete link more

Comments

I tried again after some time, now it works. Thank you for the proof.

marcoresk gravatar image marcoresk  ( 2017-09-01 05:30:17 -0500 )edit
0

answered 2020-12-30 16:45:09 -0500

htanwar922 gravatar image

See $(eval <expr>). You may thus do it as:

<launch>
  <arg name="n" />
  <param name="something" value="$(eval '/dev/video' + arg('n'))"/>
</launch>
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-21 07:32:46 -0500

Seen: 2,801 times

Last updated: Dec 30 '20