1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
altitude.cpp: Altitude estimation via barometer/accelerometer fusion
*/
#include "filters.h"
#include "algebra.h"
#include "altitude.h"
AltitudeEstimator::AltitudeEstimator(float sigmaAccel, float sigmaGyro, float sigmaBaro,
float ca, float accelThreshold)
:kalman(ca, sigmaGyro, sigmaAccel), complementary(sigmaAccel, sigmaBaro, accelThreshold)
{
this->sigmaAccel = sigmaAccel;
this->sigmaGyro = sigmaGyro;
this->sigmaBaro = sigmaBaro;
this->ca = ca;
this->accelThreshold = accelThreshold;
}
void AltitudeEstimator::estimate(float accel[3], float gyro[3], float baroHeight, uint32_t timestamp)
{
float deltat = (float)(timestamp-previousTime)/1000000.0f;
float verticalAccel = kalman.estimate(pastGyro,
pastAccel,
deltat);
complementary.estimate(& estimatedVelocity,
& estimatedAltitude,
baroHeight,
pastAltitude,
pastVerticalVelocity,
pastVerticalAccel,
deltat);
// update values for next iteration
copyVector(pastGyro, gyro);
copyVector(pastAccel, accel);
pastAltitude = estimatedAltitude;
pastVerticalVelocity = estimatedVelocity;
pastVerticalAccel = verticalAccel;
previousTime = timestamp;
}
float AltitudeEstimator::getAltitude()
{
// return the last estimated altitude
return estimatedAltitude;
}
float AltitudeEstimator::getVerticalVelocity()
{
// return the last estimated vertical velocity
return estimatedVelocity;
}
float AltitudeEstimator::getVerticalAcceleration()
{
// return the last estimated vertical acceleration
return pastVerticalAccel;
}
|