ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

convert the yaw Euler angle into into the range [0 , 360].

asked 2014-03-18 06:59:36 -0600

underwater gravatar image

Hi everyone,

I used the following code to get the yaw Euler angle:

// Convert quaternion to RPY.
  tf::Quaternion q;
  tf::quaternionMsgToTF(imu_msg->orientation, q);
  tf::Matrix3x3(q).getRPY(roll, pitch, yaw);

I get the Euler angle varying from [0,PI] and [-PI, 0]

I need rotation angles in the range of 0 to 360. Is it possible to get that directly?

Thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2014-03-18 07:11:08 -0600

ahendrix gravatar image

You can't get angles in degrees directly from the available library calls, but it's pretty trivial to convert radians to degrees:

double yaw = ...; // however you want to get yaw.
double yaw_degrees = yaw * 180.0 / M_PI; // conversion to degrees
if( yaw_degrees < 0 ) yaw_degrees += 360.0; // convert negative to positive angles
edit flag offensive delete link more


nice very thanks

underwater gravatar image underwater  ( 2014-03-18 22:50:04 -0600 )edit

This answer was some time ago, but is this not incorrect?

PEP 103 specifies that yaw measured from the x-axis (i.e. in a geographic frame from East) and is positive CCW. Heading of course is measured from the y-axis, positive CW.

vschmidt gravatar image vschmidt  ( 2017-12-03 18:33:06 -0600 )edit

answered 2014-03-18 07:38:11 -0600

You can try the angles package which provides C++ api calls for angle normalization, conversions between radians and degrees, and finding minimum angular distance.

edit flag offensive delete link more


thanks for your answer, please can you tell me how to use the angles package? I am not succeed.

underwater gravatar image underwater  ( 2014-03-18 22:53:55 -0600 )edit

Without more info about how you are not succeeding, it's hard to help. You need to (1) include angles in your manifest.xml or package.xml (2) #include <angles angles.h=""> (3) Run code like "yaw = angles::to_degrees(angles::normalize_angle_positive(yaw));"

jarvisschultz gravatar image jarvisschultz  ( 2014-03-19 05:55:36 -0600 )edit

Sorry for the bad formatting of point (2).... not my fault. See [bug report](

jarvisschultz gravatar image jarvisschultz  ( 2014-03-19 05:57:18 -0600 )edit

very thanks

underwater gravatar image underwater  ( 2014-04-01 04:50:12 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-03-18 06:59:36 -0600

Seen: 17,943 times

Last updated: Mar 18 '14