mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-24 07:52:44 +08:00
refactor(commander): one function per estimator status check (#28898)
* test(commander): pin the estimator checks before restructuring them Sixteen cases on EstimatorChecks driven through its topics, one per behaviour of the file that the next commit moves: the preflight innovation and magnetic interference checks, GNSS fusion starting and stopping, spoofing and jamming, a failing GNSS check under each COM_ARM_WO_GPS setting, the sensor bias check, the compass fault and heading reference checks, the imminent position failure warning, low position accuracy, and the attitude, angular velocity and altitude validity flags. They observe the health report of a cycle and the events it sends. All pass on the file as it is. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu> * refactor(commander): one function per estimator status check checkEstimatorStatus ran four hundred lines through eight levels of nesting, covering the preflight innovation checks, the magnetic interference check and everything about GNSS. Each of those is its own function now, named for what it checks, with an early return where a condition used to wrap the whole block, and the GNSS part is split further into the fusion change, the spoofing and jamming latches and the preflight quality check. In setModeRequirementFlags the one nested block, the warning of an imminent position failure, is extracted the same way, and the rest is left as flat sections. Three small simplifications on the way: the mavlink severity of a failed GNSS check follows the log level chosen for it instead of a second switch on the parameter, the spoofing and jamming latches are one comparison each, and the heading innovation flag that setModeRequirementFlags never read is no longer passed to it. The ITCM lists of the i.MX RT boards name setModeRequirementFlags by its new signature and take the functions split out of checkEstimatorStatus, so the same code stays in ITCM there. No event, message, condition or order of side effects changes. The extracted events are identical, and the twenty seven functional tests pass before and after. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu> --------- Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
This commit is contained in:
1 parent
68c0a6496c
commit
f19558335b
8 files changed
+982
-491
No files matched your search
@@ -458,7 +458,8 @@
|
||||
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN3ADC6sampleEj)
|
||||
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
|
||||
*(.text._ZN11ControlMath11addIfNotNanERff)
|
||||
*(.text._ZN9Commander21checkForMissionUpdateEv)
|
||||
*(.text._Z8set_tunei)
|
||||
@@ -601,6 +602,12 @@
|
||||
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
|
||||
*(.text._ZN13AnalogBattery19get_current_channelEv)
|
||||
*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
|
||||
*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
|
||||
*(.text._ZN12FailsafeBase11updateDelayERKy)
|
||||
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
|
||||
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
|
||||
|
||||
@@ -445,7 +445,8 @@
|
||||
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN3ADC6sampleEj)
|
||||
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
|
||||
*(.text._ZN11ControlMath11addIfNotNanERff)
|
||||
*(.text._ZN9Commander21checkForMissionUpdateEv)
|
||||
*(.text._Z8set_tunei)
|
||||
@@ -586,6 +587,12 @@
|
||||
*(.text._ZN12SafetyButton3RunEv)
|
||||
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
|
||||
*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
|
||||
*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
|
||||
*(.text._ZN12FailsafeBase11updateDelayERKy)
|
||||
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
|
||||
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
|
||||
|
||||
@@ -450,7 +450,8 @@
|
||||
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN3ADC6sampleEj)
|
||||
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
|
||||
*(.text._ZN11ControlMath11addIfNotNanERff)
|
||||
*(.text._ZN9Commander21checkForMissionUpdateEv)
|
||||
*(.text._Z8set_tunei)
|
||||
@@ -589,6 +590,12 @@
|
||||
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
|
||||
*(.text._ZN13AnalogBattery19get_current_channelEv)
|
||||
*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
|
||||
*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
|
||||
*(.text._ZN12FailsafeBase11updateDelayERKy)
|
||||
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
|
||||
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
|
||||
|
||||
@@ -450,7 +450,8 @@
|
||||
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN3ADC6sampleEj)
|
||||
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
|
||||
*(.text._ZN11ControlMath11addIfNotNanERff)
|
||||
*(.text._ZN9Commander21checkForMissionUpdateEv)
|
||||
*(.text._Z8set_tunei)
|
||||
@@ -588,6 +589,12 @@
|
||||
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
|
||||
*(.text._ZN13AnalogBattery19get_current_channelEv)
|
||||
*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
|
||||
*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
|
||||
*(.text._ZN12FailsafeBase11updateDelayERKy)
|
||||
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
|
||||
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
|
||||
|
||||
@@ -457,7 +457,8 @@
|
||||
*(.text._ZN24ManualVelocitySmoothingZC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN3ADC6sampleEj)
|
||||
*(.text._ZNK3Ekf22isTerrainEstimateValidEv)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks23setModeRequirementFlagsERK7ContextbbRK24vehicle_local_position_sRK14vehicle_gnss_sR16failsafe_flags_sR6Report)
|
||||
*(.text._ZN15EstimatorChecks29warnOfImminentPositionFailureER6ReportRKyRK25vehicle_global_position_sfRK16failsafe_flags_s)
|
||||
*(.text._ZN11ControlMath11addIfNotNanERff)
|
||||
*(.text._ZN9Commander21checkForMissionUpdateEv)
|
||||
*(.text._Z8set_tunei)
|
||||
@@ -600,6 +601,12 @@
|
||||
*(.text._ZN3GPS8callbackE15GPSCallbackTypePviS1_)
|
||||
*(.text._ZN13AnalogBattery19get_current_channelEv)
|
||||
*(.text._ZN15EstimatorChecks20checkEstimatorStatusERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks25checkInnovationsPreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks34checkMagneticInterferencePreflightERK7ContextR6ReportRK18estimator_status_s8NavModes)
|
||||
*(.text._ZN15EstimatorChecks15checkGnssFusionERK7ContextR6ReportRK18estimator_status_s)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssFusionChangeERK7ContextR6Reportb)
|
||||
*(.text._ZN15EstimatorChecks22reportGnssInterferenceER6Reportt)
|
||||
*(.text._ZN15EstimatorChecks30reportFailedGnssCheckPreflightER6ReportRK18estimator_status_sb)
|
||||
*(.text._ZN12FailsafeBase11updateDelayERKy)
|
||||
*(.text._ZN10FlightTask25_evaluateDistanceToGroundEv)
|
||||
*(.text._ZN4EKF218PublishGnssHgtBiasERKy)
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -71,8 +71,19 @@ private:
|
||||
WarningOnly = 2
|
||||
};
|
||||
|
||||
// The checks on the estimator status: the preflight innovation and magnetic interference checks, and
|
||||
// what the estimator makes of GNSS
|
||||
void checkEstimatorStatus(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
|
||||
NavModes required_groups);
|
||||
void checkInnovationsPreflight(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
|
||||
NavModes required_groups);
|
||||
void checkMagneticInterferencePreflight(const Context &context, Report &reporter,
|
||||
const estimator_status_s &estimator_status, NavModes required_groups);
|
||||
void checkGnssFusion(const Context &context, Report &reporter, const estimator_status_s &estimator_status);
|
||||
void reportGnssFusionChange(const Context &context, Report &reporter, bool gnss_fused);
|
||||
void reportGnssInterference(Report &reporter, uint16_t gps_check_fail_flags);
|
||||
void reportFailedGnssCheckPreflight(Report &reporter, const estimator_status_s &estimator_status, bool gnss_fused);
|
||||
|
||||
void checkSensorBias(const Context &context, Report &reporter, NavModes required_groups);
|
||||
void checkEstimatorStatusFlags(const Context &context, Report &reporter, const estimator_status_s &estimator_status,
|
||||
const vehicle_local_position_s &lpos);
|
||||
@@ -84,10 +95,12 @@ private:
|
||||
void reportGnssReasonForPositionLoss(const Context &context, Report &reporter, const hrt_abstime &now,
|
||||
const vehicle_gnss_s &vehicle_gnss) const;
|
||||
|
||||
void setModeRequirementFlags(const Context &context, bool pre_flt_fail_innov_heading,
|
||||
bool pre_flt_fail_innov_vel_horiz, bool pre_flt_fail_innov_pos_horiz,
|
||||
const vehicle_local_position_s &lpos, const vehicle_gnss_s &vehicle_gnss,
|
||||
failsafe_flags_s &failsafe_flags, Report &reporter);
|
||||
// The mode requirement flags, with the warning of an imminent position failure on its own
|
||||
void setModeRequirementFlags(const Context &context, bool pre_flt_fail_innov_vel_horiz,
|
||||
bool pre_flt_fail_innov_pos_horiz, const vehicle_local_position_s &lpos,
|
||||
const vehicle_gnss_s &vehicle_gnss, failsafe_flags_s &failsafe_flags, Report &reporter);
|
||||
void warnOfImminentPositionFailure(Report &reporter, const hrt_abstime &now, const vehicle_global_position_s &gpos,
|
||||
float lpos_eph_threshold, const failsafe_flags_s &failsafe_flags);
|
||||
|
||||
bool checkPosVelValidity(const hrt_abstime &now, const bool data_valid, const float data_accuracy,
|
||||
const float required_accuracy,
|
||||
|
||||
@@ -41,9 +41,15 @@
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/estimator_sensor_bias.h>
|
||||
#include <uORB/topics/estimator_status.h>
|
||||
#include <uORB/topics/estimator_status_flags.h>
|
||||
#include <uORB/topics/health_report.h>
|
||||
#include <uORB/topics/vehicle_gnss.h>
|
||||
#include <uORB/topics/event.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_global_position.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -63,17 +69,57 @@ public:
|
||||
{
|
||||
param_control_autosave(false);
|
||||
|
||||
int32_t one = 1;
|
||||
param_set(param_find("SYS_HAS_GPS"), &one);
|
||||
param_set(param_find("SENS_IMU_MODE"), &one);
|
||||
setParam("SYS_HAS_GPS", 1);
|
||||
setParam("SENS_IMU_MODE", 1);
|
||||
|
||||
// back to their defaults, the cases below change them
|
||||
param_reset(param_find("COM_ARM_MAG_STR"));
|
||||
param_reset(param_find("COM_ARM_WO_GPS"));
|
||||
param_reset(param_find("COM_POS_LOW_EPH"));
|
||||
param_reset(param_find("COM_POS_LOW_ACT"));
|
||||
|
||||
// the event topic has to exist before the first send, or the queued events are lost
|
||||
orb_advertise(ORB_ID(event), nullptr);
|
||||
|
||||
_failsafe_flags = {};
|
||||
// every mode requires attitude and a local and global position, so a failed check shows on every mode
|
||||
_failsafe_flags.mode_req_attitude = ~0u;
|
||||
_failsafe_flags.mode_req_local_position = ~0u;
|
||||
_failsafe_flags.mode_req_global_position = ~0u;
|
||||
|
||||
// the topics keep their last sample across cases, so each case starts from the same clean state
|
||||
publishEstimatorStatus(false, 0);
|
||||
estimator_status_flags_s flags{};
|
||||
flags.timestamp = hrt_absolute_time();
|
||||
flags.cs_yaw_align = true;
|
||||
publishStatusFlags(flags);
|
||||
estimator_sensor_bias_s bias{};
|
||||
bias.timestamp = hrt_absolute_time();
|
||||
publishSensorBias(bias);
|
||||
vehicle_global_position_s gpos{};
|
||||
gpos.timestamp = hrt_absolute_time();
|
||||
publishGlobalPosition(gpos);
|
||||
vehicle_attitude_s attitude{};
|
||||
attitude.timestamp = hrt_absolute_time();
|
||||
attitude.q[0] = 1.f;
|
||||
publishAttitude(attitude);
|
||||
vehicle_angular_velocity_s rates{};
|
||||
rates.timestamp = hrt_absolute_time();
|
||||
publishAngularVelocity(rates);
|
||||
|
||||
drainEvents();
|
||||
}
|
||||
|
||||
void setParam(const char *name, int32_t value) { param_set(param_find(name), &value); }
|
||||
void setParam(const char *name, float value) { param_set(param_find(name), &value); }
|
||||
|
||||
void publishEstimatorStatus(const estimator_status_s &status) { _estimator_status_pub.publish(status); }
|
||||
void publishStatusFlags(const estimator_status_flags_s &flags) { _status_flags_pub.publish(flags); }
|
||||
void publishSensorBias(const estimator_sensor_bias_s &bias) { _sensor_bias_pub.publish(bias); }
|
||||
void publishGlobalPosition(const vehicle_global_position_s &gpos) { _global_position_pub.publish(gpos); }
|
||||
void publishAttitude(const vehicle_attitude_s &attitude) { _attitude_pub.publish(attitude); }
|
||||
void publishAngularVelocity(const vehicle_angular_velocity_s &rates) { _angular_velocity_pub.publish(rates); }
|
||||
|
||||
// what the estimator reports: whether it fuses GNSS position, and which receiver checks fail.
|
||||
// An age stands in for a report seen that long ago.
|
||||
void publishEstimatorStatus(bool gnss_fused, uint16_t gps_check_fail_flags, hrt_abstime age = 0)
|
||||
@@ -98,7 +144,7 @@ public:
|
||||
_receiver_pub.publish(gnss);
|
||||
}
|
||||
|
||||
void publishLocalPosition(bool valid)
|
||||
void publishLocalPosition(bool valid, float eph = 0.5f, bool global_origin = false)
|
||||
{
|
||||
vehicle_local_position_s lpos{};
|
||||
lpos.timestamp = hrt_absolute_time();
|
||||
@@ -107,15 +153,17 @@ public:
|
||||
lpos.v_xy_valid = valid;
|
||||
lpos.z_valid = true;
|
||||
lpos.v_z_valid = true;
|
||||
lpos.eph = 0.5f;
|
||||
lpos.xy_global = global_origin;
|
||||
lpos.eph = eph;
|
||||
lpos.epv = 0.5f;
|
||||
lpos.evh = 0.2f;
|
||||
lpos.evv = 0.2f;
|
||||
_local_position_pub.publish(lpos);
|
||||
}
|
||||
|
||||
// one commander cycle. The failsafe flags persist across cycles as they do in commander.
|
||||
void runCheck(bool armed)
|
||||
// one commander cycle. The failsafe flags persist across cycles as they do in commander, and the
|
||||
// health report of the cycle is kept for the assertions.
|
||||
void runCheck(bool armed, bool calibrating = false)
|
||||
{
|
||||
vehicle_status_s status{};
|
||||
|
||||
@@ -123,10 +171,28 @@ public:
|
||||
status.arming_state = vehicle_status_s::ARMING_STATE_ARMED;
|
||||
}
|
||||
|
||||
status.calibration_enabled = calibrating;
|
||||
|
||||
_check.updateParams();
|
||||
Context context{status};
|
||||
Report reporter{_failsafe_flags, 0};
|
||||
_check.checkAndReport(context, reporter);
|
||||
reporter.getHealthReport(_report);
|
||||
}
|
||||
|
||||
bool armingError(health_component_t component) const
|
||||
{
|
||||
return _report.arming_check_error_flags & (uint64_t)component;
|
||||
}
|
||||
|
||||
bool armingWarning(health_component_t component) const
|
||||
{
|
||||
return _report.arming_check_warning_flags & (uint64_t)component;
|
||||
}
|
||||
|
||||
bool isPresent(health_component_t component) const
|
||||
{
|
||||
return _report.health_is_present_flags & (uint64_t)component;
|
||||
}
|
||||
|
||||
// everything published since the last drain is kept, so one test can count several ids
|
||||
@@ -178,14 +244,27 @@ public:
|
||||
|
||||
static constexpr uint32_t kReasonEvent = events::ID("check_estimator_position_lost_gnss_reason");
|
||||
static constexpr uint32_t kNoDataEvent = events::ID("check_estimator_position_lost_gnss_no_data");
|
||||
static constexpr uint32_t kFusionStartedEvent = events::ID("check_estimator_gnss_fusion_started");
|
||||
static constexpr uint32_t kFusionStoppedEvent = events::ID("check_estimator_gnss_fusion_stopped");
|
||||
static constexpr uint32_t kSpoofingEvent = events::ID("check_estimator_gnss_warning_spoofing");
|
||||
static constexpr uint32_t kJammingEvent = events::ID("check_estimator_gnss_warning_jamming");
|
||||
static constexpr uint32_t kFailureImminentEvent = events::ID("check_estimator_position_failure_imminent");
|
||||
static constexpr uint16_t kSpeedAccuracy = 1 << estimator_status_s::GPS_CHECK_FAIL_MAX_SPD_ERR;
|
||||
static constexpr uint16_t kSpoofed = 1 << estimator_status_s::GPS_CHECK_FAIL_SPOOFED;
|
||||
static constexpr uint16_t kJammed = 1 << estimator_status_s::GPS_CHECK_FAIL_JAMMED;
|
||||
static constexpr uint16_t kFixTooLow = 1 << estimator_status_s::GPS_CHECK_FAIL_GPS_FIX;
|
||||
|
||||
uORB::PublicationMulti<estimator_status_s> _estimator_status_pub{ORB_ID(estimator_status)};
|
||||
uORB::PublicationMulti<estimator_status_flags_s> _status_flags_pub{ORB_ID(estimator_status_flags)};
|
||||
uORB::PublicationMulti<estimator_sensor_bias_s> _sensor_bias_pub{ORB_ID(estimator_sensor_bias)};
|
||||
uORB::Publication<vehicle_local_position_s> _local_position_pub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Publication<vehicle_global_position_s> _global_position_pub{ORB_ID(vehicle_global_position)};
|
||||
uORB::Publication<vehicle_attitude_s> _attitude_pub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Publication<vehicle_angular_velocity_s> _angular_velocity_pub{ORB_ID(vehicle_angular_velocity)};
|
||||
uORB::Publication<vehicle_gnss_s> _receiver_pub{ORB_ID(vehicle_gnss)};
|
||||
uORB::Subscription _event_sub{ORB_ID(event)};
|
||||
|
||||
health_report_s _report{};
|
||||
failsafe_flags_s _failsafe_flags{};
|
||||
std::vector<event_s> _events;
|
||||
EstimatorChecks _check;
|
||||
@@ -400,3 +479,353 @@ TEST_F(EstimatorChecksTest, NothingWhileDisarmed)
|
||||
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
|
||||
EXPECT_EQ(countEvents(kReasonEvent), 0);
|
||||
}
|
||||
|
||||
// The rest of the checks in the file, pinned as they behave so a reorganisation of the file
|
||||
// can be held against them
|
||||
|
||||
TEST_F(EstimatorChecksTest, PreflightInnovationFailureIsReportedOnTheGround)
|
||||
{
|
||||
estimator_status_s status{};
|
||||
status.timestamp = hrt_absolute_time();
|
||||
status.pre_flt_fail_innov_heading = true;
|
||||
publishEstimatorStatus(status);
|
||||
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "the innovations are not judged in flight";
|
||||
|
||||
runCheck(false, true);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "nor during calibration";
|
||||
|
||||
// the last innovation in the chain is reported like the first
|
||||
status.pre_flt_fail_innov_heading = false;
|
||||
status.pre_flt_fail_innov_height = true;
|
||||
publishEstimatorStatus(status);
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
|
||||
status.pre_flt_fail_innov_height = false;
|
||||
publishEstimatorStatus(status);
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate));
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, MagneticInterferenceIsReportedAsConfigured)
|
||||
{
|
||||
estimator_status_s status{};
|
||||
status.timestamp = hrt_absolute_time();
|
||||
status.pre_flt_fail_mag_field_disturbed = true;
|
||||
publishEstimatorStatus(status);
|
||||
|
||||
setParam("COM_ARM_MAG_STR", 1); // deny arming
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingWarning(health_component_t::local_position_estimate));
|
||||
EXPECT_EQ(_report.can_arm_mode_flags, 0u) << "every mode needs the attitude, so none can arm";
|
||||
|
||||
setParam("COM_ARM_MAG_STR", 2); // warn only
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingWarning(health_component_t::local_position_estimate));
|
||||
EXPECT_NE(_report.can_arm_mode_flags, 0u) << "the warning alone does not block arming";
|
||||
|
||||
setParam("COM_ARM_MAG_STR", 0);
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(armingWarning(health_component_t::local_position_estimate));
|
||||
|
||||
setParam("COM_ARM_MAG_STR", 1);
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(armingWarning(health_component_t::local_position_estimate)) << "only judged on the ground";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, GnssFusionStartAndStopAreReportedInFlight)
|
||||
{
|
||||
publishLocalPosition(true);
|
||||
runCheck(true);
|
||||
drainEvents();
|
||||
|
||||
publishEstimatorStatus(true, 0);
|
||||
runCheck(true);
|
||||
EXPECT_EQ(countEvents(kFusionStartedEvent), 1);
|
||||
|
||||
runCheck(true);
|
||||
EXPECT_EQ(countEvents(kFusionStartedEvent), 1) << "reported on the change, not every cycle";
|
||||
|
||||
event_s event{};
|
||||
publishEstimatorStatus(false, 0);
|
||||
runCheck(true);
|
||||
ASSERT_EQ(countEvents(kFusionStoppedEvent, &event), 1);
|
||||
EXPECT_EQ(event.log_levels & 0x0f, (uint8_t)events::Log::Error) << "an error while the position estimate is still valid";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, GnssFusionStopIsOnlyInformationOncePositionIsLost)
|
||||
{
|
||||
flyOnGnss();
|
||||
|
||||
publishLocalPosition(false);
|
||||
runCheck(true);
|
||||
ASSERT_TRUE(_failsafe_flags.local_position_invalid);
|
||||
drainEvents();
|
||||
|
||||
event_s event{};
|
||||
publishEstimatorStatus(false, 0);
|
||||
runCheck(true);
|
||||
ASSERT_EQ(countEvents(kFusionStoppedEvent, &event), 1);
|
||||
EXPECT_EQ(event.log_levels & 0x0f, (uint8_t)events::Log::Info);
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, GnssFusionChangesAreNotReportedOnTheGround)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
runCheck(false);
|
||||
publishEstimatorStatus(false, 0);
|
||||
runCheck(false);
|
||||
EXPECT_EQ(countEvents(kFusionStartedEvent), 0);
|
||||
EXPECT_EQ(countEvents(kFusionStoppedEvent), 0);
|
||||
|
||||
// the state is still followed, so arming does not report a change that happened on the ground
|
||||
publishEstimatorStatus(true, 0);
|
||||
runCheck(false);
|
||||
runCheck(true);
|
||||
EXPECT_EQ(countEvents(kFusionStartedEvent), 0);
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, SpoofingAndJammingAreReportedOnceUntilTheyClear)
|
||||
{
|
||||
publishEstimatorStatus(true, kSpoofed);
|
||||
runCheck(false);
|
||||
runCheck(false);
|
||||
EXPECT_EQ(countEvents(kSpoofingEvent), 1);
|
||||
|
||||
publishEstimatorStatus(true, 0);
|
||||
runCheck(false);
|
||||
publishEstimatorStatus(true, kSpoofed);
|
||||
runCheck(false);
|
||||
EXPECT_EQ(countEvents(kSpoofingEvent), 2) << "reported again once it cleared in between";
|
||||
|
||||
publishEstimatorStatus(true, kJammed);
|
||||
runCheck(false);
|
||||
runCheck(false);
|
||||
EXPECT_EQ(countEvents(kJammingEvent), 1);
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, AFailingGnssCheckBlocksArmingAsConfigured)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
runCheck(false);
|
||||
const uint64_t can_arm_with_good_gnss = _report.can_arm_mode_flags;
|
||||
|
||||
publishEstimatorStatus(true, kFixTooLow);
|
||||
|
||||
setParam("COM_ARM_WO_GPS", 0); // deny arming
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingError(health_component_t::gps));
|
||||
EXPECT_EQ(_report.can_arm_mode_flags, 0u);
|
||||
|
||||
setParam("COM_ARM_WO_GPS", 1); // warn only
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(armingError(health_component_t::gps));
|
||||
EXPECT_TRUE(armingWarning(health_component_t::gps));
|
||||
EXPECT_EQ(_report.can_arm_mode_flags, can_arm_with_good_gnss);
|
||||
|
||||
setParam("COM_ARM_WO_GPS", 2); // disabled
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(armingError(health_component_t::gps));
|
||||
EXPECT_FALSE(armingWarning(health_component_t::gps));
|
||||
|
||||
setParam("COM_ARM_WO_GPS", 0);
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(armingError(health_component_t::gps)) << "the quality checks are only judged on the ground";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, GnssIsPresentWhileTheEstimatorFusesIt)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(isPresent(health_component_t::gps));
|
||||
|
||||
publishEstimatorStatus(false, 0);
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(isPresent(health_component_t::gps));
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, HighSensorBiasBlocksArming)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
|
||||
estimator_sensor_bias_s bias{};
|
||||
bias.timestamp = hrt_absolute_time();
|
||||
bias.accel_bias_valid = true;
|
||||
bias.accel_bias_limit = 0.4f;
|
||||
bias.accel_bias[1] = 0.35f; // above three quarters of the limit
|
||||
publishSensorBias(bias);
|
||||
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
|
||||
runCheck(false, true);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "not judged during calibration";
|
||||
|
||||
bias.timestamp = hrt_absolute_time() - 31_s;
|
||||
publishSensorBias(bias);
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "a stale estimate is not judged";
|
||||
|
||||
bias = {};
|
||||
bias.timestamp = hrt_absolute_time();
|
||||
bias.gyro_bias_valid = true;
|
||||
bias.gyro_bias_limit = 0.1f;
|
||||
bias.gyro_bias[2] = 0.09f;
|
||||
publishSensorBias(bias);
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, CompassFaultBlocksEveryMode)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
|
||||
estimator_status_flags_s flags{};
|
||||
flags.timestamp = hrt_absolute_time();
|
||||
flags.cs_yaw_align = true;
|
||||
flags.cs_mag_fault = true;
|
||||
publishStatusFlags(flags);
|
||||
|
||||
runCheck(true);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
EXPECT_EQ(_report.can_arm_mode_flags, 0u);
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, NoHeadingReferenceBlocksArmingOnlyWithAGlobalOrigin)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
|
||||
estimator_status_flags_s flags{};
|
||||
flags.timestamp = hrt_absolute_time();
|
||||
flags.cs_yaw_align = false;
|
||||
publishStatusFlags(flags);
|
||||
|
||||
publishLocalPosition(true, 0.5f, true);
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "only judged on the ground";
|
||||
|
||||
publishLocalPosition(true, 0.5f, false);
|
||||
runCheck(false);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "no heading reference is needed without a global origin";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, PositionFailureImminentIsWarnedOnceWhileDeadReckoning)
|
||||
{
|
||||
publishEstimatorStatus(true, 0);
|
||||
publishLocalPosition(true);
|
||||
|
||||
// a global position that is still valid but whose error is close to COM_POS_FS_EPH
|
||||
vehicle_global_position_s gpos{};
|
||||
gpos.timestamp = hrt_absolute_time();
|
||||
gpos.lat_lon_valid = true;
|
||||
gpos.alt_valid = true;
|
||||
gpos.eph = 12.f;
|
||||
publishGlobalPosition(gpos);
|
||||
|
||||
estimator_status_flags_s flags{};
|
||||
flags.timestamp = hrt_absolute_time();
|
||||
flags.cs_yaw_align = true;
|
||||
flags.cs_inertial_dead_reckoning = true;
|
||||
publishStatusFlags(flags);
|
||||
|
||||
runCheck(true);
|
||||
ASSERT_FALSE(_failsafe_flags.global_position_invalid);
|
||||
EXPECT_EQ(countEvents(kFailureImminentEvent), 1);
|
||||
|
||||
runCheck(true);
|
||||
EXPECT_EQ(countEvents(kFailureImminentEvent), 1) << "warned once";
|
||||
|
||||
flags.cs_inertial_dead_reckoning = false;
|
||||
publishStatusFlags(flags);
|
||||
runCheck(true);
|
||||
flags.cs_inertial_dead_reckoning = true;
|
||||
publishStatusFlags(flags);
|
||||
runCheck(true);
|
||||
EXPECT_EQ(countEvents(kFailureImminentEvent), 2) << "warned again after dead reckoning ended in between";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, LowPositionAccuracyIsFlaggedAndReportedInFlight)
|
||||
{
|
||||
setParam("COM_POS_LOW_EPH", 1.f);
|
||||
setParam("COM_POS_LOW_ACT", 1);
|
||||
publishEstimatorStatus(true, 0);
|
||||
|
||||
publishLocalPosition(true, 2.f);
|
||||
runCheck(true);
|
||||
ASSERT_FALSE(_failsafe_flags.local_position_invalid);
|
||||
EXPECT_TRUE(_failsafe_flags.position_accuracy_low);
|
||||
EXPECT_TRUE(armingError(health_component_t::local_position_estimate));
|
||||
|
||||
runCheck(false);
|
||||
EXPECT_TRUE(_failsafe_flags.position_accuracy_low);
|
||||
EXPECT_FALSE(armingError(health_component_t::local_position_estimate)) << "flagged but not reported on the ground";
|
||||
|
||||
publishLocalPosition(true, 0.5f);
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(_failsafe_flags.position_accuracy_low);
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, AttitudeValidityFollowsTheQuaternion)
|
||||
{
|
||||
vehicle_attitude_s attitude{};
|
||||
attitude.timestamp = hrt_absolute_time();
|
||||
attitude.q[0] = 1.f;
|
||||
publishAttitude(attitude);
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(_failsafe_flags.attitude_invalid);
|
||||
|
||||
attitude.q[0] = 1.1f;
|
||||
publishAttitude(attitude);
|
||||
runCheck(true);
|
||||
EXPECT_TRUE(_failsafe_flags.attitude_invalid) << "not a unit quaternion";
|
||||
|
||||
attitude.q[0] = 1.f;
|
||||
attitude.timestamp = hrt_absolute_time() - 2_s;
|
||||
publishAttitude(attitude);
|
||||
runCheck(true);
|
||||
EXPECT_TRUE(_failsafe_flags.attitude_invalid) << "stale";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, AngularVelocityValidityFollowsTheSamples)
|
||||
{
|
||||
vehicle_angular_velocity_s rates{};
|
||||
rates.timestamp = hrt_absolute_time();
|
||||
publishAngularVelocity(rates);
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(_failsafe_flags.angular_velocity_invalid);
|
||||
|
||||
rates.xyz[0] = NAN;
|
||||
publishAngularVelocity(rates);
|
||||
runCheck(true);
|
||||
EXPECT_TRUE(_failsafe_flags.angular_velocity_invalid) << "not finite";
|
||||
|
||||
rates.xyz[0] = 0.f;
|
||||
rates.timestamp = hrt_absolute_time() - 2_s;
|
||||
publishAngularVelocity(rates);
|
||||
runCheck(true);
|
||||
EXPECT_TRUE(_failsafe_flags.angular_velocity_invalid) << "stale";
|
||||
}
|
||||
|
||||
TEST_F(EstimatorChecksTest, LocalAltitudeIsInvalidWithoutAValidHeight)
|
||||
{
|
||||
publishLocalPosition(true);
|
||||
runCheck(true);
|
||||
EXPECT_FALSE(_failsafe_flags.local_altitude_invalid);
|
||||
|
||||
vehicle_local_position_s lpos{};
|
||||
lpos.timestamp = hrt_absolute_time();
|
||||
lpos.xy_valid = true;
|
||||
lpos.v_xy_valid = true;
|
||||
lpos.z_valid = false;
|
||||
_local_position_pub.publish(lpos);
|
||||
runCheck(true);
|
||||
EXPECT_TRUE(_failsafe_flags.local_altitude_invalid);
|
||||
}
|
||||
Reference in new issue
Block a user