simplest multiple-robot scenario

Was having trouble getting multiple robots to work, so I tried to boil it down to the simplest possible scenario. Here's what I have for a launch file:

<?xml version="1.0" encoding="utf-8"?>
<launch>
<group ns="ns0">
<param name="robot_description" command="cat '$(find urdf_tutorial)/urdf/01-myfirst.urdf'"/> <node name="my_stp" pkg="tf" type="static_transform_publisher" args="-1 0 0 0 0 0 /map base_link 100"/> <node name="my_jsp" pkg="joint_state_publisher" type="joint_state_publisher"/> <node name="my_rsp" pkg="robot_state_publisher" type="state_publisher"/> </group> <group ns="ns1"> <param name="robot_description" command="cat '$(find urdf_tutorial)/urdf/02-multipleshapes.urdf'"/>
<node name="my_stp" pkg="tf" type="static_transform_publisher" args="1 0 0 0 0 0 /map base_link 100"/>
<node name="my_jsp" pkg="joint_state_publisher" type="joint_state_publisher"/>
<node name="my_rsp" pkg="robot_state_publisher" type="state_publisher"/>
</group>

<node name="rviz" pkg="rviz" type="rviz" respawn="false" output="screen" args="-d $(find xxx)/config/xxx.rviz"/> </launch> And my xxx.rviz is the same as default.rviz with the addition of two RobotModels: - Alpha: 1 Class: rviz/RobotModel Collision Enabled: false Enabled: true Links: All Links Enabled: true Expand Joint Details: false Expand Link Details: false Expand Tree: false Link Tree Style: Links in Alphabetic Order Name: RobotModel Robot Description: ns0/robot_description TF Prefix: "" Update Interval: 0 Value: true Visual Enabled: true - Alpha: 1 Class: rviz/RobotModel Collision Enabled: false Enabled: true Links: All Links Enabled: true Expand Joint Details: false Expand Link Details: false Expand Tree: false Link Tree Style: "" Name: RobotModel Robot Description: ns1/robot_description TF Prefix: "" Update Interval: 0 Value: true Visual Enabled: true I would expect this to show 01-myfirst.urdf at position (-1,0,0) and 02-multipleshapes.urdf at position (1,0,0). However, it shows 02-multipleshapes.urdf flickering back and forth between the two positions. 01-myfirst.urdf is not shown at all. Can anyone explain what I'm missing? edit retag close merge delete Comments Are the link names (and thus tf frame ids) different between your 2 robots? If you had 2 identical robots and did not set a robot name prefix via something like a xacro argument (or hardcoded) then I would expect to see this behaviour. TF doesn't namespace without a lot of work by the user. ( 2017-06-07 19:51:29 -0600 )edit I should add that with your specific example, I would look at the name of the "root" of the 2 robots, and see if they have the same TF frame id. You could try http://wiki.ros.org/rqt_tf_tree as a debug tool. ( 2017-06-07 19:55:57 -0600 )edit The root is called "base_link" in both models. If I change the name of one of them then this scenario behaves as expected. Thank you. I guess I'll read about how to deal with namespaces in TF. Or is there are alternative to doing this sort of thing that works better? ( 2017-06-08 10:01:57 -0600 )edit I would recommend against using namespaces to resolve this sort of problem, nothing in TF is designed to be namespaced. ( 2017-06-08 10:50:07 -0600 )edit I would suggest looking at http://wiki.ros.org/urdf/Tutorials/Us... for how to use prefixes in XACRO files as a way to keep naming consistent for the tyepes of joints, but on different robots. ( 2017-06-08 10:50:31 -0600 )edit 1 Answer Sort by » oldest newest most voted Thank you for the comments. Based on those and some help from a local ROS expert, I have gotten things working like so: <?xml version="1.0" encoding="utf-8"?> <launch> <group ns="ns0"> <param name="tf_prefix" value="ns0"></param> <param name="robot_description" command="cat '$(find urdf_tutorial)/urdf/01-myfirst.urdf'"/>
<node name="my_stp" pkg="tf" type="static_transform_publisher" args="-1 0 0 0 0 0 map ns0/base_link 100"/>
<node name="my_rsp" pkg="robot_state_publisher" type="state_publisher"/>
</group>

<group ns="ns1">
<param name="tf_prefix" value="ns1"></param>
<param name="robot_description" command="cat '$(find urdf_tutorial)/urdf/02-multipleshapes.urdf'"/> <node name="my_stp" pkg="tf" type="static_transform_publisher" args="1 0 0 0 0 0 map ns1/base_link 100"/> <node name="my_rsp" pkg="robot_state_publisher" type="state_publisher"/> </group> <node name="rviz" pkg="rviz" type="rviz" respawn="false" output="screen" args="-d$(find xxx)/config/xxx.rviz"/>
</launch>

The tf_prefix params make the link names unique in each .urdf (almost as if they respected namespaces). And in the .rviz file I just added "TF Prefix: ns0" and "TF Prefix: ns1" to their respective RobotModel sections.

These changes take care of the problem of TF not handling namespaces, but it sure would be simpler if namespaces just worked across all of ROS. There's probably a good reason for it I'm not seeing yet, but I just started using ROS a few weeks ago.

I have not yet tried Dale's suggestion of using prefixes in a .xacro file. From what I have read I believe it's a very similar solution to what I have here.

more

1

I don't know a whole lot about the differences between TF and TF2, but using TF prefixes instead of XACRO prefixs may cause you trouble down the road: http://wiki.ros.org/tf2/Migration . I don't expect problems, just thought I'd point it out so you are aware of it should it ever become relevant.

( 2017-06-09 00:16:20 -0600 )edit