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

roslaunch file using rosparam

asked 2014-08-06 19:05:15 -0500

vbplaya gravatar image

updated 2014-08-07 15:57:35 -0500

I'm trying to write a roslaunch file which opens a few nodes with unique ip addresses which are provided in a yaml file. If I wanted to start each one using terminals for each I would type it in as follows:

rosrun foo_pkg foo_node 1 192.168.100.10
rosrun foo_pkg foo_node 2 192.168.100.20

I want to be able to open them all in one launch file:

FIRST TRY SIMPLY CODING INTO LAUNCH FILE:

     <launch>
       <node   name="FOO1"
               pkg="foo_pkg"
               type="foo_node"
               args="1 192.168.100.10"
               output="screen"/>
       <node   name="FOO2"
               pkg="foo_pkg"
               type="foo_node"
               args="2 192.168.100.20"
               output="screen"/>
     </launch>
This didn't work, I guess I can't put the arguments in this way but don't know how to put them in correctly. **In the end I want it to get these values from a launch file like below:**
     ip:  
       board1:  
         num: 1  
         address: '192.168.10.10'  
       board2:  
         num: 2  
         address: '192.168.10.20'

So my main question is ... HOW CAN I USE THE ROSPARAMS INSIDE THE ROSLAUNCH FILE TO PROPERLY LAUNCH THEM?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-08-07 02:17:24 -0500

ahendrix gravatar image

I think you're on the right track, but you've misunderstood the XML syntax of launch files.

Try:

<launch>
  <node   name="FOO1"
          pkg="foo_pkg"
          type="foo_node"
          args="1 192.168.100.10"
          output="screen"/>
  <node   name="FOO2"
          pkg="foo_pkg"
          type="foo_node"
          args="2 192.168.100.20"
          output="screen"/>
</launch>
edit flag offensive delete link more

Comments

Actually, I already had it exactly like this ... I just don't know how to put the greater than and less than symbols in message without it thinking it is actual xml code to execute.

vbplaya gravatar image vbplaya  ( 2014-08-07 10:56:41 -0500 )edit

You question was completely unclear about that.

ahendrix gravatar image ahendrix  ( 2014-08-07 12:23:49 -0500 )edit

You say that this launch file "didn't work." There are serveral hundred things that might cause it to not work. Can you edit your question to include the exact command and the exact output from the command?

ahendrix gravatar image ahendrix  ( 2014-08-07 12:25:38 -0500 )edit

It turns out my code was correct already (exactly yours shown above). Problem was that when you add the "args" line to the code it sends the args you entered along with 2 others: "__name:=FOO1" and "__log:= ...". I had code in the other files which verified correct # of args.

vbplaya gravatar image vbplaya  ( 2014-08-07 15:34:00 -0500 )edit

My code accounted for too few and too many args ... so I thought it was exiting because it had 0 args when it was actually because of too many.

vbplaya gravatar image vbplaya  ( 2014-08-07 15:35:04 -0500 )edit

I finally figured out how to put the code in without messing up when using the greater than or less than symbols! That took a while ... sadly. Thanks for your help. Do you have any idea on the second part of my question about how I can assign the args by means of the rosparam yaml file I load?

vbplaya gravatar image vbplaya  ( 2014-08-07 16:01:49 -0500 )edit

I think @bvbdort 's answer does a good job of describing how to set parameters in a launch file and how to retrieve them from C++.

ahendrix gravatar image ahendrix  ( 2014-08-07 16:19:03 -0500 )edit
1

answered 2014-08-07 02:30:47 -0500

bvbdort gravatar image

updated 2014-08-07 02:32:46 -0500

Use param tag inside launchfile

<launch>
   <node pkg="foo_pkg " type="foo_node" name="foo_node" output="screen">    
    <param name="num" value="1" />
    <param name="address" value="192.168.10.10" />  
  </node>
 <node pkg="foo_pkg " type="foo_node" name="foo_node" output="screen">    
    <param name="num" value="2" />
    <param name="address" value="192.168.100.20" />  
  </node>    
</launch>

Inside your node

ros::NodeHandle private_nh_("~");

std::string address_;
int num_;

private_nh_.param("address", address_, "0.0.0.0"); // 0.0.0.0 as default 
private_nh_.param("num", num_, 0); // 0 as default 

// your stuff using params here
edit flag offensive delete link more

Comments

This is how it is done on a regular basis? It seems excessive to have to go into my source code for each of my packages and add the above code replacing my normal:
int main (int argc, char *argv[])
{
ipAdd = argv[1];
...
}

vbplaya gravatar image vbplaya  ( 2014-08-07 11:06:08 -0500 )edit

if you want to use with name this way is useful, if you know the order , you can co with argv[1]... way.

bvbdort gravatar image bvbdort  ( 2014-08-07 11:11:48 -0500 )edit

It just seems like if I can call a node from the terminal

rosrun foo_pkg foo_node 1 192.168.100.10

without any knowledge of internal code parameter names. I should be able to do it in the launch file that way as well. Maybe a system call from inside the launch file would work?

vbplaya gravatar image vbplaya  ( 2014-08-07 11:17:08 -0500 )edit

you should know how the code accessing parameters, if you are using node from other packages check the documentation.

bvbdort gravatar image bvbdort  ( 2014-08-07 11:49:08 -0500 )edit

I agree I should know ... and I do. I just feel that it should be more straight forward approach which doesn't involve changing code to accommodate my launch file. I found on the ROSwiki "how" to do it but I've got it exactly this way and it isn't working. See next comment (comments are too short)

vbplaya gravatar image vbplaya  ( 2014-08-07 12:07:35 -0500 )edit

See http://wiki.ros.org/roslaunch/XML

Half way down page in "A More Complicated Example"
comment: Pass args to the listener node

<node name="listener-2" pkg="rospy_tutorials" type="listener" args="-foo arg2"/>

vbplaya gravatar image vbplaya  ( 2014-08-07 12:08:09 -0500 )edit

Apparently the way I had it coded originally was correct (see original question). The reason it was failing was due to it adding a couple args ("__name:" and "__log:"). This caused a problem with my code which looks for the correct number of args. Thanks for your help.

vbplaya gravatar image vbplaya  ( 2014-08-07 16:00:00 -0500 )edit

very good finally you fixed it. I thought your node is reading params "num", "address" like the way you mentioned at the end of your question.

bvbdort gravatar image bvbdort  ( 2014-08-07 16:09:42 -0500 )edit

Question Tools

Stats

Asked: 2014-08-06 19:05:15 -0500

Seen: 1,516 times

Last updated: Aug 07 '14