Remap(話題重映射)應用實例及作用範圍探究

最近在remap機器人發佈的joint_states的時候遇到了一些問題,在此以幾個例子記錄一下launch文件的配置。
先上結論:remap應該在節點啓動前使用。
1.首先是最開始無效的版本(無效方式1 )。

<?xml version="1.0"?>
<launch>

    <group ns="dhrobot">
        <node name="robot_driver" pkg="dhrobot_driver" type="robot_driver" />
    </group>
    
   		<remap from="base/joint_states" to="joint_states" />
        <remap from="head/joint_states" to="joint_states" />
        <remap from="torso/joint_states" to="joint_states" /> 
        
</launch>

結果看到

/dhrobot/torso/joint_states
/dhrobot/head/joint_states
/dhrobot/base/joint_states

這三個話題,話題並沒有被重映射。
2.然後我覺得可能是我的group作用域問題,就把remap移動到了group中進行嘗試(無效方式2 )。

<?xml version="1.0"?>
<launch>

    <group ns="dhrobot">
        <node name="robot_driver" pkg="dhrobot_driver" type="robot_driver" />
        <remap from="base/joint_states" to="joint_states" />
        <remap from="head/joint_states" to="joint_states" />
        <remap from="torso/joint_states" to="joint_states" /> 
    </group>
    
</launch>

發現結果和上面一樣。

/dhrobot/torso/joint_states
/dhrobot/head/joint_states
/dhrobot/base/joint_states

3.最後我讀了一下官方說明`remap,發現說明文檔是這樣說的:
<remap>標記適用於其範圍內的所有後續聲明(<launch>,<node>或<group>)。那說明remap應該在節點前使用。
遂修改如下(有效方式):

<?xml version="1.0"?>
<launch>

    <group ns="dhrobot">
        <remap from="base/joint_states" to="joint_states" />
        <remap from="head/joint_states" to="joint_states" />
        <remap from="torso/joint_states" to="joint_states" /> 
        <node name="robot_driver" pkg="dhrobot_driver" type="robot_driver" />
    </group>

</launch>

終於成功了,rostopic list一下可以看到話題:

/dhrobot//joint_states

又嘗試把remap放到group外面的發現寫相對topic的remap也是可以的。
就說明remap必須在節點前面才能生效,不知道爲什麼那麼多網上的程序把remap放在launch文件後面。

 附一下在節點啓動時的remap方法:
rosrun joint_state_pub base/joint_states:=joint_states
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章