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

ROS2 Python quaternion to euler

asked 2020-06-25 09:18:18 -0500

sbalmagro gravatar image

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:

I really appreciate if you could guide me.


edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted

answered 2022-10-07 09:01:34 -0500

rros gravatar image

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

edit flag offensive delete link more

answered 2020-12-26 15:02:12 -0500

leuko gravatar image

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

edit flag offensive delete link 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.

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

answered 2020-06-25 15:02:18 -0500

nsprague gravatar image

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

edit flag offensive delete link more



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

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

answered 2021-01-11 14:17:13 -0500

sbalmagro gravatar image

Thank you very much for all the replies.

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

edit flag offensive delete link more

answered 2020-06-25 14:29:48 -0500

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.

edit flag offensive delete link more



Your link goes to a tutorial to use "euler_from_quaternion" on ROS1, the user asked for help on ROS2. I don't have enough point to downvote your answer

luca.fancellu gravatar image luca.fancellu  ( 2020-10-02 05:37:22 -0500 )edit

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

Andromeda gravatar image Andromeda  ( 2021-07-29 07:52:56 -0500 )edit

Question Tools



Asked: 2020-06-25 09:18:18 -0500

Seen: 4,877 times

Last updated: Jan 11 '21