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/Rover/commands.cpp
Views: 1798
1
#include "Rover.h"
2
3
// set ahrs home to current location from inertial-nav location
4
bool Rover::set_home_to_current_location(bool lock)
5
{
6
Location temp_loc;
7
if (ahrs.have_inertial_nav() && ahrs.get_location(temp_loc)) {
8
if (!set_home(temp_loc, lock)) {
9
return false;
10
}
11
// we have successfully set AHRS home, set it for SmartRTL
12
g2.smart_rtl.set_home(true);
13
return true;
14
}
15
return false;
16
}
17
18
// sets ahrs home to specified location
19
// returns true if home location set successfully
20
bool Rover::set_home(const Location& loc, bool lock)
21
{
22
// set ahrs home
23
if (!ahrs.set_home(loc)) {
24
return false;
25
}
26
27
// lock home position
28
if (lock) {
29
ahrs.lock_home();
30
}
31
32
// Save Home to EEPROM
33
mode_auto.mission.write_home_to_storage();
34
35
// send text of home position to ground stations
36
gcs().send_text(MAV_SEVERITY_INFO, "Set HOME to %.6f %.6f at %.2fm",
37
static_cast<double>(loc.lat * 1.0e-7f),
38
static_cast<double>(loc.lng * 1.0e-7f),
39
static_cast<double>(loc.alt * 0.01f));
40
41
// return success
42
return true;
43
}
44
45
// called periodically while disarmed to update our home position to
46
// our current location
47
void Rover::update_home()
48
{
49
if (ahrs.home_is_locked()) {
50
// we've been explicitly told our home location
51
return;
52
}
53
54
Location loc{};
55
if (!ahrs.get_location(loc)) {
56
return;
57
}
58
59
barometer.update_calibration();
60
61
if (ahrs.home_is_set() &&
62
loc.get_distance(ahrs.get_home()) < DISTANCE_HOME_MINCHANGE) {
63
// insufficiently moved from current home - don't change it
64
return;
65
}
66
67
IGNORE_RETURN(ahrs.set_home(loc));
68
}
69
70