CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Blimp/commands.cpp
Views: 1798
1
#include "Blimp.h"
2
3
// checks if we should update ahrs/RTL home position from the EKF
4
void Blimp::update_home_from_EKF()
5
{
6
// exit immediately if home already set
7
if (ahrs.home_is_set()) {
8
return;
9
}
10
11
// special logic if home is set in-flight
12
if (motors->armed()) {
13
set_home_to_current_location_inflight();
14
} else {
15
// move home to current ekf location (this will set home_state to HOME_SET)
16
if (!set_home_to_current_location(false)) {
17
// ignore failure
18
}
19
}
20
}
21
22
// set_home_to_current_location_inflight - set home to current GPS location (horizontally) and EKF origin vertically
23
void Blimp::set_home_to_current_location_inflight()
24
{
25
// get current location from EKF
26
Location temp_loc;
27
Location ekf_origin;
28
if (ahrs.get_location(temp_loc) && ahrs.get_origin(ekf_origin)) {
29
temp_loc.alt = ekf_origin.alt;
30
if (!set_home(temp_loc, false)) {
31
return;
32
}
33
}
34
}
35
36
// set_home_to_current_location - set home to current GPS location
37
bool Blimp::set_home_to_current_location(bool lock)
38
{
39
// get current location from EKF
40
Location temp_loc;
41
if (ahrs.get_location(temp_loc)) {
42
if (!set_home(temp_loc, lock)) {
43
return false;
44
}
45
return true;
46
}
47
return false;
48
}
49
50
// set_home - sets ahrs home (used for RTL) to specified location
51
// initialises inertial nav and compass on first call
52
// returns true if home location set successfully
53
bool Blimp::set_home(const Location& loc, bool lock)
54
{
55
// check EKF origin has been set
56
Location ekf_origin;
57
if (!ahrs.get_origin(ekf_origin)) {
58
return false;
59
}
60
61
// set ahrs home (used for RTL)
62
if (!ahrs.set_home(loc)) {
63
return false;
64
}
65
66
// lock home position
67
if (lock) {
68
ahrs.lock_home();
69
}
70
71
// return success
72
return true;
73
}
74
75