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

ROS2 Python quaternion to euler

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

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: https://github.com/ros2/geometry2

I really appreciate if you could guide me.

BR

edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted
1

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

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
5

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

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:

https://automaticaddison.com/how-to-c...

edit flag offensive delete link more

Comments

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 -0600 )edit
5

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

nsprague gravatar image

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...

edit flag offensive delete link more

Comments

2

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 -0600 )edit
1

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

sbalmagro gravatar image

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...

edit flag offensive delete link more
-5

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

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...

edit flag offensive delete link more

Comments

5

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 -0600 )edit

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

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

Question Tools

4 followers

Stats

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

Seen: 9,114 times

Last updated: Jan 11 '21