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

Revision history [back]

click to hide/show revision 1
initial version

Thanks to gvdhoorn's comments, I've managed to set up some basic test which can launch a variable number of namespaces (and thus should also be capable of launching nodes in those namespaces) using recursion through including launch files.

The follow code is the launch file which called 'top_sfm_mpdm_launch.launch' and is the launch file which is called in the terminal with roslaunch.

<launch>
  <arg name="robotlist_string" default="_rdg01_rdg02_rdg03" doc="A string of robot namespace IDs prefixed with _'s. Default: '_rdg01_rdg02_rdg03'." />
  <rosparam param="robotlist_string_num" subst_value="True">$(eval arg('robotlist_string').count("_"))</rosparam>

  <include file="$(find sfm_mpdm)/launch/recursion_test.launch">
    <!-- all vars that recursion_test.launch requires must be set -->
    <arg name="robot_number" value="$(eval arg('robotlist_string').count('_'))" />
    <arg name="recursion_depth" value="1" />
    <arg name="robotlist_string" value="$(arg robotlist_string)" />
  </include>

</launch>

The included file 'recursion_test.launch' has the following code:

<launch>
  <arg name="robot_number" />
  <arg name="recursion_depth" />
  <arg name="robotlist_string" />
  <rosparam param="robot_number" subst_value="True">$(arg robot_number)</rosparam>
  <rosparam param="recursion_depth" subst_value="True">$(arg recursion_depth)</rosparam>

  <arg name="offset" value="$(eval (arg('recursion_depth')-1) * 6)" />
  <arg name="namespace" value="$(eval arg('robotlist_string')[ arg('offset')+1 : arg('offset')+6 ])" />

  <group ns="$(arg namespace)">
    <rosparam param="robot_namespace" subst_value="True">$(arg namespace)</rosparam>
  </group>

  <include file="$(find sfm_mpdm)/launch/recursion_test.launch" unless="$(eval arg('recursion_depth') == arg('robot_number'))">
      <!-- all vars that recursion_test.launch requires must be set -->
      <arg name="robot_number" value="$(arg robot_number)" />
      <arg name="recursion_depth" value="$(eval arg('recursion_depth')+1)" />
      <arg name="robotlist_string" value="$(arg robotlist_string)" />
  </include>

</launch>

The command used to launch the setup is: roslaunch sfm_mpdm top_sfm_mpdm.launch robotlist_string:=_rdg01_rgd02_rdg03_rsb06

Which produces the following parameters on the parameter server (parameter server was used for debugging and testing, you can of course launch nodes with this):

PARAMETERS
 * /rdg01/robot_namespace: rdg01
 * /rdg03/robot_namespace: rdg03
 * /recursion_depth: 4
 * /rgd02/robot_namespace: rgd02
 * /robot_number: 4
 * /robotlist_string_num: 4
 * /rosdistro: melodic
 * /rosversion: 1.14.5
 * /rsb06/robot_namespace: rsb06

(1) Now as you might have noticed. I'm using a roslaunch argument (robotlist_string) with a string _id_id_id_id e.g. _rdg01_rsb01_rdg_05_rsb_02_rsb_12 which isn't ideal. I'd rather be able to use a list of id strings, but I couldn't get this to work with eval.

(2) Similarly, I couldn't get < or <= to work with eval. So the recursion depth checking is a bit too finicky for my liking and could quite easily end up in an infinite loop..

Any help on the above two mentioned issues (1 & 2) would be great! :)