ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The quaternion for a given Z axis (yaw) rotation is given by:
w = cos(theta / 2)
x = 0
y = 0
z = sin(theta / 2)
where theta is the yaw angle in radians. If X (roll) or Y (pitch) axis rotations are involved too, the formula is a little more tedious, and can be found on Wikipedia.
The tf
library has very helpful functions for constructing quaternions from Euler angles. For yaw quaternions, there is tf::createQuaternionFromYaw(double yaw)
which takes a single argument which is the yaw angle in radians and returns a tf::Quaternion object that is equivalent. There is also tf::createQuaternionMsgFromYaw(double yaw)
(notice the 'Msg') which is similar, but returns a geometry_msgs::Quaternion ROS message.
For all three axes, there is tf::createQuaternionFromRPY(double roll, double pitch, double yaw)
and tf::createQuaternionMsgFromRollPitchYaw(double roll, double pitch, double yaw)
.
Of course, this is all available in C++ by including <tf/tf.h>
. In Python, it looks like you can convert Euler angles into a quaternion using transformations.py
(doc_link). I haven't used it myself before though.