Skip to content

Commit 39ba8a8

Browse files
committed
AP_NavEKF2: convert to using common buffer classes
this saves a considerable amount of flash
1 parent e4a9497 commit 39ba8a8

File tree

3 files changed

+31
-239
lines changed

3 files changed

+31
-239
lines changed

libraries/AP_NavEKF2/AP_NavEKF2_Buffer.h

Lines changed: 0 additions & 199 deletions
This file was deleted.

libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void NavEKF2_core::readIMUData()
447447
runUpdates = true;
448448

449449
// extract the oldest available data from the FIFO buffer
450-
imuDataDelayed = storedIMU.pop_oldest_element();
450+
imuDataDelayed = storedIMU.get_oldest_element();
451451

452452
// protect against delta time going to zero
453453
// TODO - check if calculations can tolerate 0

libraries/AP_NavEKF2/AP_NavEKF2_core.h

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <AP_Math/AP_Math.h>
2929
#include <AP_Math/vectorN.h>
3030
#include <AP_NavEKF/AP_NavEKF_core_common.h>
31-
#include <AP_NavEKF2/AP_NavEKF2_Buffer.h>
31+
#include <AP_NavEKF/EKF_Buffer.h>
3232
#include <GCS_MAVLink/GCS_MAVLink.h>
3333
#include <AP_DAL/AP_DAL.h>
3434

@@ -462,57 +462,49 @@ class NavEKF2_core : public NavEKF_core_common
462462
uint8_t accel_index;
463463
};
464464

465-
struct gps_elements {
466-
Vector2f pos; // 0..1
467-
float hgt; // 2
468-
Vector3f vel; // 3..5
469-
uint32_t time_ms; // 6
470-
uint8_t sensor_idx; // 7..9
465+
struct gps_elements : EKF_obs_element_t {
466+
Vector2f pos;
467+
float hgt;
468+
Vector3f vel;
469+
uint8_t sensor_idx;
471470
};
472471

473-
struct mag_elements {
474-
Vector3f mag; // 0..2
475-
uint32_t time_ms; // 3
472+
struct mag_elements : EKF_obs_element_t {
473+
Vector3f mag;
476474
};
477475

478-
struct baro_elements {
479-
float hgt; // 0
480-
uint32_t time_ms; // 1
476+
struct baro_elements : EKF_obs_element_t {
477+
float hgt;
481478
};
482479

483-
struct range_elements {
484-
float rng; // 0
485-
uint32_t time_ms; // 1
486-
uint8_t sensor_idx; // 2
480+
struct range_elements : EKF_obs_element_t {
481+
float rng;
482+
uint8_t sensor_idx;
487483
};
488484

489-
struct rng_bcn_elements {
485+
struct rng_bcn_elements : EKF_obs_element_t {
490486
float rng; // range measurement to each beacon (m)
491487
Vector3f beacon_posNED; // NED position of the beacon (m)
492488
float rngErr; // range measurement error 1-std (m)
493489
uint8_t beacon_ID; // beacon identification number
494-
uint32_t time_ms; // measurement timestamp (msec)
495490
};
496491

497-
struct tas_elements {
498-
float tas; // 0
499-
uint32_t time_ms; // 1
492+
struct tas_elements : EKF_obs_element_t {
493+
float tas;
500494
};
501495

502-
struct of_elements {
496+
struct of_elements : EKF_obs_element_t {
503497
Vector2f flowRadXY;
504498
Vector2f flowRadXYcomp;
505-
uint32_t time_ms;
506499
Vector3f bodyRadXYZ;
507500
Vector3f body_offset;
508501
};
509502

510-
struct ext_nav_elements {
503+
struct ext_nav_elements : EKF_obs_element_t {
511504
Vector3f pos; // XYZ position measured in a RH navigation frame (m)
512505
Quaternion quat; // quaternion describing the rotation from navigation to body frame
513506
float posErr; // spherical poition measurement error 1-std (m)
514507
float angErr; // spherical angular measurement error 1-std (rad)
515-
uint32_t time_ms; // measurement timestamp (msec)
516508
bool posReset; // true when the position measurement has been reset
517509
};
518510

@@ -524,10 +516,9 @@ class NavEKF2_core : public NavEKF_core_common
524516
float accel_zbias;
525517
} inactiveBias[INS_MAX_INSTANCES];
526518

527-
struct ext_nav_vel_elements {
519+
struct ext_nav_vel_elements : EKF_obs_element_t {
528520
Vector3f vel; // velocity in NED (m)
529521
float err; // velocity measurement error (m/s)
530-
uint32_t time_ms; // measurement timestamp (msec)
531522
};
532523

533524
// update the navigation filter status
@@ -841,13 +832,13 @@ class NavEKF2_core : public NavEKF_core_common
841832

842833
float gpsNoiseScaler; // Used to scale the GPS measurement noise and consistency gates to compensate for operation with small satellite counts
843834
Matrix24 P; // covariance matrix
844-
imu_ring_buffer_t<imu_elements> storedIMU; // IMU data buffer
845-
obs_ring_buffer_t<gps_elements> storedGPS; // GPS data buffer
846-
obs_ring_buffer_t<mag_elements> storedMag; // Magnetometer data buffer
847-
obs_ring_buffer_t<baro_elements> storedBaro; // Baro data buffer
848-
obs_ring_buffer_t<tas_elements> storedTAS; // TAS data buffer
849-
obs_ring_buffer_t<range_elements> storedRange; // Range finder data buffer
850-
imu_ring_buffer_t<output_elements> storedOutput;// output state buffer
835+
EKF_IMU_buffer_t<imu_elements> storedIMU; // IMU data buffer
836+
EKF_obs_buffer_t<gps_elements> storedGPS; // GPS data buffer
837+
EKF_obs_buffer_t<mag_elements> storedMag; // Magnetometer data buffer
838+
EKF_obs_buffer_t<baro_elements> storedBaro; // Baro data buffer
839+
EKF_obs_buffer_t<tas_elements> storedTAS; // TAS data buffer
840+
EKF_obs_buffer_t<range_elements> storedRange; // Range finder data buffer
841+
EKF_IMU_buffer_t<output_elements> storedOutput;// output state buffer
851842
Matrix3f prevTnb; // previous nav to body transformation used for INS earth rotation compensation
852843
ftype accNavMag; // magnitude of navigation accel - used to adjust GPS obs variance (m/s^2)
853844
ftype accNavMagHoriz; // magnitude of navigation accel in horizontal plane (m/s^2)
@@ -1015,7 +1006,7 @@ class NavEKF2_core : public NavEKF_core_common
10151006
bool gpsAccuracyGood; // true when the GPS accuracy is considered to be good enough for safe flight.
10161007

10171008
// variables added for optical flow fusion
1018-
obs_ring_buffer_t<of_elements> storedOF; // OF data buffer
1009+
EKF_obs_buffer_t<of_elements> storedOF; // OF data buffer
10191010
of_elements ofDataNew; // OF data at the current time horizon
10201011
of_elements ofDataDelayed; // OF data at the fusion time horizon
10211012
bool flowDataToFuse; // true when optical flow data is ready for fusion
@@ -1069,7 +1060,7 @@ class NavEKF2_core : public NavEKF_core_common
10691060
bool terrainHgtStable; // true when the terrain height is stable enough to be used as a height reference
10701061

10711062
// Range Beacon Sensor Fusion
1072-
obs_ring_buffer_t<rng_bcn_elements> storedRangeBeacon; // Beacon range buffer
1063+
EKF_obs_buffer_t<rng_bcn_elements> storedRangeBeacon; // Beacon range buffer
10731064
rng_bcn_elements rngBcnDataNew; // Range beacon data at the current time horizon
10741065
rng_bcn_elements rngBcnDataDelayed; // Range beacon data at the fusion time horizon
10751066
uint32_t lastRngBcnPassTime_ms; // time stamp when the range beacon measurement last passed innvovation consistency checks (msec)
@@ -1143,7 +1134,7 @@ class NavEKF2_core : public NavEKF_core_common
11431134
uint8_t magYawAnomallyCount; // Number of times the yaw has been reset due to a magnetic anomaly during initial ascent
11441135

11451136
// external navigation fusion
1146-
obs_ring_buffer_t<ext_nav_elements> storedExtNav; // external navigation data buffer
1137+
EKF_obs_buffer_t<ext_nav_elements> storedExtNav; // external navigation data buffer
11471138
ext_nav_elements extNavDataNew; // External nav data at the current time horizon
11481139
ext_nav_elements extNavDataDelayed; // External nav at the fusion time horizon
11491140
uint32_t extNavMeasTime_ms; // time external measurements were accepted for input to the data buffer (msec)
@@ -1154,7 +1145,7 @@ class NavEKF2_core : public NavEKF_core_common
11541145
bool extNavUsedForPos; // true when the external nav data is being used as a position reference.
11551146
bool extNavYawResetRequest; // true when a reset of vehicle yaw using the external nav data is requested
11561147

1157-
obs_ring_buffer_t<ext_nav_vel_elements> storedExtNavVel; // external navigation velocity data buffer
1148+
EKF_obs_buffer_t<ext_nav_vel_elements> storedExtNavVel; // external navigation velocity data buffer
11581149
ext_nav_vel_elements extNavVelNew; // external navigation velocity data at the current time horizon
11591150
ext_nav_vel_elements extNavVelDelayed; // external navigation velocity data at the fusion time horizon
11601151
uint32_t extNavVelMeasTime_ms; // time external navigation velocity measurements were accepted for input to the data buffer (msec)

0 commit comments

Comments
 (0)