ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

Quaternion and dual quaternion operations

I developed a package for using dual quaternions and conversions from and to ROS Pose and Transform messages in Python. Dual quaternions are an alternative to homogeneous transformation matrices that provide many benefits such as compactness, a direct relation to screw parameters, easy normalization, and an extension to quaternion SLERP for translations + rotations. They’re also mathematically pleasing :slight_smile:. I’d love to hear if there’s interest in getting this released.

I’m working on releasing this package to apt with bloom. Since dual quaternions consist of two quaternions, the package relies on an underlying quaternion python package, which AFAICT doesn’t exist in apt. I was using numpy-quaternion at first but that package will be hard to release into apt because of its dependencies. I am considering releasing pyquaternion (with some modifications) or a custom package. I wanted to hear from the community what they want to see in such a package or if another similar package is in the works. As it stands, I would be releasing 4 packages to keep the python code separated from the ROS code: dual-quaternions, quaternions, dual-quaternions-ros, and quaternions-ros.


Just a heads-up, I almost only use C++ and I work mostly with ROS2, so I’m not sure how a lot of stuff works in ROS1 and python, in case this is a very silly question

Is there a plan to somehow integrate this with TF, or how and when would this be useful in a robot system? Sorry for my ignorance :stuck_out_tongue: I believe you if you tell me dual quaternions are awesome, but the only usage of quaternions I’m aware of in ROS is “behind the scenes” for TF.

Good job either way ^^

TF is designed to hide the implementation so you can use any linear math library you want with tf. There are tutorials for adding support for both c++ and Python Once you have the bridge to the linear math library that you want you can keep operating with that libraries primatives. Both Bullet and Eigen provide Quaternion classes. It looks like this can add quaternion support to numpy.

I am planning on writing a C++ interface to this as well, very similar to how @tfoote 's angles package is set up. The reason for starting with Python is that there aren’t any stable dual quaternion packages out there unlike in C++ as many graphics folks use dual quaternions regularly.

Your question ‘why should we care’ is super valid and the main reason I’m promoting this package! The answer depends on your use case. When you’re using transformations mostly to convert points from one frame to another and other basics, you’re probably not going to be better off switching. If you’re however writing a new algorithm that heavily relies on transformations (e.g. new Unscented Kalman Filter for SLAM, an optimization algorithm for sensor extrinsic calibration), dual quaternions might be interesting as they can greatly simplify the code and improve speed because their manifold fits the underlying problem well. Most optimization algorithms for minimizing some kind of transformation error have struggled with representations that split up translation and rotation (matrices, euler angles or quaternions + translation vector) because they require separate optimizations and additional work to tie those together. Since dual quaternions combine translation and rotation intuitively, you can do ‘simultaneous optimization’. To see how dual quaternions behave (take a step on the manifold), take a look at the visualization gif in the readme. Compare that with matrix interpolation or its Lie algebra (tangent at the identity) or with quaternion + translation interpolation where the interpolation is a straight line and rotation happens uniformly along that line.
If this sounds interesting, definitely take a look at the references in the readme. I’m still working on my explanation. Let me know if you have questions or suggestions!

Interesting, once dual quaternions is released it would be great to get those bridges in place with TF.
Regarding the quaternion support to numpy, as I stated I’m looking into switching to pyquaternion as opposed to numpy-quaternion since the latter requires numpy>=1.13 and numba. However the former package doesn’t integrate into numpy as tightly as numpy-quaternion does. I prefer numpy-quaternion but I don’t know if and how I can release those requirements. Would love to hear your thoughts on this.