**Applicable models: **M600 series, A3, N3, M210 series, M210 V2 series

**SDK version: **OSDK3.7 & OSDK3.8

Telemetry provides a quaternion topic (TOPIC_QUATERNION) but does not provide a way to obtain the attitude angle. However, the quaternion can be converted into an attitude angle by means of Euler's formula. The conversion procedure is as follows:

Vector3f FlightSample::quaternionToEulerAngle(

const Telemetry::Quaternion& quat) {

Telemetry::Vector3f eulerAngle;

double q2sqr = quat.q2 * quat.q2;

double t0 = -2.0 * (q2sqr + quat.q3 * quat.q3) + 1.0;

double t1 = 2.0 * (quat.q1 * quat.q2 + quat.q0 * quat.q3);

double t2 = -2.0 * (quat.q1 * quat.q3 - quat.q0 * quat.q2);

double t3 = 2.0 * (quat.q2 * quat.q3 + quat.q0 * quat.q1);

double t4 = -2.0 * (quat.q1 * quat.q1 + q2sqr) + 1.0;

t2 = (t2 > 1.0) ? 1.0 : t2;

t2 = (t2 < -1.0) ? -1.0 : t2;

eulerAngle.x = atan2(t3, t4); //roll

eulerAngle.y = asin(t2); //pitch

eulerAngle.z = atan2(t1, t0); //yaw

return eulerAngle;

}

## Comments

0 comments

Please sign in to leave a comment.