2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2019-04-01 03:55:58 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2021-10-18 23:15:00 -03:00
|
|
|
#include "AP_InertialNav.h"
|
2014-01-03 07:57:50 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
A wrapper around the AP_InertialNav class which uses the NavEKF
|
|
|
|
filter if available, and falls back to the AP_InertialNav filter
|
|
|
|
when EKF is not available
|
|
|
|
*/
|
|
|
|
|
2014-01-03 20:16:07 -04:00
|
|
|
/**
|
|
|
|
update internal state
|
|
|
|
*/
|
2021-10-18 23:15:00 -03:00
|
|
|
void AP_InertialNav::update(bool high_vibes)
|
2014-01-03 20:16:07 -04:00
|
|
|
{
|
2016-07-09 08:37:35 -03:00
|
|
|
// get the NE position relative to the local earth frame origin
|
|
|
|
Vector2f posNE;
|
2017-01-30 15:09:27 -04:00
|
|
|
if (_ahrs_ekf.get_relative_position_NE_origin(posNE)) {
|
2016-07-09 08:37:35 -03:00
|
|
|
_relpos_cm.x = posNE.x * 100; // convert from m to cm
|
|
|
|
_relpos_cm.y = posNE.y * 100; // convert from m to cm
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the D position relative to the local earth frame origin
|
|
|
|
float posD;
|
2017-01-30 15:09:27 -04:00
|
|
|
if (_ahrs_ekf.get_relative_position_D_origin(posD)) {
|
2016-07-09 08:37:35 -03:00
|
|
|
_relpos_cm.z = - posD * 100; // convert from m in NED to cm in NEU
|
2016-03-01 14:05:59 -04:00
|
|
|
}
|
2014-02-08 22:57:08 -04:00
|
|
|
|
2015-10-12 09:13:32 -03:00
|
|
|
// get the velocity relative to the local earth frame
|
2016-07-09 08:37:35 -03:00
|
|
|
Vector3f velNED;
|
2023-11-06 18:25:35 -04:00
|
|
|
|
2023-10-25 19:50:02 -03:00
|
|
|
const bool velned_ok = _ahrs_ekf.get_velocity_NED(velNED);
|
2023-11-06 18:25:35 -04:00
|
|
|
if (velned_ok) {
|
|
|
|
_velocity_cm = velNED * 100; // convert to cm/s
|
|
|
|
_velocity_cm.z = -_velocity_cm.z; // convert from NED to NEU
|
|
|
|
}
|
|
|
|
// During high vibration events, or failure of get_velocity_NED, use the
|
|
|
|
// fallback vertical velocity estimate. For get_velocity_NED failure, freeze
|
|
|
|
// the horizontal velocity at the last good value.
|
2023-10-25 19:50:02 -03:00
|
|
|
if (!velned_ok || high_vibes) {
|
|
|
|
float rate_z;
|
|
|
|
if (_ahrs_ekf.get_vert_pos_rate_D(rate_z)) {
|
2023-11-06 18:25:35 -04:00
|
|
|
_velocity_cm.z = -rate_z * 100; // convert from m/s in NED to cm/s in NEU
|
2019-04-01 03:55:58 -03:00
|
|
|
}
|
2016-03-01 14:05:59 -04:00
|
|
|
}
|
2014-01-03 20:16:07 -04:00
|
|
|
}
|
|
|
|
|
2014-01-03 07:57:50 -04:00
|
|
|
/**
|
2015-01-02 04:06:22 -04:00
|
|
|
* get_filter_status : returns filter status as a series of flags
|
2014-01-03 07:57:50 -04:00
|
|
|
*/
|
2021-10-18 23:15:00 -03:00
|
|
|
nav_filter_status AP_InertialNav::get_filter_status() const
|
2014-01-03 07:57:50 -04:00
|
|
|
{
|
2015-10-12 09:13:32 -03:00
|
|
|
nav_filter_status status;
|
|
|
|
_ahrs_ekf.get_filter_status(status);
|
|
|
|
return status;
|
2014-01-03 07:57:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-02 01:26:14 -04:00
|
|
|
* get_position_neu_cm - returns the current position relative to the EKF origin in cm.
|
2014-01-03 07:57:50 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2021-10-20 05:33:14 -03:00
|
|
|
const Vector3f &AP_InertialNav::get_position_neu_cm(void) const
|
2014-01-03 07:57:50 -04:00
|
|
|
{
|
2015-03-12 10:22:54 -03:00
|
|
|
return _relpos_cm;
|
2014-01-03 07:57:50 -04:00
|
|
|
}
|
|
|
|
|
2021-09-11 05:40:29 -03:00
|
|
|
/**
|
2022-02-02 01:26:14 -04:00
|
|
|
* get_position_xy_cm - returns the current x-y position relative to the EKF origin in cm.
|
2021-09-11 05:40:29 -03:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2021-10-20 05:33:14 -03:00
|
|
|
const Vector2f &AP_InertialNav::get_position_xy_cm() const
|
2021-09-11 05:40:29 -03:00
|
|
|
{
|
|
|
|
return _relpos_cm.xy();
|
|
|
|
}
|
|
|
|
|
2014-01-03 07:57:50 -04:00
|
|
|
/**
|
2022-02-02 01:26:14 -04:00
|
|
|
* get_position_z_up_cm - returns the current z position relative to the EKF origin, frame z-axis up, in cm.
|
2021-10-20 05:33:14 -03:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
float AP_InertialNav::get_position_z_up_cm() const
|
|
|
|
{
|
|
|
|
return _relpos_cm.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_velocity_neu_cms - returns the current velocity in cm/s
|
2014-01-03 07:57:50 -04:00
|
|
|
*
|
|
|
|
* @return velocity vector:
|
|
|
|
* .x : latitude velocity in cm/s
|
|
|
|
* .y : longitude velocity in cm/s
|
|
|
|
* .z : vertical velocity in cm/s
|
|
|
|
*/
|
2021-10-20 05:33:14 -03:00
|
|
|
const Vector3f &AP_InertialNav::get_velocity_neu_cms() const
|
2014-01-03 07:57:50 -04:00
|
|
|
{
|
2015-03-12 10:22:54 -03:00
|
|
|
return _velocity_cm;
|
2014-01-03 07:57:50 -04:00
|
|
|
}
|
|
|
|
|
2021-09-11 05:40:29 -03:00
|
|
|
/**
|
2022-02-02 01:26:14 -04:00
|
|
|
* get_velocity_xy_cms - returns the current x-y velocity relative to the EKF origin in cm.
|
2021-09-11 05:40:29 -03:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2021-10-20 05:33:14 -03:00
|
|
|
const Vector2f &AP_InertialNav::get_velocity_xy_cms() const
|
2021-09-11 05:40:29 -03:00
|
|
|
{
|
|
|
|
return _velocity_cm.xy();
|
|
|
|
}
|
|
|
|
|
2014-01-03 07:57:50 -04:00
|
|
|
/**
|
2021-10-20 05:33:14 -03:00
|
|
|
* get_speed_xy_cms - returns the current horizontal speed in cm/s
|
2014-01-03 07:57:50 -04:00
|
|
|
*
|
2017-10-13 00:42:49 -03:00
|
|
|
* @returns the current horizontal speed in cm/s
|
2014-01-03 07:57:50 -04:00
|
|
|
*/
|
2021-10-20 05:33:14 -03:00
|
|
|
float AP_InertialNav::get_speed_xy_cms() const
|
2014-01-03 07:57:50 -04:00
|
|
|
{
|
2021-09-11 07:32:32 -03:00
|
|
|
return _velocity_cm.xy().length();
|
2014-01-03 07:57:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-20 05:33:14 -03:00
|
|
|
* get_velocity_z_up_cms - returns the current z-axis velocity, frame z-axis up, in cm/s
|
2014-01-03 07:57:50 -04:00
|
|
|
*
|
2021-10-20 05:33:14 -03:00
|
|
|
* @return z-axis velocity, frame z-axis up, in cm/s
|
2014-01-03 07:57:50 -04:00
|
|
|
*/
|
2021-10-20 05:33:14 -03:00
|
|
|
float AP_InertialNav::get_velocity_z_up_cms() const
|
2014-01-03 07:57:50 -04:00
|
|
|
{
|
2015-03-12 10:22:54 -03:00
|
|
|
return _velocity_cm.z;
|
2014-01-03 07:57:50 -04:00
|
|
|
}
|