Skyward boardcore
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MEA.h
Go to the documentation of this file.
1/* Copyright (c) 2024 Skyward Experimental Rocketry
2 * Author: Davide Mor
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
26#include <sensors/SensorData.h>
28
29#include <Eigen/Dense>
30
31namespace Boardcore
32{
33
34class MEA
35{
36public:
37 struct Config
38 {
39 Eigen::Matrix<float, 3, 3> F; //< State propagation matrix
40 Eigen::Matrix<float, 3, 3> Q; //< Model variance matrix
41 Eigen::Vector<float, 3> G; //< Input vector
42
43 Eigen::Vector<float, 3> baroH; //< Barometer output matrix
44 float baroR; //< Barometer measurement variance
45
46 Eigen::Matrix<float, 3, 3> P; //< Error covariance matrix
47
48 float initialMass; //< Initial mass of the rocket
49
50 float accelThresh; //< Minimum required acceleration to trigger accel
51 // correction.
52 float speedThresh; //< Minumum required speed to trigger accel
53 // correction.
54
55 float Kt; //< TODO: What is this?
56 float alpha; //< TODO: What is this?
57 float c; //< TODO: What is this?
58
59 Aeroutils::AerodynamicCoeff coeffs; //< Aerodynamic coefficients.
60 float crossSection; //< Cross section of the rocket.
61
62 float ae; //< Efflux area
63 float p0; //< Pressure at nozzle exit
64
65 float minMass; //< Minimum mass used for predicted apogee
66 float maxMass; //< Maximum mass used for predicted apogee
67
68 float cdCorrectionFactor; // Factor to account for extra drag generated
69 // by the plume
70 };
71
72 struct Step
73 {
75 0.0f; //< How open is the main valve? (between 0-1)
76
77 float ccPressure =
78 0.0f; //< What is the current combustion chamber pressure? [bar]
79 bool hasCCPressure = false; //< Is ccPressure valid?
80
81 Eigen::Vector<float, 3> acceleration =
82 Eigen::Vector<float, 3>::Zero(); //< Acceleration [m/s^2]
83 bool hasAcceleration = false; //< Is acceleration valid?
84
86 0.0f; //< Vertical component of speed [up positive] [m/s]
87 float mslAltitude = 0.0f; //< Mean sea level altitude [m]
89 false; //< Are verticalSpeed and mslAltitude valid?
90
91 explicit Step(float mainValveOpen);
92
94 void withCCPressure(float ccPressure);
95
97 void withAcceleration(Eigen::Vector<float, 3> acceleration);
98
99 void withSpeedAndAlt(float verticalSpeed, float mslAltitude);
100 };
101
102 explicit MEA(const Config& config);
103
104 void update(const Step& step);
105
107
108private:
109 void predict(const Step& step);
110 void computeForce(const Step& step);
111 void correctBaro(const Step& step);
112 void correctAccel(const Step& step);
113 void computeMass();
114 void computeApogee(const Step& step);
115 void updateState();
116
117 Eigen::Matrix<float, 3, 3> F; //< State propagation matrix
118 Eigen::Matrix<float, 3, 3> Q; //< Model variance matrix
119
120 Eigen::Vector<float, 3> G; //< Input Vector
121
122 Eigen::Matrix<float, 1, 3> baroH;
123 float baroR;
124
125 Eigen::Matrix<float, 3, 3> P; //< Error covariance matrix
126 Eigen::Vector<float, 3> x; //< State vector
127
128 float mach = 0.0f; //< Latest computed mach
129 float cd = 0.0f; //< Latest computed CD
130 float rho = 0.0f; //< Latest computed rho
131 float q = 0.0f; //< Latest computed dynamic pressure
132 float force = 0.0f; //< Latest computed force
133
134 float apogee = 0.0f; //< Latest computed apogee
135 float mass; //< Latest computed mass
136
137 float accelThresh;
138 float speedThresh;
139
140 float Kt;
141 float alpha;
142 float c;
143
145 float crossSection;
146
147 float ae;
148 float p0;
149
150 float minMass;
151 float maxMass;
152
153 float cdCorrectionFactor;
154
155 MEAState state;
156};
157
158} // namespace Boardcore
void update(const Step &step)
Definition MEA.cpp:73
MEAState getState()
Definition MEA.cpp:97
Driver for the VN100S IMU.
Structure to handle accelerometer data.
Definition SensorData.h:119
Aeroutils::AerodynamicCoeff coeffs
Definition MEA.h:59
float cdCorrectionFactor
Definition MEA.h:68
Eigen::Vector< float, 3 > G
Definition MEA.h:41
Eigen::Matrix< float, 3, 3 > Q
Definition MEA.h:40
Eigen::Matrix< float, 3, 3 > F
Definition MEA.h:39
Eigen::Matrix< float, 3, 3 > P
Definition MEA.h:46
Eigen::Vector< float, 3 > baroH
Definition MEA.h:43
float verticalSpeed
Definition MEA.h:85
float mslAltitude
Definition MEA.h:87
Eigen::Vector< float, 3 > acceleration
Definition MEA.h:81
float mainValveOpen
Definition MEA.h:74
bool hasSpeedAndAlt
Definition MEA.h:88
bool hasCCPressure
Definition MEA.h:79
bool hasAcceleration
Definition MEA.h:83
void withCCPressure(PressureData ccPressure)
Definition MEA.cpp:32
void withSpeedAndAlt(float verticalSpeed, float mslAltitude)
Definition MEA.cpp:54
float ccPressure
Definition MEA.h:77
void withAcceleration(AccelerometerData acceleration)
Definition MEA.cpp:43