#include "tf2_msgs/msg/tf_message.hpp"
#include <tf2/LinearMath/Quaternion.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
//欧拉角转四元数
tf2::Quaternion orientation;
float yaw=1;
orientation.setRPY(0.0, 0.0, yaw);
//四元数转欧拉角
tf2::Quaternion imu_quat(
imu_data.orientation.x,
imu_data.orientation.y,
imu_data.orientation.z,
imu_data.orientation.w);
double roll, pitch, yaw;//定义存储r\p\y的容器
tf2::Matrix3x3 m(imu_quat);
m.getRPY(roll, pitch, yaw);//进行转换
ROS中的TF功能包中的欧拉角属于泰特 - 布赖恩角,是航模中常用的航向角。
按照自身坐标系旋转顺序是 Z–>Y–>X,叫做eulerYPR(Yaw Pitch Roll);
按照外界坐标系(参考坐标系)的旋转顺序是x–>y–>z,叫做RPY(Roll Pitch Yaw);
描述同一姿态时,以上两者的表示是等价的,即Yaw Pitch Roll的角度值是一样的,这在之后会进行证明。