问题描述
根据单个urdf模型加载多个相同的模型到rviz中
主要利用launch的group标签和robot_state_publisher的tf_prefix标签。
基础
joint_state_publisher_gui发布joint_states话题,该话题被robot_state_publisher进行订阅(该订阅的话题名可以通过remap标签进行重映射),然后计算出模型各个关节之间的坐标变换,即tf
launch的group ns标签会将所有在该group内的结点及其话题(收发)封装在对应的ns(命名空间)中
robot_state_publisher的tf_prefix标签会在robot_state_publisher发布的tf坐标信息之前加上相应的tf_prefix
实现
<launch>
<group ns="jaka1">
<param name="robot_description" textfile="urdf/jaka_zu7_1200.xml" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" >
<param name="tf_prefix" value="jaka1" />
<!-- <remap from="/joint_states" to="/robot_driver/joint_states"/>-->
</node>
<node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" />
</group>
<group ns="jaka2">
<param name="robot_description" textfile="urdf/jaka_zu7_1200.xml" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" >
<param name="tf_prefix" value="jaka2" />
</node>
<node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" />
</group>
<node pkg="tf" type="static_transform_publisher" name="T_world_jaka1"
args="0 0 0 0 0 0 /world /jaka1/base_link 100" />
<node pkg="tf" type="static_transform_publisher" name="T_world_jaka2"
args="0 1.0 0 0 0 0 /world /jaka2/base_link 100" />
<node name="rviz" pkg="rviz" type="rviz" args="-d dual_jaka.rviz" />
</launch>
上述launch执行后上传的参数及启动的结点如下
PARAMETERS
* /jaka1/robot_description: <?xml version="1....
* /jaka1/robot_state_publisher/tf_prefix: jaka1
* /jaka2/robot_description: <?xml version="1....
* /jaka2/robot_state_publisher/tf_prefix: jaka2
* /rosdistro: melodic
* /rosversion: 1.14.13
NODES
/
T_world_jaka1 (tf/static_transform_publisher)
T_world_jaka2 (tf/static_transform_publisher)
rviz (rviz/rviz)
/jaka1/
joint_state_publisher_gui (joint_state_publisher_gui/joint_state_publisher_gui)
robot_state_publisher (robot_state_publisher/robot_state_publisher)
/jaka2/
joint_state_publisher_gui (joint_state_publisher_gui/joint_state_publisher_gui)
robot_state_publisher (robot_state_publisher/robot_state_publisher)
根据上述的参数及结点信息,很容易判断group ns标签的作用
rviz配置
添加RobotModel,修改对应的Robot description和tf prefix
结果如下图