Robotics StackExchange | Archived questions

What is the best way to transform the frame of a twist?

Hi all, before searching for an external library, I would like to know if ROS/ROS2 have a module to convert a twist from a frame to another. In particular I would like to convert a visual odometry twist from the camera frame to the base_link for obvious reasons.

Thanks Walter

Asked by Myzhar on 2022-07-03 05:35:14 UTC

Comments

Answers

Maybe standard tf2 library will suit you - there you have a nice tutorial from Nav2 documentation:

https://navigation.ros.org/setup_guides/transformation/setup_transforms.html

(...)

Now let’s try publishing a very simple transform using the static_transform_publisher tool provided by TF2. We will be publishing a transformation from the link base_link to the link base_laser with a translation of (x: 0.1m, y: 0.0m, z: 0.2m). Note that we will be building the transform from the diagram earlier in this tutorial.

Open up your command line and execute the following command:

ros2 run tf2_ros static_transform_publisher 0.1 0 0.2 0 0 0 base_link base_laser

With this, we are now sucessfully publishing our base_link to base_laser transform in TF2. Let us now check if it is working properly through tf2_echo. Open up a separate command line window and execute the following:

ros2 run tf2_ros tf2_echo base_link base_laser

You should be able to observe a repeated output simiar to the one below.

At time 0.0
- Translation: [0.100, 0.000, 0.200]
- Rotation: in Quaternion [0.000, 0.000, 0.000, 1.000]

Asked by ljaniec on 2022-07-03 07:22:08 UTC

Comments

As far as I know TF2 does not provide twist transformation, but only pose transformation. Twist transformations require Lie Algebra SO(3), Sophus is a known library providing it, but I do not know if it's directly available for ROS/ROS2: https://github.com/strasdat/Sophus

Asked by Myzhar on 2022-07-03 07:29:42 UTC

Ok, I misunderstood your question, sorry. But fear not, Sophus is used in ROS 1: https://wiki.ros.org/sophus and some users ported it to ROS2 as well: https://github.com/stonier/sophus (e.g. for Turtlebot 2 migration from ROS1 to ROS2)

Asked by ljaniec on 2022-07-03 11:20:28 UTC

Could make for a nice contribution: transforming Twist (and Accel and further derivatives) has been requested a couple of times already. The accepted answer is typically along the lines of: convert to your math framework of choice, transform there, then convert back to ROS/TF.

But the same argument could be made for transforming regular Poses as well.

Perhaps a package extending TF with transform(..) methods for Twist et al. using something like Sophus could fill this gap, in a nice pluggable way (ie: contribute to the tf namespace, not extending base tf2_ros itself).

Asked by gvdhoorn on 2022-07-05 01:43:01 UTC