【ROS学习】ROS中四元数与欧拉角的转换

1. 四元数转欧拉角

python 代码

# IMU callback function.
def imu_callback(self, msg):
    # Convert quaternions to Euler angles.
    (r, p, y) = tf.transformations.euler_from_quaternion([msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w])
    self.fill_euler_msg(msg, r, p, y)

c++ 代码

void odomCallback(const nav_msgs::Odometry &odom) {

  tf::Quaternion quat;
  tf::quaternionMsgToTF(odom.pose.pose.orientation, quat);

 
  double roll, pitch, yaw;//定义存储r\p\y的容器
  tf::Matrix3x3(quat).getRPY(roll, pitch, yaw);//进行转换

}

2. 欧拉角转四元数

//RPY欧拉角转四元数
tf::createQuaternionMsgFromRollPitchYaw(double r, double p, double y);//返回四元数


//只通过yaw, 即绕z的旋转角度计算四元数,用于平面小车。返回四元数
tf::createQuaternionMsgFromYaw(double y);

参考链接:
[1] 一銤阳光. ROS中四元素欧拉角变换 [EB/OL]. https://blog.csdn.net/CSDNhuaong/article/details/78510436, 2017-11-12/2022-03-24.
[2] 码农教程. ROS中quaternion四元数和RPY欧拉角转换 [EB/OL]. http://www.manongjc.com/article/62731.html, 2019-02-27/2022-03-24.

你可能感兴趣的:(ROS学习之路,ROS,四元数,欧拉角)