mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-21 14:37:35 +08:00
ekf2 initialization fixes
This commit is contained in:
+18
-66
@@ -40,67 +40,15 @@
|
||||
* @author Siddharth B Purohit <siddharthbharatpurohit@gmail.com>
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include "../ecl.h"
|
||||
#include "estimator_interface.h"
|
||||
|
||||
#include "../ecl.h"
|
||||
#include <math.h>
|
||||
#include "mathlib.h"
|
||||
|
||||
|
||||
EstimatorInterface::EstimatorInterface():
|
||||
_obs_buffer_length(10),
|
||||
_imu_buffer_length(30),
|
||||
_min_obs_interval_us(0),
|
||||
_dt_imu_avg(0.0f),
|
||||
_mag_sample_delayed{},
|
||||
_baro_sample_delayed{},
|
||||
_gps_sample_delayed{},
|
||||
_range_sample_delayed{},
|
||||
_airspeed_sample_delayed{},
|
||||
_flow_sample_delayed{},
|
||||
_ev_sample_delayed{},
|
||||
_drag_sample_delayed{},
|
||||
_drag_down_sampled{},
|
||||
_drag_sample_count(0),
|
||||
_drag_sample_time_dt(0.0f),
|
||||
_air_density(1.225f),
|
||||
_imu_ticks(0),
|
||||
_imu_updated(false),
|
||||
_initialised(false),
|
||||
_NED_origin_initialised(false),
|
||||
_gps_speed_valid(false),
|
||||
_gps_origin_eph(0.0f),
|
||||
_gps_origin_epv(0.0f),
|
||||
_pos_ref{},
|
||||
_gps_pos_prev{},
|
||||
_gps_alt_prev(0.0f),
|
||||
_yaw_test_ratio(0.0f),
|
||||
_mag_test_ratio{},
|
||||
_vel_pos_test_ratio{},
|
||||
_tas_test_ratio(0.0f),
|
||||
_terr_test_ratio(0.0f),
|
||||
_beta_test_ratio(0.0f),
|
||||
_drag_test_ratio{},
|
||||
_is_dead_reckoning(false),
|
||||
_vibe_metrics{},
|
||||
_time_last_imu(0),
|
||||
_time_last_gps(0),
|
||||
_time_last_mag(0),
|
||||
_time_last_baro(0),
|
||||
_time_last_range(0),
|
||||
_time_last_airspeed(0),
|
||||
_time_last_ext_vision(0),
|
||||
_time_last_optflow(0),
|
||||
_mag_declination_gps(0.0f),
|
||||
_mag_declination_to_save_deg(0.0f)
|
||||
{
|
||||
_delta_ang_prev.setZero();
|
||||
_delta_vel_prev.setZero();
|
||||
}
|
||||
|
||||
// Accumulate imu data and store to buffer at desired rate
|
||||
void EstimatorInterface::setIMUData(uint64_t time_usec, uint64_t delta_ang_dt, uint64_t delta_vel_dt, float (&delta_ang)[3],
|
||||
float (&delta_vel)[3])
|
||||
void EstimatorInterface::setIMUData(uint64_t time_usec, uint64_t delta_ang_dt, uint64_t delta_vel_dt,
|
||||
float (&delta_ang)[3], float (&delta_vel)[3])
|
||||
{
|
||||
if (!_initialised) {
|
||||
init(time_usec);
|
||||
@@ -129,7 +77,7 @@ void EstimatorInterface::setIMUData(uint64_t time_usec, uint64_t delta_ang_dt, u
|
||||
_imu_ticks++;
|
||||
|
||||
// calculate a metric which indicates the amount of coning vibration
|
||||
Vector3f temp = cross_product(imu_sample_new.delta_ang , _delta_ang_prev);
|
||||
Vector3f temp = cross_product(imu_sample_new.delta_ang, _delta_ang_prev);
|
||||
_vibe_metrics[0] = 0.99f * _vibe_metrics[0] + 0.01f * temp.norm();
|
||||
|
||||
// calculate a metric which indiates the amount of high frequency gyro vibration
|
||||
@@ -160,6 +108,7 @@ void EstimatorInterface::setIMUData(uint64_t time_usec, uint64_t delta_ang_dt, u
|
||||
|
||||
// calculate the downsample ratio for drag specific force data
|
||||
uint8_t min_sample_ratio = (uint8_t) ceilf((float)_imu_buffer_length / _obs_buffer_length);
|
||||
|
||||
if (min_sample_ratio < 5) {
|
||||
min_sample_ratio = 5;
|
||||
|
||||
@@ -189,7 +138,7 @@ void EstimatorInterface::setIMUData(uint64_t time_usec, uint64_t delta_ang_dt, u
|
||||
|
||||
// calculate the minimum interval between observations required to guarantee no loss of data
|
||||
// this will occur if data is overwritten before its time stamp falls behind the fusion time horizon
|
||||
_min_obs_interval_us = (_imu_sample_new.time_us - _imu_sample_delayed.time_us)/(_obs_buffer_length - 1);
|
||||
_min_obs_interval_us = (_imu_sample_new.time_us - _imu_sample_delayed.time_us) / (_obs_buffer_length - 1);
|
||||
|
||||
} else {
|
||||
_imu_updated = false;
|
||||
@@ -203,7 +152,7 @@ void EstimatorInterface::setMagData(uint64_t time_usec, float (&data)[3])
|
||||
if (time_usec - _time_last_mag > _min_obs_interval_us) {
|
||||
|
||||
magSample mag_sample_new = {};
|
||||
mag_sample_new.time_us = time_usec - _params.mag_delay_ms * 1000;
|
||||
mag_sample_new.time_us = time_usec - _params.mag_delay_ms * 1000;
|
||||
|
||||
mag_sample_new.time_us -= FILTER_UPDATE_PERIOD_MS * 1000 / 2;
|
||||
_time_last_mag = time_usec;
|
||||
@@ -223,6 +172,7 @@ void EstimatorInterface::setGpsData(uint64_t time_usec, struct gps_message *gps)
|
||||
|
||||
// limit data rate to prevent data being lost
|
||||
bool need_gps = (_params.fusion_mode & MASK_USE_GPS) || (_params.vdist_sensor_type == VDIST_SENSOR_GPS);
|
||||
|
||||
if (((time_usec - _time_last_gps) > _min_obs_interval_us) && need_gps && gps->fix_type > 2) {
|
||||
gpsSample gps_sample_new = {};
|
||||
gps_sample_new.time_us = gps->time_usec - _params.gps_delay_ms * 1000;
|
||||
@@ -353,6 +303,7 @@ void EstimatorInterface::setOpticalFlowData(uint64_t time_usec, flow_message *fl
|
||||
// NOTE: the EKF uses the reverse sign convention to the flow sensor. EKF assumes positive LOS rate is produced by a RH rotation of the image about the sensor axis.
|
||||
// copy the optical and gyro measured delta angles
|
||||
optflow_sample_new.gyroXYZ = - flow->gyrodata;
|
||||
|
||||
if (flow_quality_good) {
|
||||
optflow_sample_new.flowRadXY = - flow->flowdata;
|
||||
|
||||
@@ -362,6 +313,7 @@ void EstimatorInterface::setOpticalFlowData(uint64_t time_usec, flow_message *fl
|
||||
optflow_sample_new.flowRadXY(1) = + flow->gyrodata(1);
|
||||
|
||||
}
|
||||
|
||||
// compensate for body motion to give a LOS rate
|
||||
optflow_sample_new.flowRadXYcomp(0) = optflow_sample_new.flowRadXY(0) - optflow_sample_new.gyroXYZ(0);
|
||||
optflow_sample_new.flowRadXYcomp(1) = optflow_sample_new.flowRadXY(1) - optflow_sample_new.gyroXYZ(1);
|
||||
@@ -418,7 +370,7 @@ bool EstimatorInterface::initialise_interface(uint64_t timestamp)
|
||||
_obs_buffer_length = (ekf_delay_ms / _params.sensor_interval_min_ms) + 1;
|
||||
|
||||
// limit to be no longer than the IMU buffer (we can't process data faster than the EKF prediction rate)
|
||||
_obs_buffer_length = math::min(_obs_buffer_length,_imu_buffer_length);
|
||||
_obs_buffer_length = math::min(_obs_buffer_length, _imu_buffer_length);
|
||||
|
||||
if (!(_imu_buffer.allocate(_imu_buffer_length) &&
|
||||
_gps_buffer.allocate(_obs_buffer_length) &&
|
||||
@@ -436,7 +388,7 @@ bool EstimatorInterface::initialise_interface(uint64_t timestamp)
|
||||
}
|
||||
|
||||
// zero the data in the observation buffers
|
||||
for (int index=0; index < _obs_buffer_length; index++) {
|
||||
for (int index = 0; index < _obs_buffer_length; index++) {
|
||||
gpsSample gps_sample_init = {};
|
||||
_gps_buffer.push(gps_sample_init);
|
||||
magSample mag_sample_init = {};
|
||||
@@ -456,7 +408,7 @@ bool EstimatorInterface::initialise_interface(uint64_t timestamp)
|
||||
}
|
||||
|
||||
// zero the data in the imu data and output observer state buffers
|
||||
for (int index=0; index < _imu_buffer_length; index++) {
|
||||
for (int index = 0; index < _imu_buffer_length; index++) {
|
||||
imuSample imu_sample_init = {};
|
||||
_imu_buffer.push(imu_sample_init);
|
||||
outputSample output_sample_init = {};
|
||||
@@ -504,7 +456,7 @@ void EstimatorInterface::unallocate_buffers()
|
||||
bool EstimatorInterface::local_position_is_valid()
|
||||
{
|
||||
// return true if the position estimate is valid
|
||||
return (((_time_last_imu - _time_last_optflow) < 5e6) && _control_status.flags.opt_flow) ||
|
||||
(((_time_last_imu - _time_last_ext_vision) < 5e6) && _control_status.flags.ev_pos) ||
|
||||
global_position_is_valid();
|
||||
return (((_time_last_imu - _time_last_optflow) < 5e6) && _control_status.flags.opt_flow) ||
|
||||
(((_time_last_imu - _time_last_ext_vision) < 5e6) && _control_status.flags.ev_pos) ||
|
||||
global_position_is_valid();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user