ardupilot/APMrover2/mode_rtl.cpp

44 lines
1.3 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
set_desired_speed_to_default(true);
// set destination
set_desired_location(rover.home);
2017-08-03 03:19:57 -03:00
// RTL never reverses
rover.set_reverse(false);
2017-07-18 23:17:45 -03:00
return true;
}
void ModeRTL::update()
{
// calculate distance to home
_distance_to_destination = get_distance(rover.current_loc, _destination);
const bool near_wp = _distance_to_destination <= rover.g.waypoint_radius;
// check if we've reached the destination
if (!_reached_destination && (near_wp || location_passed_point(rover.current_loc, _origin, _destination))) {
// trigger reached
_reached_destination = true;
gcs().send_text(MAV_SEVERITY_INFO, "Reached destination");
}
// determine if we should keep navigating
if (!_reached_destination || (rover.is_boat() && !near_wp)) {
// continue driving towards destination
calc_steering_to_waypoint(_reached_destination ? rover.current_loc :_origin, _destination);
calc_throttle(calc_reduced_speed_for_turn_or_distance(_desired_speed), true, false);
} else {
// we've reached destination so stop
stop_vehicle();
2017-07-18 23:17:45 -03:00
}
}