123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #include "Sub.h"
- void Sub::update_home_from_EKF()
- {
-
- if (ahrs.home_is_set()) {
- return;
- }
-
- if (motors.armed()) {
- set_home_to_current_location_inflight();
- } else {
-
- if (!set_home_to_current_location(false)) {
-
- }
- }
- }
- void Sub::set_home_to_current_location_inflight()
- {
-
- Location temp_loc;
- Location ekf_origin;
- if (ahrs.get_location(temp_loc) && ahrs.get_origin(ekf_origin)) {
- temp_loc.alt = ekf_origin.alt;
- if (!set_home(temp_loc, false)) {
-
- }
- }
- }
- bool Sub::set_home_to_current_location(bool lock)
- {
-
- Location temp_loc;
- if (ahrs.get_location(temp_loc)) {
-
-
-
-
- temp_loc.alt -= barometer.get_altitude() * 100.0f;
- return set_home(temp_loc, lock);
- }
- return false;
- }
- bool Sub::set_home(const Location& loc, bool lock)
- {
-
- Location ekf_origin;
- if (!ahrs.get_origin(ekf_origin)) {
- return false;
- }
- const bool home_was_set = ahrs.home_is_set();
-
- if (!ahrs.set_home(loc)) {
- return false;
- }
-
- if (!home_was_set) {
-
- scaleLongDown = loc.longitude_scale();
-
- Log_Write_Event(DATA_SET_HOME);
-
- if (should_log(MASK_LOG_CMD)) {
- AP_Mission::Mission_Command temp_cmd;
- if (mission.read_cmd_from_storage(0, temp_cmd)) {
- logger.Write_Mission_Cmd(mission, temp_cmd);
- }
- }
- }
-
- if (lock) {
- ahrs.lock_home();
- }
-
- return true;
- }
- bool Sub::far_from_EKF_origin(const Location& loc)
- {
-
- Location ekf_origin;
- return ahrs.get_origin(ekf_origin) && (ekf_origin.get_distance(loc) > EKF_ORIGIN_MAX_DIST_M);
- }
|