|
|
|
@ -60,32 +60,118 @@ void Rover::set_guided_velocity(float target_steer_speed, float target_speed)
@@ -60,32 +60,118 @@ void Rover::set_guided_velocity(float target_steer_speed, float target_speed)
|
|
|
|
|
rover.rtl_complete = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// run this at setup on the ground
|
|
|
|
|
// -------------------------------
|
|
|
|
|
void Rover::init_home() |
|
|
|
|
// checks if we should update ahrs home position from the EKF's position
|
|
|
|
|
void Rover::update_home_from_EKF() |
|
|
|
|
{ |
|
|
|
|
if (!have_position) { |
|
|
|
|
// we need position information
|
|
|
|
|
// exit immediately if home already set
|
|
|
|
|
if (home_is_set != HOME_UNSET) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gcs_send_text(MAV_SEVERITY_INFO, "Init HOME"); |
|
|
|
|
// move home to current ekf location (this will set home_state to HOME_SET)
|
|
|
|
|
set_home_to_current_location(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ahrs.set_home(gps.location()); |
|
|
|
|
home_is_set = HOME_SET_NOT_LOCKED; |
|
|
|
|
Log_Write_Home_And_Origin(); |
|
|
|
|
GCS_MAVLINK::send_home_all(gps.location()); |
|
|
|
|
// 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; |
|
|
|
|
if (ahrs.get_position(temp_loc)) { |
|
|
|
|
return set_home(temp_loc, lock); |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set EKF origin to home if it hasn't been set yet
|
|
|
|
|
Location ekf_origin; |
|
|
|
|
if (!ahrs.get_origin(ekf_origin)) { |
|
|
|
|
ahrs.set_origin(loc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set ahrs home
|
|
|
|
|
ahrs.set_home(loc); |
|
|
|
|
|
|
|
|
|
// init compass declination
|
|
|
|
|
if (home_is_set == HOME_UNSET) { |
|
|
|
|
// Set compass declination automatically
|
|
|
|
|
if (g.compass_enabled) { |
|
|
|
|
compass.set_initial_location(loc.lat, loc.lng); |
|
|
|
|
} |
|
|
|
|
// record home is set
|
|
|
|
|
home_is_set = HOME_SET_NOT_LOCKED; |
|
|
|
|
|
|
|
|
|
// 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// initialise navigation to home
|
|
|
|
|
next_WP = prev_WP = home; |
|
|
|
|
|
|
|
|
|
// Load home for a default guided_WP
|
|
|
|
|
set_guided_WP(home); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// lock home position
|
|
|
|
|
if (lock) { |
|
|
|
|
home_is_set = HOME_SET_AND_LOCKED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Save Home to EEPROM
|
|
|
|
|
mission.write_home_to_storage(); |
|
|
|
|
|
|
|
|
|
// Save prev loc
|
|
|
|
|
// -------------
|
|
|
|
|
next_WP = prev_WP = home; |
|
|
|
|
// log ahrs home and ekf origin dataflash
|
|
|
|
|
Log_Write_Home_And_Origin(); |
|
|
|
|
|
|
|
|
|
// send new home location to GCS
|
|
|
|
|
GCS_MAVLINK::send_home_all(loc); |
|
|
|
|
|
|
|
|
|
// send text of home position to ground stations
|
|
|
|
|
rover.gcs_send_text_fmt(MAV_SEVERITY_INFO, "Set HOME to %.6f %.6f at %.2fm", |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Load home for a default guided_WP
|
|
|
|
|
// -------------
|
|
|
|
|
set_guided_WP(home); |
|
|
|
|
// 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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Rover::restart_nav() |
|
|
|
|