Skyward boardcore
Loading...
Searching...
No Matches
ADA.cpp
Go to the documentation of this file.
1/* Copyright (c) 2018-2022 Skyward Experimental Rocketry
2 * Authors: Luca Mozzarelli, Luca Conterio, Alberto Nidasio
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 "ADA.h"
24
27
28namespace Boardcore
29{
30
31ADA::ADA(const KalmanFilter::KalmanConfig kalmanConfig)
32 : filter(kalmanConfig), state()
33{
34 updateState();
35}
36
37void ADA::update(const float pressure)
38{
39 // Update the Kalman filter
40 filter.predict();
41 filter.correct(KalmanFilter::CVectorP{pressure});
42
43 // Convert filter data to altitudes and speeds
44 updateState();
45}
46
48{
49 // Update the Kalman filter
50 filter.predict();
51
52 // Convert filter data to altitudes and speeds
53 updateState();
54}
55
56ADAState ADA::getState() { return state; }
57
59{
60 this->reference = reference;
61}
62
63void ADA::setKalmanConfig(KalmanFilter::KalmanConfig config)
64{
65 filter.setConfig(config);
66}
67
69
70void ADA::updateState()
71{
72 const auto filterState = filter.getState();
73
74 // Convert filter data to altitudes and speeds
75 state.x0 = filterState(0);
76 state.x1 = filterState(1);
77 state.x2 = filterState(2);
80 filterState(0), reference.mslPressure, reference.mslTemperature);
81 state.aglAltitude = state.mslAltitude - reference.refAltitude;
83 filterState(0), filterState(1), reference.mslPressure,
84 reference.mslTemperature);
85}
86
87} // namespace Boardcore
ReferenceValues getReferenceValues()
Returns the current reference values.
Definition ADA.cpp:68
ADAState getState()
Definition ADA.cpp:56
void setReferenceValues(const ReferenceValues reference)
Changes the reference values.
Definition ADA.cpp:58
void setKalmanConfig(KalmanFilter::KalmanConfig config)
Changes the kalman filter configuration.
Definition ADA.cpp:63
void update()
Update the Kalman filter, skipping the correct step.
Definition ADA.cpp:47
ADA(const KalmanFilter::KalmanConfig kalmanConfig)
Definition ADA.cpp:31
Eigen::Vector< float, P_size > CVectorP
Definition Kalman.h:46
void setConfig(const KalmanConfig &config)
Definition Kalman.h:76
const CVectorN getState()
Definition Kalman.h:159
bool correct(const CVectorP &y)
Correction step.
Definition Kalman.h:137
void predict()
Prediction step with previous F matrix.
Definition Kalman.h:92
float verticalSpeed(float p, float dpDt, float pRef, float tRef)
Definition AeroUtils.cpp:69
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
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
uint64_t timestamp
Definition ADAData.h:32
Reference values for the Apogee Detection Algorithm.