Skyward boardcore
Loading...
Searching...
No Matches
TwelveParametersCorrector.cpp
Go to the documentation of this file.
1/* Copyright (c) 2025 Skyward Experimental Rocketry
2 * Author: Tommaso Lamon
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
24
25#include <fstream>
26
27namespace Boardcore
28{
29
31 Eigen::Vector3f V)
32 : V(V), W(W)
33{
34}
35
37 : V(Eigen::Vector3f::Zero()), W(Eigen::Matrix3f::Identity())
38{
39}
40
41bool TwelveParametersCorrector::fromFile(const std::string& filename)
42{
43 std::ifstream inputFile(filename);
44
45 if (inputFile)
46 {
47 inputFile.ignore(1000, '\n');
48
49 for (int i = 0; i < 3; i++)
50 {
51 for (int j = 0; j < 3; j++)
52 {
53 inputFile >> W(i, j);
54 inputFile.ignore(1, ',');
55 }
56 }
57
58 for (int i = 0; i < 3; i++)
59 {
60 inputFile >> V(i);
61 inputFile.ignore(1, ',');
62 }
63
64 return true;
65 }
66 else
67 {
68 return false;
69 }
70}
71
72bool TwelveParametersCorrector::toFile(const std::string& filename)
73{
74 std::ofstream outputFile(filename);
75
76 if (outputFile)
77 {
78 outputFile << "w00,w01,w02,w10,w11,w12,w20,w21,w22,v0,v1,v2"
79 << std::endl;
80 outputFile << W(0, 0) << "," << W(0, 1) << "," << W(0, 2) << ","
81 << W(1, 0) << "," << W(1, 1) << "," << W(1, 2) << ","
82 << W(2, 0) << "," << W(2, 1) << "," << W(2, 2) << "," << V(0)
83 << "," << V(1) << "," << V(2) << std::endl;
84 return true;
85 }
86 else
87 {
88 return false;
89 }
90}
91
93 const Eigen::Vector3f& inputVector) const
94{
95 return (W * inputVector) + V;
96}
97
98Eigen::Vector3f TwelveParametersCorrector::getV() const { return V; }
99
100void TwelveParametersCorrector::setV(const Eigen::Vector3f& V) { this->V = V; }
101
102Eigen::Matrix3f TwelveParametersCorrector::getW() const { return W; }
103
104void TwelveParametersCorrector::setW(const Eigen::Matrix3f& W) { this->W = W; }
105
106} // namespace Boardcore
Eigen::Vector3f correct(const Eigen::Vector3f &inputVector) const
Applies the correction to a_b,real.
bool toFile(const std::string &filename)
Writes the .csv file with the coefficients of W and V.
bool fromFile(const std::string &filename)
Reads the .csv file for the coefficients to configure the W and V terms of the system.
Driver for the VN100S IMU.