2015-05-13 00:16:45 -03:00
|
|
|
#include "Rover.h"
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2018-11-07 18:41:48 -04:00
|
|
|
// set ahrs home to current location from inertial-nav location
|
2017-06-05 04:55:24 -03:00
|
|
|
bool Rover::set_home_to_current_location(bool lock)
|
|
|
|
{
|
|
|
|
Location temp_loc;
|
2022-01-20 19:42:41 -04:00
|
|
|
if (ahrs.have_inertial_nav() && ahrs.get_location(temp_loc)) {
|
2018-01-15 12:11:14 -04:00
|
|
|
if (!set_home(temp_loc, lock)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// we have successfully set AHRS home, set it for SmartRTL
|
|
|
|
g2.smart_rtl.set_home(true);
|
|
|
|
return true;
|
2017-06-05 04:55:24 -03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sets ahrs home to specified location
|
2020-05-23 17:51:49 -03:00
|
|
|
// returns true if home location set successfully
|
2017-06-05 04:55:24 -03:00
|
|
|
bool Rover::set_home(const Location& loc, bool lock)
|
|
|
|
{
|
|
|
|
// set ahrs home
|
2018-05-29 21:52:57 -03:00
|
|
|
if (!ahrs.set_home(loc)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-05 04:55:24 -03:00
|
|
|
|
|
|
|
// lock home position
|
|
|
|
if (lock) {
|
2018-05-17 23:57:50 -03:00
|
|
|
ahrs.lock_home();
|
2017-06-05 04:55:24 -03:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2016-12-20 09:32:04 -04:00
|
|
|
// Save Home to EEPROM
|
2018-12-11 20:10:20 -04:00
|
|
|
mode_auto.mission.write_home_to_storage();
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// send text of home position to ground stations
|
2017-07-08 22:40:59 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Set HOME to %.6f %.6f at %.2fm",
|
2017-06-05 04:55:24 -03:00
|
|
|
static_cast<double>(loc.lat * 1.0e-7f),
|
|
|
|
static_cast<double>(loc.lng * 1.0e-7f),
|
|
|
|
static_cast<double>(loc.alt * 0.01f));
|
|
|
|
|
|
|
|
// return success
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2018-11-07 18:41:48 -04:00
|
|
|
// called periodically while disarmed to update our home position to
|
|
|
|
// our current location
|
2015-10-30 02:41:06 -03:00
|
|
|
void Rover::update_home()
|
|
|
|
{
|
2018-11-07 18:41:48 -04:00
|
|
|
if (ahrs.home_is_locked()) {
|
|
|
|
// we've been explicitly told our home location
|
|
|
|
return;
|
2015-10-30 02:41:06 -03:00
|
|
|
}
|
2018-11-07 18:41:48 -04:00
|
|
|
|
|
|
|
Location loc{};
|
2022-01-20 19:42:41 -04:00
|
|
|
if (!ahrs.get_location(loc)) {
|
2018-11-07 18:41:48 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-30 02:41:06 -03:00
|
|
|
barometer.update_calibration();
|
2018-11-07 18:41:48 -04:00
|
|
|
|
|
|
|
if (ahrs.home_is_set() &&
|
2019-02-24 20:10:39 -04:00
|
|
|
loc.get_distance(ahrs.get_home()) < DISTANCE_HOME_MINCHANGE) {
|
2018-11-07 18:41:48 -04:00
|
|
|
// insufficiently moved from current home - don't change it
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-10 10:04:14 -04:00
|
|
|
IGNORE_RETURN(ahrs.set_home(loc));
|
2015-10-30 02:41:06 -03:00
|
|
|
}
|