Skip to content

Commit

Permalink
Merge pull request #1037 from bitcraze/krichardsson/issue-1014
Browse files Browse the repository at this point in the history
Kalman: only initialise param vars one time
  • Loading branch information
krichardsson authored May 9, 2022
2 parents 06c2746 + 36e21a1 commit 52a9bf9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/modules/interface/kalman_core/kalman_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void kalmanCoreUpdateWithBaro(kalmanCoreData_t *this, const kalmanCoreParams_t *
*
* The filter progresses as:
* - Predicting the current state forward */
void kalmanCorePredict(kalmanCoreData_t *this, const kalmanCoreParams_t *params, Axis3f *acc, Axis3f *gyro, float dt, bool quadIsFlying);
void kalmanCorePredict(kalmanCoreData_t *this, Axis3f *acc, Axis3f *gyro, float dt, bool quadIsFlying);

void kalmanCoreAddProcessNoise(kalmanCoreData_t *this, const kalmanCoreParams_t *params, float dt);

Expand All @@ -155,4 +155,4 @@ void kalmanCoreDecoupleXY(kalmanCoreData_t* this);

void kalmanCoreScalarUpdate(kalmanCoreData_t* this, arm_matrix_instance_f32 *Hm, float error, float stdMeasNoise);

void kalmanCoreUpdateWithPKE(kalmanCoreData_t* this, arm_matrix_instance_f32 *Hm, arm_matrix_instance_f32 *Km, arm_matrix_instance_f32 *P_w_m, float error);
void kalmanCoreUpdateWithPKE(kalmanCoreData_t* this, arm_matrix_instance_f32 *Hm, arm_matrix_instance_f32 *Km, arm_matrix_instance_f32 *P_w_m, float error);
5 changes: 3 additions & 2 deletions src/modules/src/estimator_kalman.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ STATIC_MEM_TASK_ALLOC_STACK_NO_DMA_CCM_SAFE(kalmanTask, 3 * configMINIMAL_STACK_

// Called one time during system startup
void estimatorKalmanTaskInit() {
kalmanCoreDefaultParams(&coreParams);

vSemaphoreCreateBinary(runTaskSemaphore);

dataMutex = xSemaphoreCreateMutexStatic(&dataMutexBuffer);
Expand Down Expand Up @@ -331,7 +333,7 @@ static bool predictStateForward(uint32_t osTick, float dt) {
gyroAccumulatorCount = 0;

quadIsFlying = supervisorIsFlying();
kalmanCorePredict(&coreData, &coreParams, &accAverage, &gyroAverage, dt, quadIsFlying);
kalmanCorePredict(&coreData, &accAverage, &gyroAverage, dt, quadIsFlying);

return true;
}
Expand Down Expand Up @@ -434,7 +436,6 @@ void estimatorKalmanInit(void)
gyroAccumulatorCount = 0;
outlierFilterReset(&sweepOutlierFilterState, 0);

kalmanCoreDefaultParams(&coreParams);
kalmanCoreInit(&coreData, &coreParams);
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/src/kalman_core/kalman_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void kalmanCoreUpdateWithBaro(kalmanCoreData_t *this, const kalmanCoreParams_t *
kalmanCoreScalarUpdate(this, &H, meas - this->S[KC_STATE_Z], params->measNoiseBaro);
}

void kalmanCorePredict(kalmanCoreData_t* this, const kalmanCoreParams_t * params, Axis3f *acc, Axis3f *gyro, float dt, bool quadIsFlying)
void kalmanCorePredict(kalmanCoreData_t* this, Axis3f *acc, Axis3f *gyro, float dt, bool quadIsFlying)
{
/* Here we discretize (euler forward) and linearise the quadrocopter dynamics in order
* to push the covariance forward.
Expand Down

0 comments on commit 52a9bf9

Please sign in to comment.