Land detector: Measure total system flight time

This implementation is a baseline implementation and makes no attempt to be tamper-proof. A monotonic counter like the W25R64FV or a similar HW facility would be required to achieve this.
This commit is contained in:
Lorenz Meier
2017-01-29 15:48:34 +01:00
parent 2cf8cdc63f
commit 75132a50e6
3 changed files with 29 additions and 2 deletions
+14 -2
View File
@@ -103,6 +103,7 @@ void LandDetector::_cycle()
_landDetected.freefall = false;
_landDetected.landed = false;
_landDetected.ground_contact = false;
_p_total_flight_time = param_find("LND_FLIGHT_TIME");
// Initialize uORB topics.
_initialize_topics();
@@ -117,6 +118,8 @@ void LandDetector::_cycle()
_update_topics();
hrt_abstime now = hrt_absolute_time();
_update_state();
bool freefallDetected = (_state == LandDetectionState::FREEFALL);
@@ -135,6 +138,16 @@ void LandDetector::_cycle()
_landDetected.landed = (_state == LandDetectionState::LANDED);
_landDetected.ground_contact = (_state == LandDetectionState::GROUND_CONTACT);
// We did take off
if (landDetected && !_landDetected.landed) {
_takeoff_time = now;
} else if (_takeoff_time != 0 && !landDetected && _landDetected.landed) {
_total_flight_time = now - _takeoff_time;
_takeoff_time = 0;
param_set(_p_total_flight_time, &_total_flight_time);
}
int instance;
orb_publish_auto(ORB_ID(vehicle_land_detected), &_landDetectedPub, &_landDetected,
&instance, ORB_PRIO_DEFAULT);
@@ -164,6 +177,7 @@ void LandDetector::_check_params(const bool force)
if (updated || force) {
_update_params();
param_get(_p_total_flight_time, &_total_flight_time);
}
}
@@ -191,8 +205,6 @@ void LandDetector::_update_state()
} else {
_state = LandDetectionState::FLYING;
}
return;
}
bool LandDetector::_orb_update(const struct orb_metadata *meta, int handle, void *buffer)