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/Rover/mode_rtl.cpp
Views: 1798
#include "Rover.h"12bool ModeRTL::_enter()3{4// refuse RTL if home has not been set5if (!AP::ahrs().home_is_set()) {6return false;7}89// initialise waypoint navigation library10g2.wp_nav.init(MAX(0.0f, g2.rtl_speed));1112// set target to the closest rally point or home13#if HAL_RALLY_ENABLED14if (!g2.wp_nav.set_desired_location(g2.rally.calc_best_rally_or_home_location(rover.current_loc, ahrs.get_home().alt))) {15return false;16}17#else18// set destination19if (!g2.wp_nav.set_desired_location(ahrs.get_home())) {20return false;21}22#endif2324send_notification = true;25_loitering = false;26return true;27}2829void ModeRTL::update()30{31// determine if we should keep navigating32if (!g2.wp_nav.reached_destination()) {33// update navigation controller34navigate_to_waypoint();35} else {36// send notification37if (send_notification) {38send_notification = false;39gcs().send_text(MAV_SEVERITY_INFO, "Reached destination");40}4142// we have reached the destination43// boats loiter, rovers stop44if (!rover.is_boat()) {45stop_vehicle();46} else {47// if not loitering yet, start loitering48if (!_loitering) {49_loitering = rover.mode_loiter.enter();50}51// update stop or loiter52if (_loitering) {53rover.mode_loiter.update();54} else {55stop_vehicle();56}57}5859// update distance to destination60_distance_to_destination = rover.current_loc.get_distance(g2.wp_nav.get_destination());61}62}6364// get desired location65bool ModeRTL::get_desired_location(Location& destination) const66{67if (g2.wp_nav.is_destination_valid()) {68destination = g2.wp_nav.get_oa_destination();69return true;70}71return false;72}7374bool ModeRTL::reached_destination() const75{76return g2.wp_nav.reached_destination();77}7879// set desired speed in m/s80bool ModeRTL::set_desired_speed(float speed)81{82return g2.wp_nav.set_speed_max(speed);83}848586