roslaunch multiple node arguments

asked 2020-02-19 07:16:40 -0600

zahid990170 gravatar image

updated 2020-02-19 09:22:40 -0600

Hi,

I have the following launch file smp.launch. In particular, notice the <node /> part of the file.

<launch>

<arg
    name="option"
    default="1"
  />

  <arg
    name="coll_object"
    default="0"
  />

  <node name="ur5" pkg="ur5_moveit_path_planner" type="ur5" respawn="false" output="screen" args="$(arg option)" />
</launch>

As long as I specify just a single argument named option,

roslaunch ur5_moveit_path_planner smp.launch option:="2"

my program runs and I can see the expected output. However, I would like to add more command line arguments. I specify two arguments, as follows:

<node name="ur5" pkg="ur5_moveit_path_planner" type="ur5" respawn="false" output="screen" args="$(arg option) $(arg coll_object)" />

Now, I run the program as follows:

roslaunch ur5_moveit_path_planner smp.launch option:="1" coll_object:="0"

I am getting a very strange behavior. The program just halts, with a certain error message.

[ur5-5] process has died [pid 20708, exit code 1, cmd /home/zahid/Desktop/IMPLEMENTATIONS/zahid_test_ws/devel/lib/ur5_moveit_path_planner/ur5 1 0 __name:=ur5 __log:=/home/zahid/.ros/log/03002cba-5304-11ea-afe2-34e12da72407/ur5-5.log].
log file: /home/zahid/.ros/log/03002cba-5304-11ea-afe2-34e12da72407/ur5-5*.log

Is there something wrong regarding how I provide command line arguments to the node. What is the correct way to pass multiple command line arguments to the node?

thanks,

edit retag flag offensive close merge delete

Comments

Hi,

I assume ur5 is cpp node. The problems comes when you pass your arguments. In a normal cpp program you deal with arguments passed to the executable file in the main process E.g.: int main(int argc, char** argv), argv[0] is the program name and from that point forwards you will find all arguments passed to the program in order.

If you are not accessing properly to the argv array you will get a runtime error.

Another way of passing arguments is just using the parameter server implemented in ROS.

Weasfas gravatar image Weasfas  ( 2020-02-24 10:44:49 -0600 )edit

Hi, thanks @Weasfas, yes, it is a cpp node. When I have to get the value of option passed as a command line argument, I consider it as int selection = atoi(argv[1]); within my main program, and it works ok. I tried to access coll_object as follows int coll_flag = atoi(argv[2]); It does not generate a compile time error, but at runtime. I will check the other option that you specified.

zahid990170 gravatar image zahid990170  ( 2020-02-26 10:21:03 -0600 )edit