Skyward boardcore
Loading...
Searching...
No Matches
RotatedIMU.h
Go to the documentation of this file.
1/* Copyright (c) 2024 Skyward Experimental Rocketry
2 * Author: Niccolò Betto
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
25#include <sensors/Sensor.h>
26
27#include <Eigen/Eigen>
28#include <functional>
29
30#include "IMUData.h"
31
32namespace Boardcore
33{
34
39class RotatedIMU : public Boardcore::Sensor<IMUData>
40{
41public:
42 using SampleIMUFunction = std::function<IMUData()>;
43
50 explicit RotatedIMU(SampleIMUFunction sampleFunction);
51
52 bool init() override { return true; }
53 bool selfTest() override { return true; }
54
60 void addAccTransformation(const Eigen::Matrix3f& t);
61
67 void addGyroTransformation(const Eigen::Matrix3f& t);
68
74 void addMagTransformation(const Eigen::Matrix3f& t);
75
80
85 static Eigen::Matrix3f rotateAroundX(float angle);
86
91 static Eigen::Matrix3f rotateAroundY(float angle);
92
97 static Eigen::Matrix3f rotateAroundZ(float angle);
98
99protected:
100 IMUData sampleImpl() override;
101
102private:
103 SampleIMUFunction sampleImu;
104
105 // Transformation matrices
106 Eigen::Matrix3f accT = Eigen::Matrix3f::Identity();
107 Eigen::Matrix3f gyroT = Eigen::Matrix3f::Identity();
108 Eigen::Matrix3f magT = Eigen::Matrix3f::Identity();
109};
110
111} // namespace Boardcore
A software IMU sensor that allows applying transformations to the data after sampling via a callback....
Definition RotatedIMU.h:40
RotatedIMU(SampleIMUFunction sampleFunction)
Construct a new Rotated IMU object.
static Eigen::Matrix3f rotateAroundZ(float angle)
Creates a rotation matrix around the Z axis.
void addGyroTransformation(const Eigen::Matrix3f &t)
Multiplies the current gyroscope transformation.
static Eigen::Matrix3f rotateAroundX(float angle)
Creates a rotation matrix around the X axis.
void resetTransformations()
Resets all the transformations to the original (Identity) ones.
IMUData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
bool selfTest() override
Check if the sensor is working.
Definition RotatedIMU.h:53
void addAccTransformation(const Eigen::Matrix3f &t)
Multiplies the current accelerometer transformation.
std::function< IMUData()> SampleIMUFunction
Definition RotatedIMU.h:42
static Eigen::Matrix3f rotateAroundY(float angle)
Creates a rotation matrix around the Y axis.
void addMagTransformation(const Eigen::Matrix3f &t)
Multiplies the current magnetometer transformation.
bool init() override
Initialize the sensor.
Definition RotatedIMU.h:52
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
This file includes all the types the logdecoder script will decode.