Ask Your Question
2

How do I create dynamic launch files?

asked 2016-03-18 10:38:58 -0600

inusO gravatar image

I developed a node which represent an agent in an emergent system that implements a collision avoidance algorithm. Problem is, I need to perform multiple simulations with N robots, I know I can pass N as arg to launch file, but I can't find a way to launch N nodes in the launch file.

At the moment the only solution I have is to edit the launch file.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2018-04-26 02:20:31 -0600

MartinK gravatar image

You could use eval (as of Kinetic) to create a recursive launchfile:

<launch> 

   <!-- start node -->
   <arg name="nr" default="1"/> 
   <group ns="$(eval 'turtle' + str(arg('nr')))">
      <node name="turtle" pkg="turtlesim" type="turtlesim_node"/>
   </group>

   <!-- recursively start new node -->
   <include file="$(find your_package)/launch/this_launch_file.launch" if="$(eval arg('nr') - 1 > 0)">
       <arg name="nr" value="$(eval arg('nr') - 1)"/>
   </include>

</launch>

As of Lunar you could also use $(dirname) instead of $(find your_package)/launch.

edit flag offensive delete link more

Comments

Does eval support the smaller than symbol, i.e. < ? I tried several time this code snippet, didn't work.

raphael gravatar imageraphael ( 2018-10-20 03:23:27 -0600 )edit
2

answered 2016-03-22 08:36:53 -0600

inusO gravatar image

updated 2016-03-22 08:37:20 -0600

As far as I found out, there is no way to do it with a launch file. I solved it by writing a simple python program using the roslaunch API ( http://wiki.ros.org/roslaunch/API%20U... )

edit flag offensive delete link more
3

answered 2016-03-18 17:39:17 -0600

al-dev gravatar image

I am not aware of a way to launch N instances of the node by passing N as a roslaunch parameter, however you can follow the approach given here : put the section of the roslaunch file that you want to replicate inside a namespace ns tag, and pass the value of this namespace as a command line argument. Then you can have a shell script that calls your roslaunch command (e.g roslaunch youbot_gazebo youbot_gazebo ns:=/robot$i ) in a loop, each time with a different namespace value.

edit flag offensive delete link more

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

Stats

Asked: 2016-03-18 10:38:58 -0600

Seen: 2,406 times

Last updated: Apr 26 '18