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;
106 alpha = config.
alpha;
117void MEA::predict(
const Step& step)
119 x = F * x + G * step.mainValveOpen;
120 P = F * P * F.transpose() + Q;
123void MEA::computeForce(
const Step& step)
125 if (!step.hasSpeedAndAlt)
132 Constants::MSL_TEMPERATURE);
138 q = 0.5f * rho * (step.verticalSpeed * step.verticalSpeed);
141 force = q * crossSection * (cd * cdCorrectionFactor);
143 if (step.mslAltitude > 800)
149 force -= (p0 - p) * ae;
153void MEA::correctBaro(
const Step& step)
155 if (!step.hasCCPressure)
158 float S = baroH * P * baroH.transpose() + baroR;
164 Matrix<float, 3, 1> K = (P * baroH.transpose()) / S;
166 P = (Matrix<float, 3, 3>::Identity() - K * baroH) * P;
167 x = x + K * (step.ccPressure - baroH * x);
170void MEA::correctAccel(
const Step& step)
172 if (!step.hasAcceleration || !step.hasSpeedAndAlt)
176 if (step.acceleration.norm() < accelThresh ||
177 step.verticalSpeed < speedThresh)
182 float y = (Kt * (float)(baroH * x) - force) / x(2);
184 Matrix<float, 1, 3> accelH =
185 Vector<float, 3>{Kt * baroH(0) / x(2), Kt * baroH(1) / x(2),
186 -(Kt * (float)(baroH * x) - force) / (x(2) * x(2))}
189 float accelR = alpha * q + c;
191 float S = accelH * P * accelH.transpose() + accelR;
197 Matrix<float, 3, 1> K = (P * accelH.transpose()) / S;
199 P = (Matrix<float, 3, 3>::Identity() - K * accelH) * P;
200 x = x + K * (step.acceleration.x() - y);
203void MEA::computeMass()
207 mass = std::max(std::min(x(2), maxMass), minMass);
210void MEA::computeApogee(
const Step& step)
212 if (!step.hasSpeedAndAlt)
217 float temp = ((rho * cd * crossSection) / mass);
218 apogee = step.mslAltitude +
220 log1p(0.5 * (step.verticalSpeed * step.verticalSpeed * temp) /
224void MEA::updateState()
MEA(const Config &config)
void update(const Step &step)
void reset(const Config &config)
Resets the algorithm with the given configuration.
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.
Driver for the VN100S IMU.
Structure to handle accelerometer data.
Aeroutils::AerodynamicCoeff coeffs
Eigen::Vector< float, 3 > G
Eigen::Matrix< float, 3, 3 > Q
Eigen::Matrix< float, 3, 3 > F
Eigen::Matrix< float, 3, 3 > P
Eigen::Vector< float, 3 > baroH
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