Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/ArduSub/commands.cpp
Views: 1798
#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}910// special logic if home is set in-flight11if (motors.armed()) {12set_home_to_current_location_inflight();13} else {14// move home to current ekf location (this will set home_state to HOME_SET)15if (!set_home_to_current_location(false)) {16// ignore this failure17}18}19}2021// set_home_to_current_location_inflight - set home to current GPS location (horizontally) and EKF origin vertically22void Sub::set_home_to_current_location_inflight()23{24// get current location from EKF25Location temp_loc;26Location ekf_origin;27if (ahrs.get_location(temp_loc) && ahrs.get_origin(ekf_origin)) {28temp_loc.alt = ekf_origin.alt;29if (!set_home(temp_loc, false)) {30// ignore this failure31}32}33}3435// set_home_to_current_location - set home to current GPS location36bool Sub::set_home_to_current_location(bool lock)37{38// get current location from EKF39Location temp_loc;40if (ahrs.get_location(temp_loc)) {4142// Make home always at the water's surface.43// This allows disarming and arming again at depth.44// This also ensures that mission items with relative altitude frame, are always45// relative to the water's surface, whether in a high elevation lake, or at sea level.46temp_loc.alt -= barometer.get_altitude() * 100.0f;47return set_home(temp_loc, lock);48}49return false;50}5152// set_home - sets ahrs home (used for RTL) to specified location53// returns true if home location set successfully54bool Sub::set_home(const Location& loc, bool lock)55{56// check if EKF origin has been set57Location ekf_origin;58if (!ahrs.get_origin(ekf_origin)) {59return false;60}6162// set ahrs home (used for RTL)63if (!ahrs.set_home(loc)) {64return false;65}6667// lock home position68if (lock) {69ahrs.lock_home();70}7172// return success73return true;74}757677