Understanding and verification of topic remapping in ROS (remap label)

insert image description here

First attach a personal summary:

  • remapThe scope outside the node label <node> ... </node>is all nodes after it;

    <node> ...  </node>  <!-- 不受remap影响 -->
    <remap />
    <node> ...  </node>  <!-- 受remap影响 -->
    
  • remapThe scope between node tags <node> ... </node>is the current node;

    <node> ...  </node>  <!-- 不受remap影响 -->
    <node>
      <remap />
    </node>  <!-- 受remap影响 -->
    <node> ...  </node>  <!-- 不受remap影响 -->
    
  • If there is no call between launches, the one in one launch remapwill not take effect in other launches;

  • If there are calls between launches, the one called in the launch remapwill not take effect in other launches;

    <!-- 被调用.launch -->
    <launch>
      <node> ... </node> <!-- 不受remap影响 -->
      <remap />
      <node> ... </node> <!-- 受remap影响 -->
    </launch>
    
    <!-- 集成.launch -->
    <launch>
      <include file="$(find xxx)被调用.launch"/>
      <node> ... </node>  <!-- 不受<被调用.launch>中的remap影响 -->
      <include file="$(find xxx)其它.launch"/>  <!-- 不受<被调用.launch>中的remap影响 -->
    </launch>
    ```xml
    
    
  • If there are calls between launches, integrate the scopes in the launch remapaccording to the order of nodes in the launch file remap;

    <launch>
      <include file="$(find xxx)xxx1.launch"/> <!-- 不受remap影响 -->
      <remap />
      <node> ... </node>  <!-- 受remap影响 -->
      <include file="$(find xxx)xxx2.launch"/>  <!-- 受remap影响 -->
    </launch>
    
  • <include> ... </include>Intra-tab inserts remapdo nothing, argpass-through does not happen like that.

    <include file="$(find xxx)xxx.launch">
      <remap />  <!-- 不起任何作用 -->
    </include>
    

Explanation in remap-wiki

Remapping allows you to “trick” a ROS node so that when it thinks it is subscribing to or publishing to /some_topic it is actually subscribing to or publishing to /some_other_topic, for instance. Topics that other nodes have subscribed to or published (let’s call
it target_topic) can’t meet my needs. Through deception and remapping, I think that I have published or subscribed to the desired (predefined in node) topic (let’s call it), but it is not (although makeup source_topicor Facelifted, but still the same). So if the remap is successful, you can only see it target_topic, not see it source_topic.

  • 官方表达
    from="original-name"
    Remapped topic: name of the ROS topic that you are remapping FROM.
    to="new-name"
    Target name: name of the ROS topic that you are pointing the from topic TO.
    this means that if you remap FROM topic “A” TO topic “B”, then whenever a node thinks it is subscribing to topic “A”, it is actually subscribing to topic “B”, so anyone publishing to topic “B” will end up getting their message to this node!
  • 简单例子
    For example, you are given a node that says it subscribes to the “chatter” topic, but you only have a node that publishes to the “hello” topic. They are the same type, and you want to pipe your “hello” topic into the new node which wants “chatter”. You can do this with this remap: <remap from="chatter" to="hello"/>
    Again, this example is from the perspective of the receiving node which subscribes to the topic. So, when this node subscribes to topic “chatter” in its source code, it is remapped to actually subscribe to “hello”, so that it ends up receiving any messages published by other ROS nodes to “hello”.

code validation

Verified with real code examples

  • Node and lauch files for experiments

    • Three nodes :

      • Node talkerpublish topic /chatter;
      • Node listener_1wants to receive topic /chatter;
      • Node listener_2wants to receive topic /good/chatter:
    • Several launches :

      • talker.launch

        <launch>
          <node name="talker" pkg="beginner_tutorials" type="talker" output="screen" />
        </launch>
        
      • listener_1.launch

          <launch>
            <node name="listener_1" pkg="beginner_tutorials" type="listener_1" output="screen" />
          </launch>
        
      • listener_2.launch

          <launch>
            <node name="listener_2" pkg="beginner_tutorials" type="listener_2" output="screen" />
          </launch>
        
      • listener_1_2.launch: node1 is called first, node2 is called later

          <launch>
          	<include file="$(find beginner_tutorials)/launch/listener_1.launch">
          	<include file="$(find beginner_tutorials)/launch/listener_2.launch">
          </launch>
        

      Now by inserting in the launch file remapto achieve node communication. remapThe caret literal is defined as follows:

      • node标签内插入

        <node>
          <remap /> 
        </node>
        
      • node上插入

        <remap />
        <node>
        </node>
        
      • node下插入

        <node>
        </node>
        <remap />
        

    Experimental results:

    serial number remap location remap direction listener_1 communication result listener_2 communication result in conclusion
    1 do not insert <remap from="/good/chatter" to="/chatter"/> success fail -
    2 listener_2.launch, inserted in the node label <remap from="/good/chatter" to="/chatter"/> success success -
    3 listener_2.launch, insert on node <remap from="/good/chatter" to="/chatter"/> success success -
    4 listener_2.launch, insert under node <remap from="/good/chatter" to="/chatter"/> success fail The scope outside the node label is the node after it , so remapit takes effect, and the node listener_2still subscribes/good/chatter
    5 talker.launch, inserted in the node label <remap from="/chatter" to="/good/chatter"/> fail success -
    6 talker.launch, insert on node <remap from="/chatter" to="/good/chatter"/> fail success The scope outside the node label is the node after it , so remapit takes effect
    7 talker.launch, insert under node <remap from="/chatter" to="/good/chatter"/> fail fail The scope outside the node label is the node after it , but remapthere is no node after this
    8 listener_1.launch, inserted in the node label <remap from="/good/chatter" to="/chatter"/> success fail The scope in node is the current node , so node listener_2still subscribes/good/chatter
    9 listener_1.launch, insert on node <remap from="/good/chatter" to="/chatter"/> success fail If there is no call between launches, the one in one launch remapwill not take effect in other launches , so node listener_2still subscribes/good/chatter
    10 listener_1.launch, insert under node <remap from="/good/chatter" to="/chatter"/> success fail If there is no call between launches, the one in one launch remapwill not take effect in other launches , so node listener_2still subscribes/good/chatter
    11 listener_1.launch, inserted in the node label <remap from="/chatter" to="/good/chatter"/> fail fail Both listeners subscribe /good/chatter, but the talker publishes/chatter
    12 listener_1.launch, insert on node <remap from="/chatter" to="/good/chatter"/> fail fail Both listeners subscribe /good/chatter, but the talker publishes/chatter
    13 listener_1.launch, insert under node <remap from="/chatter" to="/good/chatter"/> success fail The scope outside the node label is the node after it , so remapit takes effect, and the node listener_1still subscribes/chatter
    14 listener_1listener_1_2.launch , includeinserted within the label <remap from="/chatter" to="/good/chatter"/> success fail includeIntra-tab insertion remapdoesn't do anything, argdelivery doesn't happen like that , so node listener_1still subscribes/chatter
    15 listener_2listener_1_2.launch , includeinserted within the label <remap from="/good/chatter" to="/chatter"/> success fail includeIntra-tab insertion remapdoesn't do anything, argdelivery doesn't happen like that , so node listener_2still subscribes/good/chatter
    16 listener_1_2.launch, listener_1insert on <remap from="/chatter" to="/good/chatter"/> fail fail remapIf there is a call to launch, the scope is considered according to the order of the nodes in the launch file , so both listeners subscribe /good/chatter, but the talker publishes/chatter
    17 listener_1_2.launch, listener_1insert listener_2between <remap from="/good/chatter" to="/chatter"/> success success remapIf there is a call to launch, the scope considered in the order of the nodes in the launch file & the scope outside the node label is the node after it , so the node listener_2subscribes/chatter

Reference link:

Guess you like

Origin blog.csdn.net/lyh458/article/details/119269633