Skyward boardcore
Loading...
Searching...
No Matches
NAS.h
Go to the documentation of this file.
1/* Copyright (c) 2020-2022 Skyward Experimental Rocketry
2 * Authors: Alessandro Del Duca, Luca Conterio, Marco Cella
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#include <utils/Constants.h>
29
30#include <Eigen/Dense>
31
32#include "NASConfig.h"
33#include "NASState.h"
34
35namespace Boardcore
36{
37
38class NAS
39{
40public:
42 static constexpr uint16_t IDX_POS = 0;
43
45 static constexpr uint16_t IDX_VEL = 3;
46
48 static constexpr uint16_t IDX_QUAT = 6;
49
51 static constexpr uint16_t IDX_BIAS = 10;
52
53 explicit NAS(NASConfig config);
54
60 void predictAcc(const Eigen::Vector3f& acceleration);
61
67 void predictAcc(const AccelerometerData& acceleration);
68
74 void predictGyro(const Eigen::Vector3f& angularSpeed);
75
81 void predictGyro(const GyroscopeData& angularSpeed);
82
88 void correctBaro(const float pressure);
89
95 void correctGPS(const Eigen::Vector4f& gps);
96
102 void correctGPS(const GPSData& gps);
103
109 void correctMag(const Eigen::Vector3f& mag);
110
116 void correctMag(const MagnetometerData& mag);
117
123 void correctAcc(const Eigen::Vector3f& acc);
124
130 void correctAcc(const AccelerometerData& acc);
131
142 void correctPitot(const float staticPressure, const float dynamicPressure);
143
147 NASState getState() const;
148
152 Eigen::Matrix<float, 13, 1> getX() const;
153
157 void setState(const NASState& state);
158
162 void setX(const Eigen::Matrix<float, 13, 1>& x);
163
167 void setReferenceValues(const ReferenceValues reference);
168
173
174private:
176 NASConfig config;
177
179 ReferenceValues reference;
180
182 Eigen::Matrix<float, 13, 1> x;
183
185 Eigen::Matrix<float, 12, 12> P;
186
188 const Eigen::Vector3f gravityNed{0.0f, 0.0f, -Constants::g};
189
190 // Utility matrixes used for the gps
191 Eigen::Matrix<float, 4, 6> H_gps;
192 Eigen::Matrix<float, 6, 4> H_gps_tr;
193 Eigen::Matrix<float, 4, 4> R_gps;
194
195 // Utility matrixes
196 Eigen::Matrix3f R_acc;
197 Eigen::Matrix3f R_mag;
198 Eigen::Matrix<float, 6, 6> Q_quat;
199 Eigen::Matrix<float, 6, 6> Q_lin;
200 Eigen::Matrix<float, 6, 6> F_lin;
201 Eigen::Matrix<float, 6, 6> F_lin_tr;
202 Eigen::Matrix<float, 6, 6> F_quat;
203 Eigen::Matrix<float, 6, 6> F_quat_tr;
204 Eigen::Matrix<float, 6, 6> G_quat;
205 Eigen::Matrix<float, 6, 6> G_quat_tr;
206};
207
208} // namespace Boardcore
void predictGyro(const Eigen::Vector3f &angularSpeed)
Prediction with gyroscope data.
void correctPitot(const float staticPressure, const float dynamicPressure)
Correction with pitot pressures.
Definition NAS.cpp:337
Eigen::Matrix< float, 13, 1 > getX() const
Definition NAS.cpp:384
void predictAcc(const Eigen::Vector3f &acceleration)
Prediction with accelerometer data.
static constexpr uint16_t IDX_BIAS
Definition NAS.h:51
NASState getState() const
Definition NAS.cpp:379
void correctAcc(const Eigen::Vector3f &acc)
Correction with accelerometer data.
void correctMag(const Eigen::Vector3f &mag)
Correction with magnetometer data.
void setState(const NASState &state)
Definition NAS.cpp:386
static constexpr uint16_t IDX_POS
< Index of position elements in the state.
Definition NAS.h:42
void setReferenceValues(const ReferenceValues reference)
Changes the reference values.
Definition NAS.cpp:390
void correctGPS(const Eigen::Vector4f &gps)
Correction with gps data.
NAS(NASConfig config)
Definition NAS.cpp:37
void correctBaro(const float pressure)
Correction with barometer data.
Definition NAS.cpp:157
static constexpr uint16_t IDX_VEL
Index of quaternions elements in the state.
Definition NAS.h:45
ReferenceValues getReferenceValues()
Returns the current reference values.
Definition NAS.cpp:395
static constexpr uint16_t IDX_QUAT
Index of bias elements in the state.
Definition NAS.h:48
void setX(const Eigen::Matrix< float, 13, 1 > &x)
Definition NAS.cpp:388
This file includes all the types the logdecoder script will decode.
Structure to handle accelerometer data.
Definition SensorData.h:121
Structure to handle GPS data.
Definition SensorData.h:291
Structure to handle gyroscope data.
Definition SensorData.h:207
Structure to handle magnetometer data.
Definition SensorData.h:249
Reference values for the Apogee Detection Algorithm.