First attach a personal summary:
-
remap
The scope outside the node label<node> ... </node>
is all nodes after it;<node> ... </node> <!-- 不受remap影响 --> <remap /> <node> ... </node> <!-- 受remap影响 -->
-
remap
The 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
remap
will not take effect in other launches; -
If there are calls between launches, the one called in the launch
remap
will 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
remap
according to the order of nodes in the launch fileremap
;<launch> <include file="$(find xxx)xxx1.launch"/> <!-- 不受remap影响 --> <remap /> <node> ... </node> <!-- 受remap影响 --> <include file="$(find xxx)xxx2.launch"/> <!-- 受remap影响 --> </launch>
-
<include> ... </include>
Intra-tab insertsremap
do nothing,arg
pass-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
ittarget_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 makeupsource_topic
or Facelifted, but still the same). So if the remap is successful, you can only see ittarget_topic
, not see itsource_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
talker
publish topic/chatter
; - Node
listener_1
wants to receive topic/chatter
; - Node
listener_2
wants to receive topic/good/chatter
:
- Node
-
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
remap
to achieve node communication.remap
The 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 remap
it takes effect, and the nodelistener_2
still 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 remap
it takes effect7 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 remap
there is no node after this8 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_2
still 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 remap
will not take effect in other launches , so nodelistener_2
still 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 remap
will not take effect in other launches , so nodelistener_2
still 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 remap
it takes effect, and the nodelistener_1
still subscribes/chatter
14 listener_1
listener_1_2.launch ,include
inserted within the label<remap from="/chatter" to="/good/chatter"/>
success fail include
Intra-tab insertionremap
doesn't do anything,arg
delivery doesn't happen like that , so nodelistener_1
still subscribes/chatter
15 listener_2
listener_1_2.launch ,include
inserted within the label<remap from="/good/chatter" to="/chatter"/>
success fail include
Intra-tab insertionremap
doesn't do anything,arg
delivery doesn't happen like that , so nodelistener_2
still subscribes/good/chatter
16 listener_1_2.launch, listener_1
insert on<remap from="/chatter" to="/good/chatter"/>
fail fail remap
If 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_1
insertlistener_2
between<remap from="/good/chatter" to="/chatter"/>
success success remap
If 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 nodelistener_2
subscribes/chatter
-
Reference link: