Skyward boardcore
Loading...
Searching...
No Matches
BiasCorrector.cpp
Go to the documentation of this file.
1/* Copyright (c) 2020-2022 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
23#include "BiasCorrector.h"
24
25#include <fstream>
26
27using namespace Eigen;
28
29namespace Boardcore
30{
31
33
34BiasCorrector::BiasCorrector(const Eigen::Vector3f& b) : b(b) {}
35
36bool BiasCorrector::fromFile(const std::string& fileName)
37{
38 std::ifstream input(fileName);
39
40 if (input)
41 {
42 // Ignore header line (csv header)
43 input.ignore(1000, '\n');
44
45 for (int i = 0; i < 3; i++)
46 {
47 input >> b(i);
48 input.ignore(1, ',');
49 }
50
51 return true;
52 }
53 else
54 {
55 return false;
56 }
57}
58
59bool BiasCorrector::toFile(const std::string& fileName)
60{
61 std::ofstream output(fileName);
62
63 if (output)
64 {
65 output << "b0,b1,b2" << std::endl;
66 output << b(0) << "," << b(1) << "," << b(1);
67
68 return true;
69 }
70 else
71 {
72 return false;
73 }
74}
75
76Eigen::Vector3f BiasCorrector::getb() const { return b; }
77
78void BiasCorrector::setb(const Eigen::Vector3f& b) { this->b = b; }
79
80Vector3f BiasCorrector::correct(const Vector3f& data) const { return data - b; }
81
82} // namespace Boardcore
virtual bool toFile(const std::string &fileName)
virtual bool fromFile(const std::string &fileName)
void setb(const Eigen::Vector3f &b)
Eigen::Vector3f getb() const
virtual Eigen::Vector3f correct(const Eigen::Vector3f &data) const
This file includes all the types the logdecoder script will decode.