Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Rover/commands.cpp
9377 views
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
// send text of home position to ground stations
33
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Set HOME to %.6f %.6f at %.2fm",
34
static_cast<double>(loc.lat * 1.0e-7f),
35
static_cast<double>(loc.lng * 1.0e-7f),
36
static_cast<double>(loc.alt * 0.01f));
37
38
// return success
39
return true;
40
}
41
42
// called periodically while disarmed to update our home position to
43
// our current location
44
void Rover::update_home()
45
{
46
if (ahrs.home_is_locked()) {
47
// we've been explicitly told our home location
48
return;
49
}
50
51
Location loc{};
52
if (!ahrs.get_location(loc)) {
53
return;
54
}
55
56
barometer.update_calibration();
57
58
if (ahrs.home_is_set() &&
59
loc.get_distance(ahrs.get_home()) < DISTANCE_HOME_MINCHANGE) {
60
// insufficiently moved from current home - don't change it
61
return;
62
}
63
64
IGNORE_RETURN(ahrs.set_home(loc));
65
}
66
67