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/ArduCopter/commands.cpp
Views: 1798
#include "Copter.h"12// checks if we should update ahrs/RTL home position from the EKF3void Copter::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 failure17}18}19}2021// set_home_to_current_location_inflight - set home to current GPS location (horizontally) and EKF origin vertically22void Copter::set_home_to_current_location_inflight() {23// get current location from EKF24Location temp_loc;25Location ekf_origin;26if (ahrs.get_location(temp_loc) && ahrs.get_origin(ekf_origin)) {27temp_loc.alt = ekf_origin.alt;28if (!set_home(temp_loc, false)) {29return;30}31// we have successfully set AHRS home, set it for SmartRTL32#if MODE_SMARTRTL_ENABLED33g2.smart_rtl.set_home(true);34#endif35}36}3738// set_home_to_current_location - set home to current GPS location39bool Copter::set_home_to_current_location(bool lock) {40// get current location from EKF41Location temp_loc;42if (ahrs.get_location(temp_loc)) {43if (!set_home(temp_loc, lock)) {44return false;45}46// we have successfully set AHRS home, set it for SmartRTL47#if MODE_SMARTRTL_ENABLED48g2.smart_rtl.set_home(true);49#endif50return true;51}52return false;53}5455// set_home - sets ahrs home (used for RTL) to specified location56// returns true if home location set successfully57bool Copter::set_home(const Location& loc, bool lock)58{59// check EKF origin has been set60Location ekf_origin;61if (!ahrs.get_origin(ekf_origin)) {62return false;63}6465// set ahrs home (used for RTL)66if (!ahrs.set_home(loc)) {67return false;68}6970// lock home position71if (lock) {72ahrs.lock_home();73}7475// return success76return true;77}787980