Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/ArduPlane/mode_LoiterAltQLand.cpp
Views: 1798
#include "mode.h"1#include "Plane.h"23#if HAL_QUADPLANE_ENABLED45bool ModeLoiterAltQLand::_enter()6{7if (plane.previous_mode->is_vtol_mode() || plane.quadplane.in_vtol_mode()) {8plane.set_mode(plane.mode_qland, ModeReason::LOITER_ALT_IN_VTOL);9return true;10}1112// If we were already in a loiter then use that waypoint. Else, use the current point13const bool already_in_a_loiter = plane.nav_controller->reached_loiter_target() && !plane.nav_controller->data_is_stale();14const Location loiter_wp = already_in_a_loiter ? plane.next_WP_loc : plane.current_loc;1516ModeLoiter::_enter();1718handle_guided_request(loiter_wp);1920switch_qland();2122return true;23}2425void ModeLoiterAltQLand::navigate()26{27switch_qland();2829ModeLoiter::navigate();30}3132void ModeLoiterAltQLand::switch_qland()33{34ftype dist;35if ((!plane.current_loc.get_alt_distance(plane.next_WP_loc, dist) || is_negative(dist)) && plane.nav_controller->reached_loiter_target()) {36plane.set_mode(plane.mode_qland, ModeReason::LOITER_ALT_REACHED_QLAND);37}38}3940bool ModeLoiterAltQLand::handle_guided_request(Location target_loc)41{42// setup altitude43#if AP_TERRAIN_AVAILABLE44if (plane.terrain_enabled_in_mode(Mode::Number::QLAND)) {45target_loc.set_alt_m(quadplane.qrtl_alt, Location::AltFrame::ABOVE_TERRAIN);46} else {47target_loc.set_alt_m(quadplane.qrtl_alt, Location::AltFrame::ABOVE_HOME);48}49#else50target_loc.set_alt_m(quadplane.qrtl_alt, Location::AltFrame::ABOVE_HOME);51#endif5253plane.set_guided_WP(target_loc);5455return true;56}5758#endif596061