Ask Your Question

Is there a environmental variable for current namespace in launchfiles?

asked 2015-06-28 18:43:21 -0600

updated 2015-07-04 10:19:02 -0600


I have created an multirobot launch for Gazebo. Now I found out that there is a solvable problem with the namespace in the robot state publisher. I solved it with adding a tf_prefix. But now here is what I am interested in.

Is it possible to get the current namespace into the

 <param name="tf_prefix" value="robotA"/>

instead of writing the namespace name? Is there an environment variable that I could for example write something like this to get the "current namespace" for a parameter?:

 <param name="tf_prefix" value="$(optenv ns)"/> <!--  CAUTION: THIS IS NOT A WORKING SOLUTION  -->

Unfortunately robot state publisher does not care about the namespace like for example the gazebo plugins do, if you do not add an tf_prefix they add it automatically.

I also know that there is the possibility to include this by a separate launchfile and add an argument for that.

<!--ROBOT A-->  
<group ns="robotA" clear_params="true">
    <param name="robot_description" command=
    "$(find xacro)/ $(find h4r_rapid_robot_xacros)/defs/test_robots/diff_drive_bot.xacro" />

    <node pkg="robot_state_publisher" 
          type="state_publisher" name="robot_state_publisher">
        <param name="tf_prefix" value="robotA"/><!-- Is needed, for adding the namespace to other links -->
        <param name="publish_frequency" type="double" value="30.0"/>

    <node name="spawn_test_bot" pkg="gazebo_ros" type="spawn_model" 
          args="-z 0.2 -x 0 -urdf -param robot_description -model robot_description" 
          respawn="false" />

Code is here

Or can I make this code (robot_state_publisher)

  std::string tf_prefix_key;
  n_tilde.searchParam("tf_prefix", tf_prefix_key);
  n_tilde.param(tf_prefix_key, tf_prefix_, std::string(""));

return the current namespace into tf_prefix_ somehow?

UPDATE: I added a pull request for the robot state publisher to be able to use the current namespace as prefix, as long as there is not another approach:



edit retag flag offensive close merge delete



Just a headsup, tf_prefix is deprecated in tf2. And have you looked at this?

130s gravatar image 130s  ( 2015-07-04 07:51:26 -0600 )edit

Thanks for the hint @130s

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-04 10:23:11 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-04 10:22:19 -0600

A way around my problem meanwhile is:

<arg name="ns" default="/" /> <!-- empty strings are not allowed for namespace ! -> "/" -->
<group ns="$(arg ns)">  

    <node pkg="robot_state_publisher" type="robot_state_publisher" output="screen"
          <param name="robot_description" value="robot_description"/>
          <param name="publish_frequency" value="30.0"/>
          <param name="tf_prefix"    value="$(arg ns)"/>

Unfortunatley this requires to have a group inside the launchfile. But the launchfile can be used with or without namespace.

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



Asked: 2015-06-28 18:43:21 -0600

Seen: 455 times

Last updated: Jul 04 '15