Skip to content

Commit a2e0e28

Browse files
committed
Plane: fence: refactor action cases
1 parent 478b47c commit a2e0e28

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

ArduPlane/fence.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,24 @@ void Plane::fence_check()
8080
switch (fence_act) {
8181
case AC_FENCE_ACTION_REPORT_ONLY:
8282
break;
83-
case AC_FENCE_ACTION_GUIDED:
84-
case AC_FENCE_ACTION_GUIDED_THROTTLE_PASS:
83+
8584
case AC_FENCE_ACTION_RTL_AND_LAND:
86-
if (fence_act == AC_FENCE_ACTION_RTL_AND_LAND) {
87-
if (control_mode == &mode_auto &&
88-
mission.get_in_landing_sequence_flag() &&
89-
(g.rtl_autoland == RtlAutoland::RTL_THEN_DO_LAND_START ||
90-
g.rtl_autoland == RtlAutoland::RTL_IMMEDIATE_DO_LAND_START)) {
91-
// already landing
92-
return;
93-
}
94-
set_mode(mode_rtl, ModeReason::FENCE_BREACHED);
95-
} else {
96-
set_mode(mode_guided, ModeReason::FENCE_BREACHED);
85+
if (control_mode == &mode_auto &&
86+
mission.get_in_landing_sequence_flag() &&
87+
(g.rtl_autoland == RtlAutoland::RTL_THEN_DO_LAND_START ||
88+
g.rtl_autoland == RtlAutoland::RTL_IMMEDIATE_DO_LAND_START)) {
89+
// already landing
90+
return;
9791
}
92+
set_mode(mode_rtl, ModeReason::FENCE_BREACHED);
93+
break;
94+
95+
case AC_FENCE_ACTION_GUIDED:
96+
case AC_FENCE_ACTION_GUIDED_THROTTLE_PASS:
97+
set_mode(mode_guided, ModeReason::FENCE_BREACHED);
9898

9999
Location loc;
100-
if (fence.get_return_rally() != 0 || fence_act == AC_FENCE_ACTION_RTL_AND_LAND) {
100+
if (fence.get_return_rally() != 0) {
101101
loc = calc_best_rally_or_home_location(current_loc, get_RTL_altitude_cm());
102102
} else {
103103
//return to fence return point, not a rally point
@@ -126,10 +126,8 @@ void Plane::fence_check()
126126
}
127127
}
128128

129-
if (fence.get_action() != AC_FENCE_ACTION_RTL_AND_LAND) {
130-
setup_terrain_target_alt(loc);
131-
set_guided_WP(loc);
132-
}
129+
setup_terrain_target_alt(loc);
130+
set_guided_WP(loc);
133131

134132
if (fence.get_action() == AC_FENCE_ACTION_GUIDED_THROTTLE_PASS) {
135133
guided_throttle_passthru = true;

0 commit comments

Comments
 (0)