Ardupilot2/APMrover2/mode_rtl.cpp

56 lines
1.4 KiB
C++
Raw Normal View History

2017-07-18 23:17:45 -03:00
#include "mode.h"
#include "Rover.h"
bool ModeRTL::_enter()
{
// refuse RTL if home has not been set
2018-03-15 22:49:06 -03:00
if (!AP::ahrs().home_is_set()) {
return false;
}
// initialise waypoint speed
2019-04-29 03:31:45 -03:00
if (is_positive(g2.rtl_speed)) {
g2.wp_nav.set_desired_speed(g2.rtl_speed);
} else {
g2.wp_nav.set_desired_speed_to_default();
}
2018-08-29 22:14:31 -03:00
// set target to the closest rally point or home
#if AP_RALLY == ENABLED
2019-04-29 03:31:45 -03:00
g2.wp_nav.set_desired_location(g2.rally.calc_best_rally_or_home_location(rover.current_loc, ahrs.get_home().alt));
2018-08-29 22:14:31 -03:00
#else
// set destination
2019-04-29 03:31:45 -03:00
g2.wp_nav.set_desired_location(rover.home);
2018-08-29 22:14:31 -03:00
#endif
2019-04-29 03:31:45 -03:00
sent_notification = false;
2017-07-18 23:17:45 -03:00
return true;
}
void ModeRTL::update()
{
// determine if we should keep navigating
2019-04-29 03:31:45 -03:00
if (!g2.wp_nav.reached_destination() || rover.is_boat()) {
// update navigation controller
navigate_to_waypoint();
} else {
2019-04-29 03:31:45 -03:00
// send notification
if (!sent_notification) {
sent_notification = true;
gcs().send_text(MAV_SEVERITY_INFO, "Reached destination");
}
// we've reached destination so stop
stop_vehicle();
2019-04-29 03:31:45 -03:00
// update distance to destination
_distance_to_destination = rover.current_loc.get_distance(g2.wp_nav.get_destination());
2017-07-18 23:17:45 -03:00
}
}
2019-04-29 03:31:45 -03:00
bool ModeRTL::reached_destination() const
{
return g2.wp_nav.reached_destination();
}