Home

Awesome

topic_tools

This package is the ROS 2 port of https://wiki.ros.org/topic_tools

Tools for directing, throttling, selecting, and otherwise manipulating ROS 2 topics at a meta-level. These tools do not generally perform serialization on the streams being manipulated, instead acting on generic binary data using rclcpp's GenericPublisher and GenericSubscription.

The tools in this package are provided as composable ROS 2 component nodes, so that they can be spawned into an existing process, launched from launchfiles, or invoked from the command line.

Components

Relay

Relay is ROS 2 node that subscribes to a topic and republishes all incoming data to another topic. It can work with any message type.

Usage

ros2 run topic_tools relay <intopic> [outtopic]

Subscribe to intopic and republish to either

E.g. rename base_scan to my_base_scan:

ros2 run topic_tools relay base_scan my_base_scan

Parameters

RelayField

RelayField is a ROS 2 node that allows to republish data in a different message type.

Usage

ros2 run topic_tools relay_field <input topic> <output topic> <output type> [<expression on m>]

Subscribe to input topic and republish one or many of its fields onto another field in a different message type

E.g. publish the contents of the data field in a std_msgs/msg/String onto the frame_id field of a std_msgs/msg/Header:

ros2 run topic_tools relay_field /chatter /header std_msgs/Header "{stamp: {sec: 0, nanosec: 0}, frame_id: m.data}"

Transform

Transform is a ROS 2 node that allows to take a topic or one of it fields and output it on another topic.

Usage

ros2 run topic_tools transform <input topic> <output topic> <output type> [<expression on m>] [--import <modules>] [--field <topic_field>]

Subscribe to input topic and convert topic content or its field into

E.g. transform imu orientation to norm:

ros2 run topic_tools transform /imu --field orientation /norm std_msgs/Float64 'std_msgs.msg.Float64(data=numpy.sqrt(numpy.sum(numpy.array([m.x, m.y, m.z, m.w]))))' --import std_msgs numpy

Throttle

Throttle is ROS 2 node that subscribes to a topic and republishes incoming data to another topic, either at a maximum bandwidth or maximum message rate.

Usage

throttle message (rate)

ros2 run topic_tools throttle messages <intopic> <msgs_per_sec> [outtopic]

Throttle messages on intopic to a particular rate.

E.g. throttle bandwidth-hogging laser scans (base_scan) to 1Hz:

ros2 run topic_tools throttle messages base_scan 1.0

throttle bytes (bandwidth)

ros2 run topic_tools throttle bytes <intopic> <bytes_per_sec> <window> [outtopic]

Throttle messages on intopic to a particular rate.

E.g. throttle bandwidth-hogging laser scans (base_scan) to 1KBps:

ros2 run topic_tools throttle bytes base_scan 1024 1.0

Parameters

Drop

Drop is ROS 2 node that can subscribe to a topic and republish incoming data to another topic, dropping X out of every Y incoming messages. It's mainly useful for limiting bandwidth usage, e.g., over a wireless link. It can work with any message type.

Usage

ros2 run topic_tools drop <intopic> <X> <Y> [outtopic]

Subscribe to <intopic> and drop every <X> out of <Y> messages.

E.g. drop every other message published to base_scan:

ros2 run topic_tools drop base_scan 1 2

Parameters

Mux

mux is a ROS2 node that subscribes to a set of incoming topics and republishes incoming data from one of them to another topic, i.e., it's a multiplexer that switches an output among 1 of N inputs. Services are offered to switch among input topics, and to add and delete input topics. At startup, the first input topic on the command line is selected.

Usage

ros2 run topic_tools mux <outopic> <intopic1> [intopic2...]

Subscribe to <intopic1>...N and publish currently selected topic to outopic. mux will start with <intopic1> selected.

E.g. mux two command streams (auto_cmdvel and joystick_cmdvel) into one (sel_cmdvel):

ros2 run topic_tools mux sel_cmdvel auto_cmdvel joystick_cmdvel

Parameters

Delay

Delay is a ROS 2 node that can subscribe to a topic and republish incoming data to another topic, delaying the message by a fixed duration. It's useful to simulate computational results with high latency.

Usage

ros2 run topic_tools delay <intopic> <delay> [outtopic]

Subscribe to <intopic> and republish on <outtopic> delayed by <delay>.

E.g. delay messages published to base_scan by 500ms:

ros2 run topic_tools delay base_scan 0.5

Parameters