Skip to content

Commit e64753b

Browse files
committed
[NAV] Add accelerometer weight so it could be disabled for the estimator if necessary
1 parent c13d1ec commit e64753b

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

src/main/fc/settings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,10 @@ groups:
12061206
field: w_xy_res_v
12071207
min: 0
12081208
max: 10
1209+
- name: inav_w_xyz_acc_p
1210+
field: w_xyz_acc_p
1211+
min: 0
1212+
max: 1
12091213
- name: inav_w_acc_bias
12101214
field: w_acc_bias
12111215
min: 0

src/main/navigation/navigation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ typedef struct positionEstimationConfig_s {
114114
float w_xy_res_v;
115115

116116
float w_acc_bias; // Weight (cutoff frequency) for accelerometer bias estimation. 0 to disable.
117+
float w_xyz_acc_p;
117118

118119
float max_eph_epv; // Max estimated position error acceptable for estimation (cm)
119120
float baro_epv; // Baro position error

src/main/navigation/navigation_pos_estimator.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
navigationPosEstimator_t posEstimator;
5555

56-
PG_REGISTER_WITH_RESET_TEMPLATE(positionEstimationConfig_t, positionEstimationConfig, PG_POSITION_ESTIMATION_CONFIG, 3);
56+
PG_REGISTER_WITH_RESET_TEMPLATE(positionEstimationConfig_t, positionEstimationConfig, PG_POSITION_ESTIMATION_CONFIG, 4);
5757

5858
PG_RESET_TEMPLATE(positionEstimationConfig_t, positionEstimationConfig,
5959
// Inertial position estimator parameters
@@ -66,6 +66,8 @@ PG_RESET_TEMPLATE(positionEstimationConfig_t, positionEstimationConfig,
6666

6767
.max_surface_altitude = 200,
6868

69+
.w_xyz_acc_p = 1.0f,
70+
6971
.w_z_baro_p = 0.35f,
7072

7173
.w_z_surface_p = 3.500f,
@@ -433,6 +435,12 @@ static bool navIsHeadingUsable(void)
433435
}
434436
}
435437

438+
float navGetAccelerometerWeight(void)
439+
{
440+
// TODO(digitalentity): consider accelerometer health in weight calculation
441+
return positionEstimationConfig()->w_xyz_acc_p;
442+
}
443+
436444
static uint32_t calculateCurrentValidityFlags(timeUs_t currentTimeUs)
437445
{
438446
/* Figure out if we have valid position data from our data sources */
@@ -474,11 +482,13 @@ static uint32_t calculateCurrentValidityFlags(timeUs_t currentTimeUs)
474482

475483
static void estimationPredict(estimationContext_t * ctx)
476484
{
485+
const float accWeight = navGetAccelerometerWeight();
486+
477487
/* Prediction step: Z-axis */
478488
if ((ctx->newFlags & EST_Z_VALID)) {
479489
posEstimator.est.pos.z += posEstimator.est.vel.z * ctx->dt;
480-
posEstimator.est.pos.z += posEstimator.imu.accelNEU.z * sq(ctx->dt) / 2.0f;
481-
posEstimator.est.vel.z += posEstimator.imu.accelNEU.z * ctx->dt;
490+
posEstimator.est.pos.z += posEstimator.imu.accelNEU.z * sq(ctx->dt) / 2.0f * accWeight;
491+
posEstimator.est.vel.z += posEstimator.imu.accelNEU.z * ctx->dt * sq(accWeight);
482492
}
483493

484494
/* Prediction step: XY-axis */
@@ -489,10 +499,10 @@ static void estimationPredict(estimationContext_t * ctx)
489499

490500
// If heading is valid, accelNEU is valid as well. Account for acceleration
491501
if (navIsHeadingUsable() && navIsAccelerationUsable()) {
492-
posEstimator.est.pos.x += posEstimator.imu.accelNEU.x * sq(ctx->dt) / 2.0f;
493-
posEstimator.est.pos.y += posEstimator.imu.accelNEU.y * sq(ctx->dt) / 2.0f;
494-
posEstimator.est.vel.x += posEstimator.imu.accelNEU.x * ctx->dt;
495-
posEstimator.est.vel.y += posEstimator.imu.accelNEU.y * ctx->dt;
502+
posEstimator.est.pos.x += posEstimator.imu.accelNEU.x * sq(ctx->dt) / 2.0f * accWeight;
503+
posEstimator.est.pos.y += posEstimator.imu.accelNEU.y * sq(ctx->dt) / 2.0f * accWeight;
504+
posEstimator.est.vel.x += posEstimator.imu.accelNEU.x * ctx->dt * sq(accWeight);
505+
posEstimator.est.vel.y += posEstimator.imu.accelNEU.y * ctx->dt * sq(accWeight);
496506
}
497507
}
498508
}

src/main/navigation/navigation_pos_estimator_agl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ void estimationCalculateAGL(estimationContext_t * ctx)
149149
}
150150

151151
// Update estimate
152+
const float accWeight = navGetAccelerometerWeight();
152153
posEstimator.est.aglAlt += posEstimator.est.aglVel * ctx->dt;
153-
posEstimator.est.aglAlt += posEstimator.imu.accelNEU.z * sq(ctx->dt) / 2.0f;
154-
posEstimator.est.aglVel += posEstimator.imu.accelNEU.z * ctx->dt;
154+
posEstimator.est.aglAlt += posEstimator.imu.accelNEU.z * sq(ctx->dt) / 2.0f * accWeight;
155+
posEstimator.est.aglVel += posEstimator.imu.accelNEU.z * ctx->dt * sq(accWeight);
155156

156157
// Apply correction
157158
if (posEstimator.est.aglQual == SURFACE_QUAL_HIGH) {

src/main/navigation/navigation_pos_estimator_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,5 @@ typedef struct {
182182
extern float updateEPE(const float oldEPE, const float dt, const float newEPE, const float w);
183183
extern void estimationCalculateAGL(estimationContext_t * ctx);
184184
extern bool estimationCalculateCorrection_XY_FLOW(estimationContext_t * ctx);
185-
185+
extern float navGetAccelerometerWeight(void);
186186

0 commit comments

Comments
 (0)