2015-05-13 00:16:45 -03:00
|
|
|
#include "Rover.h"
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// checks if we should update ahrs home position from the EKF's position
|
|
|
|
void Rover::update_home_from_EKF()
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2017-06-05 04:55:24 -03:00
|
|
|
// exit immediately if home already set
|
2018-03-15 22:06:46 -03:00
|
|
|
if (ahrs.home_is_set()) {
|
2012-11-28 07:44:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// move home to current ekf location (this will set home_state to HOME_SET)
|
|
|
|
set_home_to_current_location(false);
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// set ahrs home to current location from EKF reported location or GPS
|
|
|
|
bool Rover::set_home_to_current_location(bool lock)
|
|
|
|
{
|
|
|
|
// use position from EKF if available otherwise use GPS
|
|
|
|
Location temp_loc;
|
2017-09-18 05:22:51 -03:00
|
|
|
if (ahrs.have_inertial_nav() && ahrs.get_position(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
|
|
|
|
// returns true if home location set successfully
|
|
|
|
bool Rover::set_home(const Location& loc, bool lock)
|
|
|
|
{
|
|
|
|
// check location is valid
|
|
|
|
if (loc.lat == 0 && loc.lng == 0 && loc.alt == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!check_latlng(loc)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-18 02:37:37 -03:00
|
|
|
// check if EKF origin has been set
|
2017-06-05 04:55:24 -03:00
|
|
|
Location ekf_origin;
|
|
|
|
if (!ahrs.get_origin(ekf_origin)) {
|
2017-09-18 02:37:37 -03:00
|
|
|
return false;
|
2017-06-05 04:55:24 -03:00
|
|
|
}
|
|
|
|
|
2018-05-17 23:57:50 -03:00
|
|
|
const bool home_was_set = ahrs.home_is_set();
|
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// set ahrs home
|
|
|
|
ahrs.set_home(loc);
|
|
|
|
|
2018-05-17 23:57:50 -03:00
|
|
|
if (!home_was_set) {
|
2017-06-05 04:55:24 -03:00
|
|
|
// log new home position which mission library will pull from ahrs
|
|
|
|
if (should_log(MASK_LOG_CMD)) {
|
|
|
|
AP_Mission::Mission_Command temp_cmd;
|
|
|
|
if (mission.read_cmd_from_storage(0, temp_cmd)) {
|
|
|
|
DataFlash.Log_Write_Mission_Cmd(mission, temp_cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
mission.write_home_to_storage();
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// log ahrs home and ekf origin dataflash
|
2018-05-16 00:28:59 -03:00
|
|
|
ahrs.Log_Write_Home_And_Origin();
|
2017-06-05 04:55:24 -03:00
|
|
|
|
2017-09-18 02:37:37 -03:00
|
|
|
// send new home and ekf origin to GCS
|
2018-05-16 01:48:48 -03:00
|
|
|
gcs().send_home();
|
|
|
|
gcs().send_ekf_origin();
|
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
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// checks if we should update ahrs/RTL home position from GPS
|
|
|
|
void Rover::set_system_time_from_GPS()
|
|
|
|
{
|
|
|
|
// exit immediately if system time already set
|
|
|
|
if (system_time_set) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we have a 3d lock and valid location
|
|
|
|
if (gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
|
|
|
|
// set system clock for log timestamps
|
|
|
|
const uint64_t gps_timestamp = gps.time_epoch_usec();
|
|
|
|
|
|
|
|
hal.util->set_system_clock(gps_timestamp);
|
|
|
|
|
|
|
|
// update signing timestamp
|
|
|
|
GCS_MAVLINK::update_signing_timestamp(gps_timestamp);
|
|
|
|
|
|
|
|
system_time_set = true;
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-10-30 02:41:06 -03:00
|
|
|
/*
|
|
|
|
update home location from GPS
|
|
|
|
this is called as long as we have 3D lock and the arming switch is
|
|
|
|
not pushed
|
|
|
|
*/
|
|
|
|
void Rover::update_home()
|
|
|
|
{
|
2018-05-17 23:57:50 -03:00
|
|
|
if (!ahrs.home_is_locked()) {
|
2017-02-27 15:14:51 -04:00
|
|
|
Location loc;
|
|
|
|
if (ahrs.get_position(loc)) {
|
2017-05-04 06:10:05 -03:00
|
|
|
if (get_distance(loc, ahrs.get_home()) > DISTANCE_HOME_MAX) {
|
|
|
|
ahrs.set_home(loc);
|
2018-05-16 00:28:59 -03:00
|
|
|
ahrs.Log_Write_Home_And_Origin();
|
2018-05-16 01:48:48 -03:00
|
|
|
gcs().send_home();
|
2017-05-04 06:10:05 -03:00
|
|
|
}
|
2016-08-24 23:48:08 -03:00
|
|
|
}
|
2015-10-30 02:41:06 -03:00
|
|
|
}
|
|
|
|
barometer.update_calibration();
|
|
|
|
}
|