Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / common / sensor_alignment.h
blobe158c6052edbed406bd9850993d69d71a4809e58
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "axis.h"
24 #include "maths.h"
26 typedef enum {
27 ALIGN_DEFAULT = 0, // driver-provided alignment
29 // the order of these 8 values also correlate to corresponding code in ALIGNMENT_TO_BITMASK.
31 // R, P, Y
32 CW0_DEG = 1, // 00,00,00
33 CW90_DEG = 2, // 00,00,01
34 CW180_DEG = 3, // 00,00,10
35 CW270_DEG = 4, // 00,00,11
36 CW0_DEG_FLIP = 5, // 00,10,00 // _FLIP = 2x90 degree PITCH rotations
37 CW90_DEG_FLIP = 6, // 00,10,01
38 CW180_DEG_FLIP = 7, // 00,10,10
39 CW270_DEG_FLIP = 8, // 00,10,11
41 ALIGN_CUSTOM = 9, // arbitrary sensor angles, e.g. for external sensors
42 } sensor_align_e;
44 typedef union sensorAlignment_u {
45 // value order is the same as axis_e
47 // values are in DECIDEGREES, and should be limited to +/- 3600
49 int16_t raw[XYZ_AXIS_COUNT];
50 struct {
51 int16_t roll;
52 int16_t pitch;
53 int16_t yaw;
55 } sensorAlignment_t;
57 #define SENSOR_ALIGNMENT(ROLL, PITCH, YAW) ((sensorAlignment_t){\
58 .roll = DEGREES_TO_DECIDEGREES(ROLL), \
59 .pitch = DEGREES_TO_DECIDEGREES(PITCH), \
60 .yaw = DEGREES_TO_DECIDEGREES(YAW), \
63 #define CUSTOM_ALIGN_CW0_DEG SENSOR_ALIGNMENT( 0, 0, 0)
64 #define CUSTOM_ALIGN_CW90_DEG SENSOR_ALIGNMENT( 0, 0, 90)
65 #define CUSTOM_ALIGN_CW180_DEG SENSOR_ALIGNMENT( 0, 0, 180)
66 #define CUSTOM_ALIGN_CW270_DEG SENSOR_ALIGNMENT( 0, 0, 270)
67 #define CUSTOM_ALIGN_CW0_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 0)
68 #define CUSTOM_ALIGN_CW90_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 90)
69 #define CUSTOM_ALIGN_CW180_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 180)
70 #define CUSTOM_ALIGN_CW270_DEG_FLIP SENSOR_ALIGNMENT( 0, 180, 270)
72 void buildRotationMatrixFromAlignment(const sensorAlignment_t* alignment, fp_rotationMatrix_t* rm);
73 void buildAlignmentFromStandardAlignment(sensorAlignment_t* sensorAlignment, sensor_align_e alignment);