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

Is there a environmental variable for current namespace in launchfiles?

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

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

Hi,

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)/xacro.py $(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>

    <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" />
</group>

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: https://github.com/ros/robot_state_pu...

Regards,

Christian

edit retag flag offensive close merge delete

Comments

1

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 -0500 )edit
1

Thanks for the hint @130s

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

1 Answer

Sort by ยป oldest newest most voted
1

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

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"
          name="robot_state_publisher">
          <param name="robot_description" value="robot_description"/>
          <param name="publish_frequency" value="30.0"/>
          <param name="tf_prefix"    value="$(arg ns)"/>
    </node>
</group>

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

Question Tools

2 followers

Stats

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

Seen: 788 times

Last updated: Jul 04 '15