Skyward boardcore
Loading...
Searching...
No Matches
AeroUtils.cpp
Go to the documentation of this file.
1/* Copyright (c) 2019-2023 Skyward Experimental Rocketry
2 * Authors: Luca Erbetta, Emilio Corigliano
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#include "AeroUtils.h"
24
25#include <utils/Constants.h>
26
27using namespace Eigen;
28using namespace Boardcore::Constants;
29
30namespace Boardcore
31{
32
33namespace Aeroutils
34{
35
36float relAltitude(float pressure, float pressureRef, float temperatureRef)
37{
38 return temperatureRef / a * (1 - powf(pressure / pressureRef, nInv));
39}
40
41float relPressure(float altitude, float pressureRef, float temperatureRef)
42{
43 return pressureRef * powf(1 - a * altitude / temperatureRef, n);
44}
45
46float relTemperature(float altitude, float temperatureRef)
47{
48 return temperatureRef - Constants::a * altitude;
49}
50
51float relDensity(float pressure, float pressureRef, float altitudeRef,
52 float temperatureRef)
53{
54 return pressure / (R * a * altitudeRef +
55 R * temperatureRef * powf(pressure / pressureRef, nInv));
56}
57
58float mslPressure(float pressureRef, float temperatureRef, float altitudeRef)
59{
60 float T0 = mslTemperature(temperatureRef, altitudeRef);
61 return pressureRef / powf(1 - a * altitudeRef / T0, n);
62}
63
64float mslTemperature(float temperatureRef, float altitudeRef)
65{
66 return temperatureRef + Constants::a * altitudeRef;
67}
68
69float verticalSpeed(float p, float dpDt, float pRef, float tRef)
70{
71 return -(tRef * dpDt * powf(p / pRef, nInv)) / (a * n * p);
72}
73
74Vector2f geodetic2NED(const Vector2f& target, const Vector2f& origin)
75{
76 float mPerDegLat = 111132.95225;
77 float mPerDegLon =
78 fabsf(111412.87733 * cosf(target[0] * Constants::DEGREES_TO_RADIANS));
79
80 return {
81 mPerDegLat * (target[0] - origin[0]),
82 mPerDegLon * (target[1] - origin[1]),
83 };
84}
85
86float computeRho(float d, float t0)
87{
88 float T = t0 + Constants::a * d;
89 return Constants::RHO_0 *
90 powf(T / Constants::MSL_TEMPERATURE,
91 Constants::g / (Constants::a * Constants::R) - 1.f);
92}
93
94float computeSoundSpeed(float d, float t0)
95{
96 float T = t0 + Constants::a * d;
97 float c = sqrtf(Constants::GAMMA_AIR * Constants::R * T);
98 return c;
99}
100
101float computeMach(float d, float vtot, float t0)
102{
103 return vtot / computeSoundSpeed(d, t0);
104}
105
106float computePitotMach(float pressureTotal, float pressureStatic)
107{
108 return sqrtf(((powf(pressureTotal / pressureStatic,
109 (Constants::GAMMA_AIR - 1) / Constants::GAMMA_AIR)) -
110 1) *
111 (2 / (Constants::GAMMA_AIR - 1)));
112}
113
114float computePitotAirspeed(float pressureTotal, float pressureStatic, float d,
115 float t0)
116{
117 float c = computeSoundSpeed(d, t0);
118 float M = computePitotMach(pressureTotal, pressureStatic);
119 return M * c;
120}
121
122float computeCd(const AerodynamicCoeff& coeff, float mach)
123{
124 return coeff.n000 + coeff.n100 * mach + coeff.n200 * powf(mach, 2) +
125 coeff.n300 * powf(mach, 3) + coeff.n400 * powf(mach, 4) +
126 coeff.n500 * powf(mach, 5) + coeff.n600 * powf(mach, 6);
127}
128
129} // namespace Aeroutils
130
131} // namespace Boardcore
float computePitotMach(float pressureTotal, float pressureStatic)
Computes the mach from total and static pressure measures from a pitot tube.
float computePitotAirspeed(float pressureTotal, float pressureStatic, float d, float t0)
Computes air speed relative to the pitot tube.
float computeMach(float d, float vtot, float t0)
Computes the mach relative to the speed at a certain altitude.
float verticalSpeed(float p, float dpDt, float pRef, float tRef)
Definition AeroUtils.cpp:69
float mslPressure(float pressureRef, float temperatureRef, float altitudeRef)
Returns the expected pressure at mean sea level based on temperature and pressure at a reference alti...
Definition AeroUtils.cpp:58
float relDensity(float pressure, float pressureRef, float altitudeRef, float temperatureRef)
Returns the air density given the pressure with respect to a reference pressure, altitude and tempera...
Definition AeroUtils.cpp:51
Vector2f geodetic2NED(const Vector2f &target, const Vector2f &origin)
Definition AeroUtils.cpp:74
float computeCd(const AerodynamicCoeff &coeff, float mach)
Computes the CD from aerodynamic coefficients and mach.
float mslTemperature(float temperatureRef, float altitudeRef)
Returns the expected temperature at mean sea level based on temperature at a reference altitude,...
Definition AeroUtils.cpp:64
float relAltitude(float pressure, float pressureRef, float temperatureRef)
Returns the altitude given the pressure with respect to a reference pressure and temperature,...
Definition AeroUtils.cpp:36
float relPressure(float altitude, float pressureRef, float temperatureRef)
Returns the pressure given the altitude with respect to a reference pressure and temperature,...
Definition AeroUtils.cpp:41
float computeSoundSpeed(float d, float t0)
Computes the speed of sound at the given altitude.
Definition AeroUtils.cpp:94
float relTemperature(float altitude, float temperatureRef)
Returns the temperature at the given altitude with respect to the reference temperature.
Definition AeroUtils.cpp:46
float computeRho(float d, float t0)
Computes the rho (air density) of air at the given altitude.
Definition AeroUtils.cpp:86
This file includes all the types the logdecoder script will decode.