Skip to content

Commit

Permalink
VTOL: Mode 25 to land at the guided location
Browse files Browse the repository at this point in the history
  • Loading branch information
magicrub committed Oct 12, 2023
1 parent 659db36 commit a07330a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions ArduPlane/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class ModeLoiterAltQLand : public ModeLoiter
// handle a guided target request from GCS
bool handle_guided_request(Location target_loc) override;

Location loiter_wp;

protected:
bool _enter() override;

Expand Down
23 changes: 13 additions & 10 deletions ArduPlane/mode_LoiterAltQLand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ bool ModeLoiterAltQLand::_enter()
return true;
}

const Location previous_wp = plane.next_WP_loc;

ModeLoiter::_enter();

#if AP_TERRAIN_AVAILABLE
if (plane.terrain_enabled_in_mode(Mode::Number::QLAND)) {
plane.next_WP_loc.set_alt_cm(quadplane.qrtl_alt*100UL, Location::AltFrame::ABOVE_TERRAIN);
} else {
plane.next_WP_loc.set_alt_cm(quadplane.qrtl_alt*100UL, Location::AltFrame::ABOVE_HOME);
}
#else
plane.next_WP_loc.set_alt_cm(quadplane.qrtl_alt*100UL, Location::AltFrame::ABOVE_HOME);
#endif
const Location target_loc = (plane.previous_mode->is_guided_mode() && !plane.any_failsafe_triggered()) ? previous_wp : plane.next_WP_loc;
handle_guided_request(target_loc);

switch_qland();

Expand All @@ -38,7 +33,13 @@ void ModeLoiterAltQLand::switch_qland()
{
ftype dist;
if ((!plane.current_loc.get_alt_distance(plane.next_WP_loc, dist) || is_negative(dist)) && plane.nav_controller->reached_loiter_target()) {
plane.set_mode(plane.mode_qland, ModeReason::LOITER_ALT_REACHED_QLAND);
if (plane.previous_mode->is_guided_mode() && !plane.any_failsafe_triggered()) {
plane.set_mode(plane.mode_qrtl, ModeReason::LOITER_ALT_REACHED_QLAND);
plane.set_next_WP(loiter_wp);
} else
{
plane.set_mode(plane.mode_qland, ModeReason::LOITER_ALT_REACHED_QLAND);
}
}
}

Expand All @@ -57,6 +58,8 @@ bool ModeLoiterAltQLand::handle_guided_request(Location target_loc)

plane.set_guided_WP(target_loc);

loiter_wp = target_loc;

return true;
}

Expand Down

0 comments on commit a07330a

Please sign in to comment.