Ask Your Question

How to set arg to a node from launch file?

asked 2012-10-16 05:06:35 -0500

aldo85ita gravatar image

Hi everybody, I can't set the args of my gscam node by launch file (this node is different from the original,because I modified it). This is the most important piece of source of my modified gscam node:

int main(int argc, char** argv) {
    if (argc != 2)
        ROS_WARN("WARNING: you should specify camera info properties!");
         ROS_INFO("INFO: you have set camera properties file: %s\n",argv[1]);

This is a piece of my launch file:

<node pkg="gscam" type="gscam"
  <env name="GSCAM_CONFIG"
       value="multifilesrc location=&quot;/home/aldo/Documents/VISIONE/visual_odometry/libviso2/2010_03_09_drive_0019/I1_%06d.png&quot; index=0 num-buffers=-1  caps=&quot;image/png,framerate=\(fraction\)19/10\&quot; ! videorate framerate=19/10 ! pngdec ! ffmpegcolorspace"/>

this is the got message when I run "roslaunch my_file.launch --screen" :

[ WARN] [1350399215.805837395]: WARNING: you should specify camera info properties!

Note: If I run my gscam node without launch file it works properly (the argument is recognized):

rosrun gscam gscam /home/aldo/Projects/4thRC/BergamoComponents/services_caller/camera_parameters_to_set.txt
[ INFO] [1350399865.086125707]: INFO: you have set camera properties file: /home/aldo/Projects/4thRC/BergamoComponents/services_caller/camera_parameters_to_set.txt

How to fix it?

edit retag flag offensive close merge delete


Have you tried printing out how many and what arguments are passed? It might be that you're receiving more than 2 arguments from the launch file.

Ivan Dryanovski gravatar imageIvan Dryanovski ( 2012-10-16 05:14:08 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2012-10-16 05:13:47 -0500

dornhege gravatar image

updated 2012-10-16 06:28:55 -0500

Your argc condition is wrong. You don't account for the additional parameters that roslaunch gives the node.

Either change your condition or call ros::init before your code, if possible. That should filter out ROS arguments.

edit flag offensive delete link more

answered 2018-01-24 15:10:49 -0500

Jacob gravatar image

You can use ros::removeROSArgs(argc,argv,args) to strip out the command-line options added by ROS. It returns args, an std::vector<std::string> which should contain the program name followed by whatever arguments you passed.

edit flag offensive delete link more

answered 2012-10-16 05:26:06 -0500

aldo85ita gravatar image

updated 2012-10-16 05:54:04 -0500

The solution is to count the number of arguments after ros::init :

ros::init(argc, argv, "gscam_publisher");
    if (argc != 2)
            ROS_WARN("WARNING: you should specify camera info properties!");
             ROS_INFO("INFO: you have set camera properties file: %s\n",argv[1]);

Because ROS add 2 further arguments to the node if you start it from the launch file. (I mean two arguments more than the basic rosnode command).

edit flag offensive delete link more


You will need to elaborate on this condition. If you use roslaunch without args your condition will trigger the second case and assume __name:=gscam is the file. Better try calling ros::init before to remove the ROS arguments.

dornhege gravatar imagedornhege ( 2012-10-16 05:37:09 -0500 )edit

Thank you @dornhege, you're right! If you run condition code after ros::int I get the same number of arguments both in roslaunch and in rosnode executions. I'll public the code with solution, you can copy it in a new answer and I'll give you points for the right answer.

aldo85ita gravatar imagealdo85ita ( 2012-10-16 05:50:17 -0500 )edit

Please do not open answers for discussion or comments. This is not a forum. Instead, please either edit your original question or use the comment functionality.

Lorenz gravatar imageLorenz ( 2012-10-16 06:30:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-10-16 05:06:35 -0500

Seen: 4,084 times

Last updated: Oct 29 '12