@@ -168,6 +168,7 @@ const AP_Param::GroupInfo AP_AdvancedFailsafe::var_info[] = {
168
168
// @Description: See description for each bitmask bit description
169
169
// @Bitmask: 0: Continue the mission even after comms are recovered (does not go to the mission item at the time comms were lost)
170
170
// @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
171
172
AP_GROUPINFO (" OPTIONS" , 21 , AP_AdvancedFailsafe, options, 0 ),
172
173
173
174
// @Param: GCS_TIMEOUT
@@ -251,13 +252,16 @@ AP_AdvancedFailsafe::check(uint32_t last_valid_rc_ms)
251
252
if (!gcs_link_ok) {
252
253
GCS_SEND_TEXT (MAV_SEVERITY_DEBUG, " AFS State: DATA_LINK_LOSS" );
253
254
_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 ()){
256
258
mission.set_current_cmd (_wp_comms_hold);
259
+
257
260
if (mode == AFS_AUTO && option_is_set (Option::GCS_FS_ALL_AUTONOMOUS_MODES)) {
258
261
set_mode_auto ();
259
262
}
260
263
}
264
+
261
265
// if two events happen within 30s we consider it to be part of the same event
262
266
if (now - _last_comms_loss_ms > 30 *1000UL ) {
263
267
_comms_loss_count++;
@@ -414,6 +418,27 @@ AP_AdvancedFailsafe::check_altlimit(void)
414
418
return false ;
415
419
}
416
420
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
+ }
417
442
/*
418
443
return true if we should crash the vehicle
419
444
*/
0 commit comments