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(const 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
178 void resetCovariance();
179
180private:
182 NASConfig config;
183
185 ReferenceValues reference;
186
188 Eigen::Matrix<float, 13, 1> x;
189
191 Eigen::Matrix<float, 12, 12> P;
192
194 const Eigen::Vector3f gravityNed{0.0f, 0.0f, -Constants::g};
195
196 // Utility matrixes used for the gps
197 Eigen::Matrix<float, 4, 6> H_gps;
198 Eigen::Matrix<float, 6, 4> H_gps_tr;
199 Eigen::Matrix<float, 4, 4> R_gps;
200
201 // Utility matrixes
202 Eigen::Matrix3f R_acc;
203 Eigen::Matrix3f R_mag;
204 Eigen::Matrix<float, 6, 6> Q_quat;
205 Eigen::Matrix<float, 6, 6> Q_lin;
206 Eigen::Matrix<float, 6, 6> F_lin;
207 Eigen::Matrix<float, 6, 6> F_lin_tr;
208 Eigen::Matrix<float, 6, 6> F_quat;
209 Eigen::Matrix<float, 6, 6> F_quat_tr;
210 Eigen::Matrix<float, 6, 6> G_quat;
211 Eigen::Matrix<float, 6, 6> G_quat_tr;
212};
213
214} // 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:318
Eigen::Matrix< float, 13, 1 > getX() const
Definition NAS.cpp:469
void resetCovariance()
Resets the covariance matrix to the initial state based on the configuration.
Definition NAS.cpp:482
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:464
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:471
static constexpr uint16_t IDX_POS
< Index of position elements in the state.
Definition NAS.h:42
void correctGPS(const Eigen::Vector4f &gps)
Correction with gps data.
void setReferenceValues(const ReferenceValues &reference)
Changes the reference values.
Definition NAS.cpp:475
void correctBaro(const float pressure)
Correction with barometer data.
Definition NAS.cpp:138
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:480
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:473
Driver for the VN100S IMU.
Structure to handle accelerometer data.
Definition SensorData.h:119
Structure to handle GPS data.
Definition SensorData.h:277
Structure to handle gyroscope data.
Definition SensorData.h:199
Structure to handle magnetometer data.
Definition SensorData.h:238
Reference values for the Apogee Detection Algorithm.