message_tf_frame_transformer

Transforms messages of arbitrary type to a different frame using tf2::doTransform

README

message_tf_frame_transformer

The message_tf_frame_transformer package provides a ROS / ROS 2 node(let) to transform ROS messages of arbitrary type to a different coordinate frame. This can be helpful if you cannot or do not want to modify the source code of other ROS nodes that require your data to be valid in a specific coordinate frame. Simply launch the message_tf_frame_transformer node and transform arbitrary ROS message to a target coordinate frame.

Installation

The message_tf_frame_transformer package is released as an official ROS / ROS 2 package and can easily be installed via a package manager.

sudo apt install ros-$ROS_DISTRO-message-tf-frame-transformer

If you would like to install message_tf_frame_transformer from source, simply clone this repository into your ROS workspace. All dependencies that are listed in the ROS package.xml can be installed using rosdep.

# message_tf_frame_transformer$
rosdep install -r --ignore-src --from-paths .

# ROS 2
# workspace$
colcon build --packages-up-to message_tf_frame_transformer --cmake-args -DCMAKE_BUILD_TYPE=Release

# ROS
# workspace$
catkin build -DCMAKE_BUILD_TYPE=Release message_tf_frame_transformer

docker-ros

message_tf_frame_transformer is also available as a Docker image, containerized through docker-ros.

# ROS
docker run --rm ghcr.io/ika-rwth-aachen/message_tf_frame_transformer:ros

# ROS 2
docker run --rm ghcr.io/ika-rwth-aachen/message_tf_frame_transformer:ros2

Usage

In order to transform messages on topic $INPUT_TOPIC to frame $TARGET_FRAME_ID and publish them to topic $OUTPUT_TOPIC, the message_tf_frame_transformer node can be started with the following topic remappings and parameter setting. Only the target_frame_id parameter is required. The source_frame_id parameter is only required for non-stamped messages without an std_msgs/Header. The topics default to ~/input and ~/transformed in the node’s private namespace.

# ROS 2
ros2 run message_tf_frame_transformer message_tf_frame_transformer --ros-args \
  -r \~/input:=$INPUT_TOPIC \
  -r \~/transformed:=$OUTPUT_TOPIC \
  -p source_frame_id:=$SOURCE_FRAME_ID \
  -p target_frame_id:=$TARGET_FRAME_ID

# ROS
rosrun message_tf_frame_transformer message_tf_frame_transformer \
  ~input:=$INPUT_TOPIC \
  ~transformed:=$OUTPUT_TOPIC \
  _source_frame_id:=$SOURCE_FRAME_ID \
  _target_frame_id:=$TARGET_FRAME_ID

The provided launch file enables you to directly launch a tf2_ros/static_transform_publisher alongside the message_tf_frame_transformer node. This way you can transform a topic to a new coordinate frame with a single command.

# ROS 2
 ros2 launch message_tf_frame_transformer message_tf_frame_transformer.launch.ros2.xml \
  input_topic:=$INPUT_TOPIC \
  output_topic:=$OUTPUT_TOPIC \
  source_frame_id:=$SOURCE_FRAME_ID \
  target_frame_id:=$TARGET_FRAME_ID \
  x:=$X \
  y:=$Y \
  z:=$Z \
  roll:=$ROLL \
  pitch:=$PITCH \
  yaw:=$YAW

# ROS
roslaunch message_tf_frame_transformer message_tf_frame_transformer.launch \
  input_topic:=$INPUT_TOPIC \
  output_topic:=$OUTPUT_TOPIC \
  source_frame_id:=$SOURCE_FRAME_ID \
  target_frame_id:=$TARGET_FRAME_ID \
  xyzrpy:="$X $Y $Z $ROLL $PITCH $YAW"

Supported Message Types

The message_tf_frame_transformer package is able to support any ROS message type that integrates with tf2::doTransform. Currently, the following message types are explicitly supported.

ROS

ROS 2

Remarks

geometry_msgs/Point

geometry_msgs/msg/Point

geometry_msgs/PointStamped

geometry_msgs/msg/PointStamped

geometry_msgs/Pose

geometry_msgs/msg/Pose

geometry_msgs/PoseStamped

geometry_msgs/msg/PoseStamped

geometry_msgs/PoseWithCovariance

geometry_msgs/msg/PoseWithCovariance

geometry_msgs/PoseWithCovarianceStamped

geometry_msgs/msg/PoseWithCovarianceStamped

geometry_msgs/Quaternion

geometry_msgs/msg/Quaternion

geometry_msgs/QuaternionStamped

geometry_msgs/msg/QuaternionStamped

geometry_msgs/Transform

geometry_msgs/msg/Transform

geometry_msgs/TransformStamped

geometry_msgs/msg/TransformStamped

geometry_msgs/Vector3

geometry_msgs/msg/Vector3

geometry_msgs/Vector3Stamped

geometry_msgs/msg/Vector3Stamped

geometry_msgs/Wrench

geometry_msgs/msg/Wrench

geometry_msgs/WrenchStamped

geometry_msgs/msg/WrenchStamped

sensor_msgs/PointCloud2

sensor_msgs/msg/PointCloud2

Only the first three point cloud channels (usually xyz) are transformed.

Adding Support for a New Message Type

Through application of preprocessor macros, adding support for a new ROS message type is as easy as adding only two lines of code. Note that the ROS message types have to integrate with tf2::doTransform. Feel free to open a pull request to add support for more message types!

  1. message_types.h (ROS) / message_types.ros2.hpp (ROS 2)

    • include required message headers

  2. message_types.macro (ROS) / message_types.ros2.macro (ROS 2)

    • define information about the new message type by calling the MESSAGE_TYPE macro

      • TYPE: ROS message type (e.g. geometry_msgs::msg::PointStamped)

      • NAME: (ROS 2 only) ROS message type name (e.g. geometry_msgs/msg/PointStamped)

Nodes/Nodelets

ROS 2

Package

Node

Description

message_tf_frame_transformer

message_tf_frame_transformer

transform arbitrary ROS messages to a different coordinate frame

ROS

Package

Node

Nodelet

Description

message_tf_frame_transformer

message_tf_frame_transformer

MessageTfFrameTransformer

transform arbitrary ROS messages to a different coordinate frame

message_tf_frame_transformer/message_tf_frame_transformer

Subscribed Topics

Topic

Type

Description

~/input

see Supported Message Types

message to transform

Published Topics

Topic

Type

Description

~/transformed

see Supported Message Types

transformed message

Services

-

Actions

-

Parameters

Parameter

Type

Description

~/target_frame_id

string

target frame ID

~/source_frame_id

string

source frame ID (optional; if message has no std_msgs/Header)

Acknowledgements

This research is accomplished within the project 6GEM (FKZ 16KISK036K). We acknowledge the financial support for the project by the Federal Ministry of Education and Research of Germany (BMBF).