commander: move ownership of vehicle_status_flags_s to HealthAndArmingChecks

This commit is contained in:
Beat Küng
2022-09-06 09:24:00 +02:00
committed by Daniel Agar
parent cf2eb69d25
commit 6fda555cba
8 changed files with 42 additions and 28 deletions
@@ -33,11 +33,10 @@
#include "HealthAndArmingChecks.hpp"
HealthAndArmingChecks::HealthAndArmingChecks(ModuleParams *parent, vehicle_status_flags_s &status_flags,
vehicle_status_s &status)
HealthAndArmingChecks::HealthAndArmingChecks(ModuleParams *parent, vehicle_status_s &status)
: ModuleParams(parent),
_context(status),
_reporter(status_flags)
_reporter(_failsafe_flags)
{
// Initialize mode requirements to invalid
_failsafe_flags.angular_velocity_invalid = true;
@@ -67,9 +66,10 @@ bool HealthAndArmingChecks::update(bool force_reporting)
_checks[i]->checkAndReport(_context, _reporter);
}
_reporter.finalize();
const bool results_changed = _reporter.finalize();
const bool reported = _reporter.report(_context.isArmed(), force_reporting);
if (_reporter.report(_context.isArmed(), force_reporting)) {
if (reported) {
// LEGACY start
// Run the checks again, this time with the mavlink publication set.
@@ -97,10 +97,17 @@ bool HealthAndArmingChecks::update(bool force_reporting)
_reporter.getHealthReport(health_report);
health_report.timestamp = hrt_absolute_time();
_health_report_pub.publish(health_report);
return true;
}
return false;
// Check if we need to publish the failsafe flags
const hrt_abstime now = hrt_absolute_time();
if (now - _failsafe_flags.timestamp > 500_ms || results_changed) {
_failsafe_flags.timestamp = now;
_failsafe_flags_pub.publish(_failsafe_flags);
}
return reported;
}
void HealthAndArmingChecks::updateParams()