|
|
@ -57,6 +57,7 @@ LandDetector::LandDetector() : |
|
|
|
_state{}, |
|
|
|
_state{}, |
|
|
|
_freefall_hysteresis(false), |
|
|
|
_freefall_hysteresis(false), |
|
|
|
_landed_hysteresis(true), |
|
|
|
_landed_hysteresis(true), |
|
|
|
|
|
|
|
_maybe_landed_hysteresis(true), |
|
|
|
_ground_contact_hysteresis(true), |
|
|
|
_ground_contact_hysteresis(true), |
|
|
|
_total_flight_time{0}, |
|
|
|
_total_flight_time{0}, |
|
|
|
_takeoff_time{0}, |
|
|
|
_takeoff_time{0}, |
|
|
@ -64,6 +65,7 @@ LandDetector::LandDetector() : |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Use Trigger time when transitioning from in-air (false) to landed (true) / ground contact (true).
|
|
|
|
// Use Trigger time when transitioning from in-air (false) to landed (true) / ground contact (true).
|
|
|
|
_landed_hysteresis.set_hysteresis_time_from(false, LAND_DETECTOR_TRIGGER_TIME_US); |
|
|
|
_landed_hysteresis.set_hysteresis_time_from(false, LAND_DETECTOR_TRIGGER_TIME_US); |
|
|
|
|
|
|
|
_maybe_landed_hysteresis.set_hysteresis_time_from(false, MAYBE_LAND_DETECTOR_TRIGGER_TIME_US); |
|
|
|
_ground_contact_hysteresis.set_hysteresis_time_from(false, GROUND_CONTACT_TRIGGER_TIME_US); |
|
|
|
_ground_contact_hysteresis.set_hysteresis_time_from(false, GROUND_CONTACT_TRIGGER_TIME_US); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -93,6 +95,7 @@ void LandDetector::_cycle() |
|
|
|
_landDetected.freefall = false; |
|
|
|
_landDetected.freefall = false; |
|
|
|
_landDetected.landed = false; |
|
|
|
_landDetected.landed = false; |
|
|
|
_landDetected.ground_contact = false; |
|
|
|
_landDetected.ground_contact = false; |
|
|
|
|
|
|
|
_landDetected.maybe_landed = false; |
|
|
|
_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI"); |
|
|
|
_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI"); |
|
|
|
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO"); |
|
|
|
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO"); |
|
|
|
|
|
|
|
|
|
|
@ -117,6 +120,7 @@ void LandDetector::_cycle() |
|
|
|
|
|
|
|
|
|
|
|
bool freefallDetected = (_state == LandDetectionState::FREEFALL); |
|
|
|
bool freefallDetected = (_state == LandDetectionState::FREEFALL); |
|
|
|
bool landDetected = (_state == LandDetectionState::LANDED); |
|
|
|
bool landDetected = (_state == LandDetectionState::LANDED); |
|
|
|
|
|
|
|
bool maybe_landedDetected = (_state == LandDetectionState::MAYBE_LANDED); |
|
|
|
bool ground_contactDetected = (_state == LandDetectionState::GROUND_CONTACT); |
|
|
|
bool ground_contactDetected = (_state == LandDetectionState::GROUND_CONTACT); |
|
|
|
|
|
|
|
|
|
|
|
// Only publish very first time or when the result has changed.
|
|
|
|
// Only publish very first time or when the result has changed.
|
|
|
@ -124,6 +128,7 @@ void LandDetector::_cycle() |
|
|
|
(_landDetected.freefall != freefallDetected) || |
|
|
|
(_landDetected.freefall != freefallDetected) || |
|
|
|
(_landDetected.landed != landDetected) || |
|
|
|
(_landDetected.landed != landDetected) || |
|
|
|
(_landDetected.ground_contact != ground_contactDetected) || |
|
|
|
(_landDetected.ground_contact != ground_contactDetected) || |
|
|
|
|
|
|
|
(_landDetected.maybe_landed != maybe_landedDetected) || |
|
|
|
(fabsf(_landDetected.alt_max - alt_max_prev) > FLT_EPSILON)) { |
|
|
|
(fabsf(_landDetected.alt_max - alt_max_prev) > FLT_EPSILON)) { |
|
|
|
|
|
|
|
|
|
|
|
if (!landDetected && _landDetected.landed) { |
|
|
|
if (!landDetected && _landDetected.landed) { |
|
|
@ -144,6 +149,7 @@ void LandDetector::_cycle() |
|
|
|
_landDetected.freefall = (_state == LandDetectionState::FREEFALL); |
|
|
|
_landDetected.freefall = (_state == LandDetectionState::FREEFALL); |
|
|
|
_landDetected.landed = (_state == LandDetectionState::LANDED); |
|
|
|
_landDetected.landed = (_state == LandDetectionState::LANDED); |
|
|
|
_landDetected.ground_contact = (_state == LandDetectionState::GROUND_CONTACT); |
|
|
|
_landDetected.ground_contact = (_state == LandDetectionState::GROUND_CONTACT); |
|
|
|
|
|
|
|
_landDetected.maybe_landed = (_state == LandDetectionState::MAYBE_LANDED); |
|
|
|
_landDetected.alt_max = _altitude_max; |
|
|
|
_landDetected.alt_max = _altitude_max; |
|
|
|
|
|
|
|
|
|
|
|
int instance; |
|
|
|
int instance; |
|
|
@ -188,6 +194,7 @@ void LandDetector::_update_state() |
|
|
|
* with higher priority for landed */ |
|
|
|
* with higher priority for landed */ |
|
|
|
_freefall_hysteresis.set_state_and_update(_get_freefall_state()); |
|
|
|
_freefall_hysteresis.set_state_and_update(_get_freefall_state()); |
|
|
|
_landed_hysteresis.set_state_and_update(_get_landed_state()); |
|
|
|
_landed_hysteresis.set_state_and_update(_get_landed_state()); |
|
|
|
|
|
|
|
_maybe_landed_hysteresis.set_state_and_update(_get_maybe_landed_state()); |
|
|
|
_ground_contact_hysteresis.set_state_and_update(_landed_hysteresis.get_state() || _get_ground_contact_state()); |
|
|
|
_ground_contact_hysteresis.set_state_and_update(_landed_hysteresis.get_state() || _get_ground_contact_state()); |
|
|
|
|
|
|
|
|
|
|
|
if (_freefall_hysteresis.get_state()) { |
|
|
|
if (_freefall_hysteresis.get_state()) { |
|
|
@ -196,6 +203,9 @@ void LandDetector::_update_state() |
|
|
|
} else if (_landed_hysteresis.get_state()) { |
|
|
|
} else if (_landed_hysteresis.get_state()) { |
|
|
|
_state = LandDetectionState::LANDED; |
|
|
|
_state = LandDetectionState::LANDED; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (_maybe_landed_hysteresis.get_state()) { |
|
|
|
|
|
|
|
_state = LandDetectionState::MAYBE_LANDED; |
|
|
|
|
|
|
|
|
|
|
|
} else if (_ground_contact_hysteresis.get_state()) { |
|
|
|
} else if (_ground_contact_hysteresis.get_state()) { |
|
|
|
_state = LandDetectionState::GROUND_CONTACT; |
|
|
|
_state = LandDetectionState::GROUND_CONTACT; |
|
|
|
|
|
|
|
|
|
|
|