← Back to search

[ROS Q&A] 044 - How to convert quaternions to Euler angles

The Construct Robotics Institute 17:25

15,194 views · 120 likes Watch on YouTube ↗

Full code & post of the video: http://www.theconstructsim.com/ros-qa-how-to-convert-quaternions-to-euler-angles/

Q: How to convert quaternions to Euler angles?

A: The following example can help you understand how to use the conversion from quaternions provided by an Odometry message to Euler angles Roll, Pitch and Yaw.

In the following example, you can see that the program subscribes to the odometry topic to get the orientation of a Turtlebot3 robot. Then it uses the tf.transformation functions to obtain the yaw value (the actual 'z' value or orientation of the odometry).

Then the program uses the roll, pitch and yaw to convert them back into a quaternion.

#!/usr/bin/env python
import rospy
from nav_msgs.msg import Odometry
from tf.transformations import euler_from_quaternion, quaternion_from_euler

roll = pitch = yaw = 0.0

def get_rotation (msg):
global roll, pitch, yaw
orientation_q = msg.pose.pose.orientation
orientation_list = [orientation_q.x, orientation_q.y, orientation_q.z, orientation_q.w]
(roll, pitch, yaw) = euler_from_quaternion (orientation_list)
print yaw

rospy.init_node('my_quaternion_to_euler')

sub = rospy.Subscriber ('/odom', Odometry, get_rotation)

r = rospy.Rate(1)
while not rospy.is_shutdown():
quat = quaternion_from_euler (roll, pitch,yaw)
print quat
r.sleep()

How to install Turtlebot 3 simulation in 5 minutes: https://www.youtube.com/watch?v=y54BWXInJDQ&t=133s

---------Want to learn ROS really FAST and master the latest Robotics topics?-----------
::Visit Robot Ignite Academy, the online Academy that teaches you ROS really FAST, from beginner to master, using only a web browser: https://www.robotigniteacademy.com/en/
Robot Ignite Academy is an integrated ROS learning platform which contains a series of online ROS tutorials tied to online simulations, giving you the tools and knowledge to understand and create any ROS based robotics development.

——————Are you a ROS expert and want to develop FAST your next ROS project?-----------

:: Then, use the ROS Development Studio (RDS) for your next project: http://www.theconstructsim.com/rds-ros-development-studio/
With the ROS Development Studio, you will be able to:
- Develop ROS programs for robots in a faster way, with an already setup IDE environment that includes autocomplete.
- Test the programs in real time on the provided simulated robots. Use the provided simulations or upload your own. Quickly see the results of your programming.
- Debug using graphical ROS tools.
- Test what you have developed on RDS in the real robot (if you have it :wink:
all of these are using ONLY a web browser without any installation and not limited by any operating system. DEVELOP FOR ROS USING WINDOWS, LINUX OR OSX.

Category (YouTube): Science & Technology

Playback is via YouTube's official embedded player. Data from YouTube; Exumo is not affiliated with YouTube.