pub fn euler_angles(attitude: &UnitQuaternion<f32>) -> (f32, f32, f32)Expand description
ZYX Euler angles (roll, pitch, yaw) in radians of an attitude quaternion, in the
frame contract’s convention (the same as
UnitQuaternion::euler_angles). Use this rather than nalgebra’s method to read Euler angles
from VehicleState::attitude.
It is a closed form on the quaternion. nalgebra’s goes through a rotation matrix and cos
(more flash on target), and its gimbal-lock branch reports a finite pitch of -π/2 and yaw 0
for a NaN attitude. Here NaN in gives NaN out, which the controllers treat as neutral. Near
±90° pitch the asin argument is clamped, so float rounding can’t turn a valid attitude
into NaN.
§Examples
use stable_flight::euler_angles;
use stable_flight::nalgebra::UnitQuaternion;
let attitude = UnitQuaternion::from_euler_angles(0.1, -0.2, 1.5);
let (roll, pitch, yaw) = euler_angles(&attitude);
assert!((roll - 0.1).abs() < 1e-6 && (pitch + 0.2).abs() < 1e-6 && (yaw - 1.5).abs() < 1e-6);