32 data_roll.setMaximumRangeX(data_x.maximumRangeX());
33 data_pitch.setMaximumRangeX(data_x.maximumRangeX());
34 data_yaw.setMaximumRangeX(data_x.maximumRangeX());
40 if (data_x.size() == 0 || data_x.size() != data_y.size() ||
41 data_y.size() != data_z.size() || data_z.size() != data_w.size())
47 size_t index = pos < 0 ? 0 : static_cast<size_t>(pos);
49 while (index < data_x.size())
51 auto& point_x = data_x.at(index);
52 double timestamp = point_x.x;
53 double q_x = point_x.y;
54 double q_y = data_y.at(index).y;
55 double q_z = data_z.at(index).y;
56 double q_w = data_w.at(index).y;
60 std::array<double, 3> RPY;
74 const std::array<double, 4>& quat,
75 std::array<double, 3>& rpy)
82 double quat_norm2 = (q_w * q_w) + (q_x * q_x) + (q_y * q_y) + (q_z * q_z);
83 if (std::abs(quat_norm2 - 1.0) > std::numeric_limits<double>::epsilon())
85 double mult = 1.0 / std::sqrt(quat_norm2);
91 double roll, pitch, yaw;
93 double sinr_cosp = 2 * (q_w * q_x + q_y * q_z);
94 double cosr_cosp = 1 - 2 * (q_x * q_x + q_y * q_y);
95 roll = std::atan2(sinr_cosp, cosr_cosp);
98 double sinp = 2 * (q_w * q_y - q_z * q_x);
99 if (std::abs(sinp) >= 1)
101 pitch = std::copysign(
M_PI_2, sinp);
105 pitch = std::asin(sinp);
108 double siny_cosp = 2 * (q_w * q_z + q_x * q_y);
109 double cosy_cosp = 1 - 2 * (q_y * q_y + q_z * q_z);
110 yaw = std::atan2(siny_cosp, cosy_cosp);
112 const double WRAP_ANGLE =
M_PI * 2.0;
113 const double WRAP_THRESHOLD =
M_PI * 1.95;
116 if (index != 0 &&
_wrap)
122 else if ((
_prev_roll - roll) > WRAP_THRESHOLD)
140 else if ((
_prev_yaw - yaw) > WRAP_THRESHOLD)
150 rpy = { roll, pitch, yaw };