Position hold depends on GPS (#14101)
[betaflight.git] / src / main / common / sensor_alignment.c
blobe19365cfcdd77b1c147f292b05a7663199a6d63a
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 #include <stdbool.h>
22 #include <string.h>
24 #include "platform.h"
26 #include "build/build_config.h"
28 #include "common/sensor_alignment.h"
29 #include "common/sensor_alignment_impl.h"
30 #include "common/vector.h"
32 void buildRotationMatrixFromAngles(matrix33_t *rm, const sensorAlignment_t *rpy)
34 fp_angles_t rotationAngles;
35 rotationAngles.angles.roll = DECIDEGREES_TO_RADIANS(rpy->roll);
36 rotationAngles.angles.pitch = DECIDEGREES_TO_RADIANS(rpy->pitch);
37 rotationAngles.angles.yaw = DECIDEGREES_TO_RADIANS(rpy->yaw);
39 buildRotationMatrix(rm, &rotationAngles);
42 void buildAlignmentFromStandardAlignment(sensorAlignment_t* rpy, sensor_align_e stdAlignment)
44 if (stdAlignment == ALIGN_CUSTOM || stdAlignment == ALIGN_DEFAULT) {
45 return;
48 uint8_t alignmentBits = ALIGNMENT_TO_BITMASK(stdAlignment);
50 memset(rpy, 0x00, sizeof(sensorAlignment_t));
52 for (int axis = 0; axis < FLIGHT_DYNAMICS_INDEX_COUNT; axis++) {
53 rpy->raw[axis] = DEGREES_TO_DECIDEGREES(90) * ALIGNMENT_AXIS_ROTATIONS(alignmentBits, axis);