- Joined
- Jan 23, 2009
- Messages
- 5,994
- Reaction score
- 4,103
I'd love to see a snippet of code (preferably in C...) for that. All of the code I've seen so far seems a lot more complex than it should given that there is only one sensor (baro) and an error-free model. Dave's core code is in PIC assembly, I don't do PIC (at least, yet...).
Here's one simplistic implementation
Code:
void KalmanUpdateState(int32_t aglAltMeas, int16_t accelMeas)
{
// calculate apriori state estimate from last updated state
//
// calculate next estimate
int32_t alt, vel ;
int32_t accel ;
int32_t res_alt ;
int32_t res_accel ;
// save last updated estimate in dummy variables
alt = strState.strData.i32KalAlt ;
vel = strState.strData.i32KalVel ;
accel = strState.strData.i32KalAccel ;
// calculate apriori estimate of next state
strState.strData.i32KalAlt = KGA1*alt + KV1*vel + KDV1*accel ;
strState.strData.i32KalAlt /= KGA2 ;
strState.strData.i32KalVel = KGA3*vel + accel ;
strState.strData.i32KalVel /= KGA4 ;
// calculate measurement residuals
res_alt = (int32_t)aglAltMeas - strState.strData.i32KalAlt ;
res_accel = (accelMeas*KK)/K2 - strState.strData.i32KalAccel ;
// update prediction by multiply measurement residuals by Kalman gains
strState.strData.i32KalAlt += (KGAIN00*res_alt + KGAIN01*res_accel)/TEN3 ;
strState.strData.i32KalVel += (KGAIN10*res_alt + KGAIN11*res_accel)/TEN3 ;
strState.strData.i32KalAccel += (KGAIN20*res_alt + KGAIN21*res_accel)/TEN3 ;
}