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

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

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?

edit retag close merge delete

Sort by » oldest newest most voted

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

more

nice very thanks

( 2014-03-18 22:50:04 -0500 )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.

( 2017-12-03 18:33:06 -0500 )edit

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

more

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

( 2014-03-18 22:53:55 -0500 )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));"

( 2014-03-19 05:55:36 -0500 )edit

Sorry for the bad formatting of point (2).... not my fault. See [bug report](https://github.com/ros-infrastructure/answers.ros.org/issues/65)

( 2014-03-19 05:57:18 -0500 )edit

very thanks

( 2014-04-01 04:50:12 -0500 )edit