#include "Sub.h"12// checks if we should update ahrs/RTL home position from the EKF3void Sub::update_home_from_EKF()4{5// exit immediately if home already set6if (ahrs.home_is_set()) {7return;8}9if (!set_home_to_current_location(false)) {10// ignore this failure11}12}1314// set_home_to_current_location - set home to current GPS location15bool Sub::set_home_to_current_location(bool lock)16{17// get current location from EKF18Location temp_loc;19if (ahrs.get_location(temp_loc)) {2021// Make home always at the water's surface.22// This allows disarming and arming again at depth.23// This also ensures that mission items with relative altitude frame, are always24// relative to the water's surface, whether in a high elevation lake, or at sea level.25temp_loc.offset_up_m(-barometer.get_altitude());26return set_home(temp_loc, lock);27}28return false;29}3031// set_home - sets ahrs home (used for RTL) to specified location32// returns true if home location set successfully33bool Sub::set_home(const Location& loc, bool lock)34{35// check if EKF origin has been set36Location ekf_origin;37if (!ahrs.get_origin(ekf_origin)) {38return false;39}4041// set ahrs home (used for RTL)42if (!ahrs.set_home(loc)) {43return false;44}4546// lock home position47if (lock) {48ahrs.lock_home();49}5051// return success52return true;53}545556