Skyward boardcore
Loading...
Searching...
No Matches
SixParametersCorrector.cpp
Go to the documentation of this file.
1/* Copyright (c) 2021 Skyward Experimental Rocketry
2 * Authors: Riccardo Musso, 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
24
25#include <fstream>
26
27using namespace Eigen;
28
29namespace Boardcore
30{
31
35
37 Eigen::Vector3f b)
38 : BiasCorrector(b), A(A)
39{
40}
41
42bool SixParametersCorrector::fromFile(const std::string& fileName)
43{
44 std::ifstream input(fileName);
45
46 if (input)
47 {
48 // Ignore header line (csv header)
49 input.ignore(1000, '\n');
50
51 for (int i = 0; i < 3; i++)
52 {
53 input >> b(i);
54 input.ignore(1, ',');
55 }
56
57 for (int i = 0; i < 3; i++)
58 {
59 input >> A(i);
60 input.ignore(1, ',');
61 }
62
63 input.close();
64
65 return true;
66 }
67 else
68 {
69 return false;
70 }
71}
72
73bool SixParametersCorrector::toFile(const std::string& fileName)
74{
75 std::ofstream output(fileName);
76
77 if (output)
78 {
79 output << "b0,b1,b2,A0,A1,A2" << std::endl;
80 output << b(0) << "," << b(1) << "," << b(2) << ",";
81 output << A(0) << "," << A(1) << "," << A(2);
82
83 output.close();
84
85 return true;
86 }
87 else
88 {
89 return false;
90 }
91}
92
93Vector3f SixParametersCorrector::correct(const Vector3f& input) const
94{
95 // From magcal in MATLab: out = (in - b) * A
96 return A.cwiseProduct(input - b);
97}
98
99Eigen::Vector3f SixParametersCorrector::getA() const { return A; }
100
101void SixParametersCorrector::setA(const Eigen::Vector3f& A) { this->A = A; }
102
103} // namespace Boardcore
Bias correction removes a bias from a measurement.
bool fromFile(const std::string &fileName) override
void setA(const Eigen::Vector3f &A)
Eigen::Vector3f correct(const Eigen::Vector3f &input) const override
bool toFile(const std::string &fileName) override
This file includes all the types the logdecoder script will decode.