Ros中Remap(話題重映射)的兩種使用方法(這個真的是折磨我好久的一個坑啊)

最近在remap機器人發佈的joint_states的時候遇到了一些問題,在此以幾個例子記錄一下launch文件的配置。
先敲黑板!!!:

  • remap在node之外的作用域是他之後的所有節點,在node中的作用域是當前節點,此外要注意想要remap的話題是這個節點要接收的還是要發佈的。
  • 如果是要remap一個該節點發布的source_topictarget_topic,應該是<remap from="/source_topic" to="/target_topic" />
  • 如果是要remap一個該節點想要接收的的target_topic,而實際被另外一個節點發布的話題是source_topic,應該是<remap from="/target_topic" to="/source_topic" />
    舉兩個例子!要注意區分兩種使用情況!

1、remap要發佈的話題

節點中通過ros::Publisher發佈了base/joint_states,head/joint_states,torso/joint_states,想要把發佈出來的話題重映射到joint_states上,可以這麼寫:

<?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

2、remap要接收的話題

節點中通過Ros::Subscriber想要接收/image話題,但是實際攝像頭髮布的話題是/kinect2/hd/image_color,所以需要這樣處理:

<?xml version="1.0"?>
<launch>
   <node name="robot_visual" pkg="dhrobot_demo" type="robot_visual" >
	<remap from="/image" to="/kinect2/hd/image_color" />  
  </node>  
</launch>
  • 最後附一下在終端中節點啓動時的remap方法,還是舉兩個例子,一個發佈一個接收:
rosrun joint_state_pub base/joint_states:=joint_states
rosrun robot_state_publisher /joint_states:=/base/joint_states
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章