39 this->ccPressure = ccPressure;
45 withAcceleration(
static_cast<Eigen::Vector<float, 3>
>(acceleration));
50 this->acceleration = acceleration;
51 hasAcceleration =
true;
56 this->verticalSpeed = verticalSpeed;
57 this->mslAltitude = mslAltitude;
58 hasSpeedAndAlt =
true;
62 : F{config.F}, Q{config.Q}, G{config.G}, baroH{config.baroH},
63 baroR{config.baroR}, P{config.P}, x{0, 0, config.initialMass},
64 mass{config.initialMass}, accelThresh{config.accelThresh},
65 speedThresh{config.speedThresh}, Kt{config.Kt}, alpha{config.alpha},
66 c{config.c}, coeffs{config.coeffs}, crossSection{config.crossSection},
67 ae{config.ae}, p0{config.p0}, minMass{config.minMass},
68 maxMass{config.maxMass}, cdCorrectionFactor(config.cdCorrectionFactor)
99void MEA::predict(
const Step& step)
101 x = F * x + G * step.mainValveOpen;
102 P = F * P * F.transpose() + Q;
105void MEA::computeForce(
const Step& step)
107 if (!step.hasSpeedAndAlt)
114 Constants::MSL_TEMPERATURE);
120 q = 0.5f * rho * (step.verticalSpeed * step.verticalSpeed);
123 force = q * crossSection * (cd * cdCorrectionFactor);
125 if (step.mslAltitude > 800)
131 force -= (p0 - p) * ae;
135void MEA::correctBaro(
const Step& step)
137 if (!step.hasCCPressure)
140 float S = baroH * P * baroH.transpose() + baroR;
146 Matrix<float, 3, 1> K = (P * baroH.transpose()) / S;
148 P = (Matrix<float, 3, 3>::Identity() - K * baroH) * P;
149 x = x + K * (step.ccPressure - baroH * x);
152void MEA::correctAccel(
const Step& step)
154 if (!step.hasAcceleration || !step.hasSpeedAndAlt)
158 if (step.acceleration.norm() < accelThresh ||
159 step.verticalSpeed < speedThresh)
164 float y = (Kt * (float)(baroH * x) - force) / x(2);
166 Matrix<float, 1, 3> accelH =
167 Vector<float, 3>{Kt * baroH(0) / x(2), Kt * baroH(1) / x(2),
168 -(Kt * (float)(baroH * x) - force) / (x(2) * x(2))}
171 float accelR = alpha * q + c;
173 float S = accelH * P * accelH.transpose() + accelR;
179 Matrix<float, 3, 1> K = (P * accelH.transpose()) / S;
181 P = (Matrix<float, 3, 3>::Identity() - K * accelH) * P;
182 x = x + K * (step.acceleration.x() - y);
185void MEA::computeMass()
189 mass = std::max(std::min(x(2), maxMass), minMass);
192void MEA::computeApogee(
const Step& step)
194 if (!step.hasSpeedAndAlt)
199 float temp = ((rho * cd * crossSection) / mass);
200 apogee = step.mslAltitude +
202 log1p(0.5 * (step.verticalSpeed * step.verticalSpeed * temp) /
206void MEA::updateState()
MEA(const Config &config)
void update(const Step &step)
float computeMach(float d, float vtot, float t0)
Computes the mach relative to the speed at a certain altitude.
float computeCd(const AerodynamicCoeff &coeff, float mach)
Computes the CD from aerodynamic coefficients and mach.
float relPressure(float altitude, float pressureRef, float temperatureRef)
Returns the pressure given the altitude with respect to a reference pressure and temperature,...
float computeRho(float d, float t0)
Computes the rho (air density) of air at the given altitude.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
Structure to handle accelerometer data.
void withCCPressure(PressureData ccPressure)
void withSpeedAndAlt(float verticalSpeed, float mslAltitude)
void withAcceleration(AccelerometerData acceleration)
Step(float mainValveOpen)
float x0
first kalman state
float estimatedMass
Estimated rocket mass [kg].
float estimatedPressure
Estimated pressure in combustion chamber [Pa].
float x2
third kalman state representing the mass
float estimatedApogee
Estimated apogee in msl [m].
float estimatedForce
Estimated drag force [N].
float x1
second kalman state