2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2012-11-07 06:03:30 -04:00
|
|
|
// read_inertia - read inertia in from accelerometers
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::read_inertia()
|
2012-06-26 02:17:04 -03:00
|
|
|
{
|
2019-03-21 06:51:35 -03:00
|
|
|
// inertial altitude estimates. Use barometer climb rate during high vibrations
|
|
|
|
inertial_nav.update(vibration_check.high_vibes);
|
2013-02-01 23:00:09 -04:00
|
|
|
|
2019-06-28 10:55:36 -03:00
|
|
|
// pull position from ahrs
|
|
|
|
Location loc;
|
2022-01-20 19:42:41 -04:00
|
|
|
ahrs.get_location(loc);
|
2019-06-28 10:55:36 -03:00
|
|
|
current_loc.lat = loc.lat;
|
|
|
|
current_loc.lng = loc.lng;
|
2016-04-19 04:16:06 -03:00
|
|
|
|
2015-05-13 03:24:52 -03:00
|
|
|
// exit immediately if we do not have an altitude estimate
|
|
|
|
if (!inertial_nav.get_filter_status().flags.vert_pos) {
|
2015-02-26 01:17:02 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-01 03:55:28 -04:00
|
|
|
// current_loc.alt is alt-above-home, converted from inertial nav's alt-above-ekf-origin
|
2021-10-20 05:29:57 -03:00
|
|
|
const int32_t alt_above_origin_cm = inertial_nav.get_position_z_up_cm();
|
2020-02-01 03:55:28 -04:00
|
|
|
current_loc.set_alt_cm(alt_above_origin_cm, Location::AltFrame::ABOVE_ORIGIN);
|
2020-02-05 02:25:43 -04:00
|
|
|
if (!ahrs.home_is_set() || !current_loc.change_alt_frame(Location::AltFrame::ABOVE_HOME)) {
|
2020-02-01 03:55:28 -04:00
|
|
|
// if home has not been set yet we treat alt-above-origin as alt-above-home
|
|
|
|
current_loc.set_alt_cm(alt_above_origin_cm, Location::AltFrame::ABOVE_HOME);
|
2015-05-13 03:24:52 -03:00
|
|
|
}
|
2013-04-23 10:03:34 -03:00
|
|
|
}
|