Skip to content

Commit

Permalink
[ahrs] add filter on accel heuristic of DCM AHRS
Browse files Browse the repository at this point in the history
the same filter is already applied in the int_quat ahrs and can prevent
incorrect measurement rejection when strong structural vibrations
increase the IMU noise
  • Loading branch information
gautierhattenberger authored and fvantienen committed Jun 30, 2019
1 parent 9c6bcf9 commit 02a5d39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/modules/ahrs_float_dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<configure name="AHRS_ALIGNER_LED" value="1" description="LED number to indicate AHRS alignment, none to disable (default is board dependent)"/>
<define name="USE_MAGNETOMETER_ONGROUND" description="use magnetic compensation before takeoff only while GPS course not good"/>
<define name="USE_AHRS_GPS_ACCELERATIONS" description="enable forward acceleration compensation from GPS speed"/>
<define name="ACCEL_WEIGHT_FILTER" value="8" description="adjust accel drift heuristic filter (default 8, 0 to disable filter)"/>
</doc>

<settings>
Expand Down
13 changes: 12 additions & 1 deletion sw/airborne/subsystems/ahrs/ahrs_float_dcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,18 @@ void Normalize(void)
}
}

// strong structural vibrations can prevent to perform the drift correction
// so accel magnitude is filtered before computing the weighting heuristic
#ifndef ACCEL_WEIGHT_FILTER
#define ACCEL_WEIGHT_FILTER 8
#endif

void Drift_correction()
{
//Compensation the Roll, Pitch and Yaw drift.
static float Scaled_Omega_P[3];
static float Scaled_Omega_I[3];
static float Accel_filtered = 0.f;
float Accel_magnitude;
float Accel_weight;
float Integrator_magnitude;
Expand All @@ -377,9 +383,14 @@ void Drift_correction()
// Calculate the magnitude of the accelerometer vector
Accel_magnitude = sqrtf(accel_float.x * accel_float.x + accel_float.y * accel_float.y + accel_float.z * accel_float.z);
Accel_magnitude = Accel_magnitude / GRAVITY; // Scale to gravity.
#if ACCEL_WEIGHT_FILTER
Accel_filtered = (Accel_magnitude + (ACCEL_WEIGHT_FILTER - 1) * Accel_filtered) / ACCEL_WEIGHT_FILTER;
#else // set ACCEL_WEIGHT_FILTER to 0 to disable filter
Accel_filtered = Accel_magnitude;
#endif
// Dynamic weighting of accelerometer info (reliability filter)
// Weight for accelerometer info (<0.5G = 0.0, 1G = 1.0 , >1.5G = 0.0)
Accel_weight = Clip(1 - 2 * fabsf(1 - Accel_magnitude), 0, 1); //
Accel_weight = Clip(1.f - 2.f * fabsf(1.f - Accel_filtered), 0.f, 1.f);


#if PERFORMANCE_REPORTING == 1
Expand Down

0 comments on commit 02a5d39

Please sign in to comment.