Skip to content

Instantly share code, notes, and snippets.

@alifahrri
Last active October 26, 2018 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alifahrri/84d283f69598e2d89c7ed850ef4b76d7 to your computer and use it in GitHub Desktop.
Save alifahrri/84d283f69598e2d89c7ed850ef4b76d7 to your computer and use it in GitHub Desktop.
rpy <-> quaternion
#include <tf2/LinearMath/Quaternion.h>
#include <tf/transform_datatypes.h>
...
tf2::Quaternion myQuaternion;
myQuaternion.setRPY( 0, 0, 0 );  // Create this quaternion from roll/pitch/yaw (in radians)
ROS_INFO_STREAM(q);  // Print the quaternion components (0,0,0,1)
...
quaternionMsgToTF(quat_msg , quat_tf);
import tf
from geometry_msgs.msg import Quaternion
...
quat_msg = Quaternion(quat_tf[0], quat_tf[1], quat_tf[2], quat_tf[3])
quaternion = (
    pose.orientation.x,
    pose.orientation.y,
    pose.orientation.z,
    pose.orientation.w)
euler = tf.transformations.euler_from_quaternion(quaternion)
roll = euler[0]
pitch = euler[1]
yaw = euler[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment