Skip to content

Commit 7776686

Browse files
committed
AP_AdvancedFailsafe: option to not go back to the loss comm mission item if we already in the return path
1 parent a5d7f03 commit 7776686

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

libraries/AP_AdvancedFailsafe/AP_AdvancedFailsafe.cpp

+27-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ const AP_Param::GroupInfo AP_AdvancedFailsafe::var_info[] = {
168168
// @Description: See description for each bitmask bit description
169169
// @Bitmask: 0: Continue the mission even after comms are recovered (does not go to the mission item at the time comms were lost)
170170
// @Bitmask: 1: Enable AFS for all autonomous modes (not just AUTO)
171+
// @Bitmask: 2: Option to not jump to AFS_WP_COMMS if already in the return path
171172
AP_GROUPINFO("OPTIONS", 21, AP_AdvancedFailsafe, options, 0),
172173

173174
// @Param: GCS_TIMEOUT
@@ -251,13 +252,16 @@ AP_AdvancedFailsafe::check(uint32_t last_valid_rc_ms)
251252
if (!gcs_link_ok) {
252253
GCS_SEND_TEXT(MAV_SEVERITY_DEBUG, "AFS State: DATA_LINK_LOSS");
253254
_state = STATE_DATA_LINK_LOSS;
254-
if (_wp_comms_hold) {
255-
_saved_wp = mission.get_current_nav_cmd().index;
255+
_saved_wp = mission.get_current_nav_cmd().index;
256+
257+
if (should_use_comms_hold()){
256258
mission.set_current_cmd(_wp_comms_hold);
259+
257260
if (mode == AFS_AUTO && option_is_set(Option::GCS_FS_ALL_AUTONOMOUS_MODES)) {
258261
set_mode_auto();
259262
}
260263
}
264+
261265
// if two events happen within 30s we consider it to be part of the same event
262266
if (now - _last_comms_loss_ms > 30*1000UL) {
263267
_comms_loss_count++;
@@ -414,6 +418,27 @@ AP_AdvancedFailsafe::check_altlimit(void)
414418
return false;
415419
}
416420

421+
/*
422+
return true if we should jump to _wp_comms_hold
423+
*/
424+
bool AP_AdvancedFailsafe::should_use_comms_hold(void){
425+
426+
AP_Mission *_mission = AP::mission();
427+
428+
if (_mission == nullptr) {
429+
return false;
430+
}
431+
432+
if (_wp_comms_hold <= 0) {
433+
return false;
434+
}
435+
436+
if ((_mission->state() == AP_Mission::MISSION_RUNNING) && _mission->get_in_return_path_flag() && option_is_set(Option::CONTINUE_IF_ALREADY_IN_RETURN_PATH)){
437+
return false;
438+
}
439+
440+
return true;
441+
}
417442
/*
418443
return true if we should crash the vehicle
419444
*/

libraries/AP_AdvancedFailsafe/AP_AdvancedFailsafe.h

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AP_AdvancedFailsafe
8282
// during sensor calibration
8383
void heartbeat(void);
8484

85+
//return true if we should jump to _wp_comms_hold
86+
bool should_use_comms_hold(void);
87+
8588
// return true if we are terminating (deliberately crashing the vehicle)
8689
bool should_crash_vehicle(void);
8790

@@ -171,6 +174,7 @@ class AP_AdvancedFailsafe
171174
enum class Option {
172175
CONTINUE_AFTER_RECOVERED = (1U<<0),
173176
GCS_FS_ALL_AUTONOMOUS_MODES = (1U<<1),
177+
CONTINUE_IF_ALREADY_IN_RETURN_PATH = (1U<<2),
174178
};
175179
bool option_is_set(Option option) const {
176180
return (options.get() & int16_t(option)) != 0;

0 commit comments

Comments
 (0)