Fix pt2 and pt3 filter initialization in gyro_init.c (#13960)
[betaflight.git] / src / main / common / sensor_alignment.c
blob47267c319a396b2623ab1ee3aca5bcffd618bc6a
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);
43 void buildAlignmentFromStandardAlignment(sensorAlignment_t* rpy, sensor_align_e stdAlignment)
45 if (stdAlignment == ALIGN_CUSTOM || stdAlignment == ALIGN_DEFAULT) {
46 return;
49 uint8_t alignmentBits = ALIGNMENT_TO_BITMASK(stdAlignment);
51 memset(rpy, 0x00, sizeof(sensorAlignment_t));
53 for (int axis = 0; axis < FLIGHT_DYNAMICS_INDEX_COUNT; axis++) {
54 rpy->raw[axis] = DEGREES_TO_DECIDEGREES(90) * ALIGNMENT_AXIS_ROTATIONS(alignmentBits, axis);