APM:Libraries
AP_InertialNav_NavEKF.cpp
Go to the documentation of this file.
1 #include <AP_HAL/AP_HAL.h>
2 #include "AP_InertialNav.h"
3 
4 #if AP_AHRS_NAVEKF_AVAILABLE
5 
6 /*
7  A wrapper around the AP_InertialNav class which uses the NavEKF
8  filter if available, and falls back to the AP_InertialNav filter
9  when EKF is not available
10  */
11 
15 void AP_InertialNav_NavEKF::update(float dt)
16 {
17  // get the NE position relative to the local earth frame origin
18  Vector2f posNE;
20  _relpos_cm.x = posNE.x * 100; // convert from m to cm
21  _relpos_cm.y = posNE.y * 100; // convert from m to cm
22  }
23 
24  // get the D position relative to the local earth frame origin
25  float posD;
27  _relpos_cm.z = - posD * 100; // convert from m in NED to cm in NEU
28  }
29 
30  // get the absolute WGS-84 position
32 
33  // get the velocity relative to the local earth frame
34  Vector3f velNED;
35  if (_ahrs_ekf.get_velocity_NED(velNED)) {
36  _velocity_cm = velNED * 100; // convert to cm/s
37  _velocity_cm.z = -_velocity_cm.z; // convert from NED to NEU
38  }
39 
40  // Get a derivative of the vertical position which is kinematically consistent with the vertical position is required by some control loops.
41  // This is different to the vertical velocity from the EKF which is not always consistent with the vertical position due to the various errors that are being corrected for.
43  _pos_z_rate *= 100; // convert to cm/s
44  _pos_z_rate = - _pos_z_rate; // InertialNav is NEU
45  }
46 }
47 
52 {
53  nav_filter_status status;
55  return status;
56 }
57 
62 {
63  struct Location ret;
64  if (!_ahrs_ekf.get_origin(ret)) {
65  // initialise location to all zeros if EKF origin not yet set
66  memset(&ret, 0, sizeof(ret));
67  }
68  return ret;
69 }
70 
77 {
78  return _relpos_cm;
79 }
80 
85 bool AP_InertialNav_NavEKF::get_location(struct Location &loc) const
86 {
87  return _ahrs_ekf.get_location(loc);
88 }
89 
94 {
95  return _abspos.lat;
96 }
97 
103 {
104  return _abspos.lng;
105 }
106 
116 {
117  return _velocity_cm;
118 }
119 
126 {
127  return norm(_velocity_cm.x, _velocity_cm.y);
128 }
129 
134 {
135  return _pos_z_rate;
136 }
137 
143 {
144  return _relpos_cm.z;
145 }
146 
155 {
156  return _velocity_cm.z;
157 }
158 
159 #endif // AP_AHRS_NAVEKF_AVAILABLE
float norm(const T first, const U second, const Params... parameters)
Definition: AP_Math.h:190
bool get_relative_position_D_origin(float &posD) const override
float get_velocity_z() const
float get_altitude() const
struct Location get_origin() const
bool get_filter_status(nav_filter_status &status) const
float get_pos_z_derivative() const
bool get_location(struct Location &loc) const
int32_t lat
param 3 - Latitude * 10**7
Definition: AP_Common.h:143
const Vector3f & get_position() const
bool get_origin(Location &ret) const override
T y
Definition: vector2.h:37
const Vector3f & get_velocity() const
nav_filter_status get_filter_status() const
int32_t get_latitude() const
T y
Definition: vector3.h:67
T z
Definition: vector3.h:67
bool get_position(struct Location &loc) const override
bool get_relative_position_NE_origin(Vector2f &posNE) const override
bool get_vert_pos_rate(float &velocity) const
T x
Definition: vector2.h:37
int32_t lng
param 4 - Longitude * 10**7
Definition: AP_Common.h:144
void update(float dt)
float get_velocity_xy() const
int32_t get_longitude() const
bool get_velocity_NED(Vector3f &vec) const override
T x
Definition: vector3.h:67
bool get_location(struct Location &loc) const