Commander: add max flight time RTL

Adds COM_FLT_TIME_MAX param and logic in Commander to enforce RTL when
flight time is above this value. User can only override to LAND mode,
but not proceed flight beyond that.

Signed-off-by: Silvan Fuhrer <silvan@auterion.com>
This commit is contained in:
Silvan Fuhrer 2022-05-09 18:01:25 +02:00
parent 2e1cdc9e75
commit 1aad82f87d
3 changed files with 38 additions and 1 deletions

View File

@ -2916,6 +2916,24 @@ Commander::run()
/* Get current timestamp */
const hrt_abstime now = hrt_absolute_time();
// Trigger RTL if flight time is larger than max flight time specified in COM_FLT_TIME_MAX.
// The user is not able to override once above threshold, except for triggering Land.
if (!_vehicle_land_detected.landed
&& _param_com_flt_time_max.get() > FLT_EPSILON
&& _internal_state.main_state != commander_state_s::MAIN_STATE_AUTO_RTL
&& _internal_state.main_state != commander_state_s::MAIN_STATE_AUTO_LAND
&& (now - _status.takeoff_time) > (1_s * _param_com_flt_time_max.get())) {
main_state_transition(_status, commander_state_s::MAIN_STATE_AUTO_RTL, _status_flags, _internal_state);
_status_changed = true;
mavlink_log_critical(&_mavlink_log_pub, "Maximum flight time reached, abort operation and RTL");
/* EVENT
* @description
* Maximal flight time reached, return to launch.
*/
events::send(events::ID("commander_max_flight_time_rtl"), {events::Log::Critical, events::LogInternal::Warning},
"Maximum flight time reached, abort operation and RTL");
}
// automatically set or update home position
if (_param_com_home_en.get() && !_home_pub.get().manual_home) {
if (!_armed.armed && _vehicle_land_detected.landed) {

View File

@ -273,7 +273,8 @@ private:
(ParamFloat<px4::params::CP_DIST>) _param_cp_dist,
(ParamFloat<px4::params::BAT_LOW_THR>) _param_bat_low_thr,
(ParamFloat<px4::params::BAT_CRIT_THR>) _param_bat_crit_thr
(ParamFloat<px4::params::BAT_CRIT_THR>) _param_bat_crit_thr,
(ParamInt<px4::params::COM_FLT_TIME_MAX>) _param_com_flt_time_max
)
enum class PrearmedMode {

View File

@ -1065,3 +1065,21 @@ PARAM_DEFINE_INT32(COM_ARM_SDCARD, 1);
* @unit m/s
*/
PARAM_DEFINE_FLOAT(COM_WIND_WARN, -1.f);
/**
* Maximum allowed flight time
*
* The vehicle aborts the current operation and returns to launch when
* the time since takeoff is above this value. It is not possible to resume the
* mission or switch to any mode other than RTL or Land.
*
* Set a nagative value to disable.
*
*
* @unit s
* @min -1
* @max 10000
* @value 0 Disable
* @group Commander
*/
PARAM_DEFINE_INT32(COM_FLT_TIME_MAX, -1);