Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / flight / imu.h
blob8afcc50e57954edc2a97f921e8943cb528ef5f8b
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include "common/axis.h"
21 #include "common/maths.h"
22 #include "common/vector.h"
23 #include "common/quaternion.h"
24 #include "common/time.h"
25 #include "config/parameter_group.h"
27 extern fpVector3_t imuMeasuredAccelBF; // cm/s/s
28 extern fpVector3_t imuMeasuredRotationBF; // rad/s
29 extern fpVector3_t imuMeasuredRotationBFFiltered; // rad/s
30 extern fpVector3_t compansatedGravityBF; // cm/s/s
31 extern fpVector3_t HeadVecEFFiltered;
33 typedef union {
34 int16_t raw[XYZ_AXIS_COUNT];
35 struct {
36 // absolute angle inclination in multiple of 0.1 degree 180 deg = 1800
37 int16_t roll;
38 int16_t pitch;
39 int16_t yaw;
40 } values;
41 } attitudeEulerAngles_t;
43 extern fpQuaternion_t orientation;
44 extern attitudeEulerAngles_t attitude;
45 extern float rMat[3][3];
47 typedef struct imuConfig_s {
48 uint16_t dcm_kp_acc; // DCM filter proportional gain ( x 10000) for accelerometer
49 uint16_t dcm_ki_acc; // DCM filter integral gain ( x 10000) for accelerometer
50 uint16_t dcm_kp_mag; // DCM filter proportional gain ( x 10000) for magnetometer and GPS heading
51 uint16_t dcm_ki_mag; // DCM filter integral gain ( x 10000) for magnetometer and GPS heading
52 uint8_t small_angle;
53 uint8_t acc_ignore_rate;
54 uint8_t acc_ignore_slope;
55 uint8_t gps_yaw_windcomp;
56 uint8_t inertia_comp_method;
57 uint16_t gps_yaw_weight;
58 } imuConfig_t;
60 PG_DECLARE(imuConfig_t, imuConfig);
62 typedef struct imuRuntimeConfig_s {
63 float dcm_kp_acc;
64 float dcm_ki_acc;
65 float dcm_kp_mag;
66 float dcm_ki_mag;
67 uint8_t small_angle;
68 } imuRuntimeConfig_t;
70 typedef enum
72 COMPMETHOD_VELNED = 0,
73 COMPMETHOD_TURNRATE,
74 COMPMETHOD_ADAPTIVE
75 } imu_inertia_comp_method_e;
77 void imuConfigure(void);
79 void imuSetMagneticDeclination(float declinationDeg);
80 void imuUpdateAttitude(timeUs_t currentTimeUs);
81 void imuUpdateAccelerometer(void);
82 float calculateCosTiltAngle(void);
83 bool isImuReady(void);
84 bool isImuHeadingValid(void);
86 void imuTransformVectorBodyToEarth(fpVector3_t * v);
87 void imuTransformVectorEarthToBody(fpVector3_t * v);
89 void imuInit(void);
91 #if defined(SITL_BUILD)
92 void imuSetAttitudeRPY(int16_t roll, int16_t pitch, int16_t yaw);
93 #endif