ros1+<remap>标签

  • roslaunch
  • XML
  • remap
ROS 2 Documentation

The ROS Wiki is for ROS 1. Are you using ROS 2 (Humble, Iron, or Rolling)?
Check out the ROS 2 Project Documentation
Related

  1. Remapping Arguments

  2. Names

ROS Topic Remapping for Nodes

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.

Quick Start: Why & How to do this

Sometimes, you may need a message on a specific ROS topic which normally only goes to one set of nodes to also be received by another node. If able, simply tell the new node to subscribe to this other topic. (有时候,你需要A节点订阅B节点的某个topic,但是A节点的cpp文件里面没不想改,这个时候你可以使用remap标签,实现让节点A订阅节点B的某个topic的功能)However, you may also do some remapping so that the new node ends up subscribing to /needed_topic when it thinks it is subscribing to /different_topic.

This could be accomplished by adding the following line to the launch file:

Now, when this node subscribes to topic /different_topic, the remapping makes it actually subscribe to topic /needed_topic. So, anyone publishing to /needed_topic ends up getting their message to this new node as well!

实现功能:不修改cpp文件订阅了某个topic.

More on the tag

The  tag allows you to pass in name remapping arguments to the ROS node that you are launching in a more structured manner than setting the args attribute of a  directly. The  tag applies to all subsequent declarations in its scope ( or ).

To understand how remapping resolves names, see Remapping Arguments and Names.

Attributes

  • 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.

Remember: 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!

Another Example

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:

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".

Important Notes

  1. Remapping applies to the lines following the remap. Nodes that are launched before any remap lines are not affected.

  2. Remapping affects both which topics a node subscribes to or publishes to. However, usually remapping is done on the subscribing node, meaning that it is actually subscribing to the remapped topic. Therefore, any publishing nodes end up getting their messages to that node by publishing to the topic specified in the to field in the remap command! This may seem backwards at first, but once understood from the perspective of the subscribing node (which is the one remapped in this example), it makes perfect sense.

你可能感兴趣的:(ros2,ros,remap)