Skyward boardcore
Loading...
Searching...
No Matches
AxisOrientation.h
Go to the documentation of this file.
1/* Copyright (c) 2021-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#pragma once
24
25#include <sensors/Sensor.h>
26
27#include <Eigen/Core>
28#include <Eigen/Geometry>
29
30namespace Boardcore
31{
32
36enum class Direction : uint8_t
37{
38 POSITIVE_X = 0,
44};
45
46constexpr const char* humanFriendlyDirection[]{
47 "North", "South", "East", "West", "Down", "Up",
48};
49
50inline Eigen::Vector3f orientationToVector(Direction direction)
51{
52 switch (direction)
53 {
55 return {1, 0, 0};
57 return {-1, 0, 0};
59 return {0, 1, 0};
61 return {0, -1, 0};
63 return {0, 0, 1};
65 return {0, 0, -1};
66 default:
67 // never happens, added just to shut up the warnings
68 return {0, 0, 0};
69 }
70}
71
80{
81 virtual Eigen::Matrix3f getMatrix() const = 0;
82};
83
104{
105 float yaw, pitch, roll;
106
108
109 AxisAngleOrientation(float _yaw, float _pitch, float _roll)
110 : yaw(_yaw), pitch(_pitch), roll(_roll)
111 {
112 }
113
114 Eigen::Matrix3f getMatrix() const override
115 {
116 return (Eigen::AngleAxisf(yaw, Eigen::Vector3f::UnitZ()) *
117 Eigen::AngleAxisf(pitch, Eigen::Vector3f::UnitY()) *
118 Eigen::AngleAxisf(roll, Eigen::Vector3f::UnitX()))
119 .toRotationMatrix();
120 }
121};
122
149{
151
156
158 : xAxis(_xAxis), yAxis(_yAxis)
159 {
160 }
161
167 Eigen::Matrix3f getMatrix() const override
168 {
169 Eigen::Vector3f vx, vy, vz;
170
173 vz = vx.cross(vy);
174
175 Eigen::Matrix3f mat;
176 mat.row(0) << vx.transpose();
177 mat.row(1) << vy.transpose();
178 mat.row(2) << vz.transpose();
179 return mat;
180 }
181};
182
191{
193
199
200 Eigen::Matrix3f getMatrix() const override
201 {
202 return orientationA.getMatrix() * orientationB.getMatrix();
203 }
204};
205
206} // namespace Boardcore
This file includes all the types the logdecoder script will decode.
constexpr const char * humanFriendlyDirection[]
Eigen::Vector3f orientationToVector(Direction direction)
This struct uses the three angles yaw, pitch and roll to define a transformation.
Eigen::Matrix3f getMatrix() const override
AxisAngleOrientation(float _yaw, float _pitch, float _roll)
This struct represents in the most general way any kind of transformation of the reference frame (axi...
virtual Eigen::Matrix3f getMatrix() const =0
This struct represents orthogonal rotations.
AxisOrthoOrientation(Direction _xAxis, Direction _yAxis)
Eigen::Matrix3f getMatrix() const override
Returns a rotation matrix.
This struct represents axis orientation relative to a reference system.
const AxisOrientation & orientationA
const AxisOrientation & orientationB
AxisRelativeOrientation(const AxisOrientation &orientationA, const AxisOrientation &orientationB)
Eigen::Matrix3f getMatrix() const override