Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduCopter/inertia.cpp
9492 views
1
#include "Copter.h"
2
3
// read_inertia - read inertia in from accelerometers
4
void Copter::read_inertia()
5
{
6
// inertial altitude estimates. Use barometer climb rate during high vibrations
7
pos_control->update_estimates(vibration_check.high_vibes);
8
#if MODE_FOLLOW_ENABLED
9
g2.follow.update_estimates();
10
#endif
11
12
// pull position from ahrs
13
Location loc;
14
ahrs.get_location(loc);
15
current_loc.lat = loc.lat;
16
current_loc.lng = loc.lng;
17
18
// exit immediately if we do not have an altitude estimate
19
float pos_d_m;
20
if (!AP::ahrs().get_relative_position_D_origin_float(pos_d_m)) {
21
return;
22
}
23
24
// current_loc.alt is alt-above-home, converted from AHRS's alt-above-ekf-origin
25
const float alt_above_origin_m = -pos_d_m;
26
current_loc.set_alt_m(alt_above_origin_m, Location::AltFrame::ABOVE_ORIGIN);
27
if (!ahrs.home_is_set() || !current_loc.change_alt_frame(Location::AltFrame::ABOVE_HOME)) {
28
// if home has not been set yet we treat alt-above-origin as alt-above-home
29
current_loc.set_alt_m(alt_above_origin_m, Location::AltFrame::ABOVE_HOME);
30
}
31
}
32
33