Skip to content

Commit

Permalink
Plane: fence: refactor action cases
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed Feb 23, 2025
1 parent 5f1d3da commit 9dc2428
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions ArduPlane/fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,24 @@ void Plane::fence_check()
switch (fence_act) {
case AC_FENCE_ACTION_REPORT_ONLY:
break;
case AC_FENCE_ACTION_GUIDED:
case AC_FENCE_ACTION_GUIDED_THROTTLE_PASS:

case AC_FENCE_ACTION_RTL_AND_LAND:
if (fence_act == AC_FENCE_ACTION_RTL_AND_LAND) {
if (control_mode == &mode_auto &&
mission.get_in_landing_sequence_flag() &&
(g.rtl_autoland == RtlAutoland::RTL_THEN_DO_LAND_START ||
g.rtl_autoland == RtlAutoland::RTL_IMMEDIATE_DO_LAND_START)) {
// already landing
return;
}
set_mode(mode_rtl, ModeReason::FENCE_BREACHED);
} else {
set_mode(mode_guided, ModeReason::FENCE_BREACHED);
if (control_mode == &mode_auto &&
mission.get_in_landing_sequence_flag() &&
(g.rtl_autoland == RtlAutoland::RTL_THEN_DO_LAND_START ||
g.rtl_autoland == RtlAutoland::RTL_IMMEDIATE_DO_LAND_START)) {
// already landing
return;
}
set_mode(mode_rtl, ModeReason::FENCE_BREACHED);
break;

case AC_FENCE_ACTION_GUIDED:
case AC_FENCE_ACTION_GUIDED_THROTTLE_PASS:
set_mode(mode_guided, ModeReason::FENCE_BREACHED);

Location loc;
if (fence.get_return_rally() != 0 || fence_act == AC_FENCE_ACTION_RTL_AND_LAND) {
if (fence.get_return_rally() != 0) {
loc = calc_best_rally_or_home_location(current_loc, get_RTL_altitude_cm());
} else {
//return to fence return point, not a rally point
Expand Down Expand Up @@ -126,10 +126,8 @@ void Plane::fence_check()
}
}

if (fence.get_action() != AC_FENCE_ACTION_RTL_AND_LAND) {
setup_terrain_target_alt(loc);
set_guided_WP(loc);
}
setup_terrain_target_alt(loc);
set_guided_WP(loc);

if (fence.get_action() == AC_FENCE_ACTION_GUIDED_THROTTLE_PASS) {
guided_throttle_passthru = true;
Expand Down

0 comments on commit 9dc2428

Please sign in to comment.