ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange

ROS2 Python quaternion to euler

Dear ROS community,

I am trying to use the function "quaternion to euler" using python for ROS2 eloquent, but I can not import the right library.

Here there is not example related to that: https://github.com/ros2/geometry2

I really appreciate if you could guide me.

BR

edit retag close merge delete

Sort by ยป oldest newest most voted

For anyone who stumbles upon this in the future, now there is a function available in the tf_transformations library called euler_from_quaternion in ROS2 Humble and above.

You can use it by importing it first from tf_transformations import euler_from_quaternion

Then convert the quaternion to roll, pitch, yaw by

orientation_list = [orientation_q.x, orientation_q.y, orientation_q.z, orientation_q.w]

(roll, pitch, yaw) = euler_from_quaternion(orientation_list)

self.pose_yaw = yaw

more

if @nsprague's answer does not satisfy you, and you do not want to use transforms3d library, you can also implement the function yourself:

more

Hello, I read since hours about this topic but I'm totally lost now. I need a way to build a Quaternion from Euler in Python for ROS2 Foxy as my IMU Sensor only provide YPR as Euler. Do I really need to build a method in Python to do this by my own? Is there really no build-in functionality I can use? I found some example using c++ there they build a Quaternion by something like:

q = tf2::Quaternion() q.setRPY(r, p, y)

Is there no equivalent in Python for this? I can'T find any example on this.

( 2021-01-11 13:56:39 -0500 )edit

You may be looking for the transformations.py file that is associated with tf. Here is an issue explaining why it doesn't exist in tf2:

https://github.com/ros/geometry2/issu...

more

2

TL/DR: ros2 should stay lightweight. An idea is to package transforms3d library for ROS2 like it was done for kinetic.

( 2020-12-26 14:59:47 -0500 )edit

Thank you very much for all the replies.

As a workaround, I have found an implementation of the transformations:

https://gist.github.com/salmagro/2e69...

more

A simple google search of that question title resulted in several other questions and links with examples; please consider doing a little legwork before asking here.

https://www.theconstructsim.com/ros-q...

more

5

( 2020-10-02 05:37:22 -0500 )edit

But I have.... downvote! And upvote for you Luca

( 2021-07-29 07:52:56 -0500 )edit