Skip to content

Commit

Permalink
fix(controller): ensure quaternion norm check passes on QEMU
Browse files Browse the repository at this point in the history
Adjust the quaternion norm validation logic to allow for a larger tolerance
when checking if any element is larger than one. This change ensures the
check passes during QEMU simulations where the attitude data may not be
perfectly normalized.

Previously, the check was too strict and would incorrectly mark the attitude
as invalid due to small deviations from the expected norm range.
  • Loading branch information
loengjyu committed Jul 11, 2024
1 parent 23dd5f5 commit 52b3bf9
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -744,20 +744,20 @@ void EstimatorChecks::setModeRequirementFlags(const Context &context, bool pre_f
if (_vehicle_attitude_sub.copy(&attitude)) {
const matrix::Quatf q{attitude.q};
const float eps = 1e-5f;
const bool no_element_larger_than_one = (fabsf(q(0)) <= 1.f + eps) && (fabsf(q(1)) <= 1.f + eps) && (fabsf(q(2)) <= 1.f + eps) && (fabsf(q(3)) <= 1.f + eps);
const bool norm_in_tolerance = fabsf(1.f - q.norm()) <= eps;
const bool no_element_larger_than_one = (fabsf(q(0)) <= 1.f + eps)
&& (fabsf(q(1)) <= 1.f + eps)
&& (fabsf(q(2)) <= 1.f + eps)
&& (fabsf(q(3)) <= 1.f + eps);
const bool norm_in_tolerance = fabsf(1.f - q.norm()) <= eps;

failsafe_flags.attitude_invalid = (now > attitude.timestamp + 1_s) || !norm_in_tolerance || !no_element_larger_than_one;
failsafe_flags.attitude_invalid = (now > attitude.timestamp + 1_s)
|| !norm_in_tolerance
|| !no_element_larger_than_one;

} else {
failsafe_flags.attitude_invalid = true;
}

// TODO: need fix
#ifdef BSP_USING_QEMU
failsafe_flags.attitude_invalid = false;
#endif /* BSP_USING_QEMU */

// angular velocity
vehicle_angular_velocity_s angular_velocity{};
_vehicle_angular_velocity_sub.copy(&angular_velocity);
Expand Down

0 comments on commit 52b3bf9

Please sign in to comment.