Modify STM32F405 UID Address for MSC Enumeration (#13769)
[betaflight.git] / src / main / flight / imu.h
blob8dd758dd063e35e6239ba42dad0af7baf0dd2acf
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 "common/axis.h"
24 #include "common/time.h"
25 #include "common/maths.h"
26 #include "pg/pg.h"
28 // Exported symbols
29 extern bool canUseGPSHeading;
31 typedef struct {
32 float w,x,y,z;
33 } quaternion;
34 #define QUATERNION_INITIALIZE {.w=1, .x=0, .y=0,.z=0}
36 typedef struct {
37 float ww,wx,wy,wz,xx,xy,xz,yy,yz,zz;
38 } quaternionProducts;
39 #define QUATERNION_PRODUCTS_INITIALIZE {.ww=1, .wx=0, .wy=0, .wz=0, .xx=0, .xy=0, .xz=0, .yy=0, .yz=0, .zz=0}
41 typedef union {
42 int16_t raw[XYZ_AXIS_COUNT];
43 struct {
44 // absolute angle inclination in multiple of 0.1 degree 180 deg = 1800
45 int16_t roll;
46 int16_t pitch;
47 int16_t yaw;
48 } values;
49 } attitudeEulerAngles_t;
50 #define EULER_INITIALIZE { { 0, 0, 0 } }
52 extern attitudeEulerAngles_t attitude;
53 extern float rMat[3][3];
55 typedef struct imuConfig_s {
56 uint16_t imu_dcm_kp; // DCM filter proportional gain ( x 10000)
57 uint16_t imu_dcm_ki; // DCM filter integral gain ( x 10000)
58 uint8_t small_angle;
59 uint8_t imu_process_denom;
60 uint16_t mag_declination; // Magnetic declination in degrees * 10
61 } imuConfig_t;
63 PG_DECLARE(imuConfig_t, imuConfig);
65 typedef struct imuRuntimeConfig_s {
66 float imuDcmKi;
67 float imuDcmKp;
68 } imuRuntimeConfig_t;
70 void imuConfigure(uint16_t throttle_correction_angle, uint8_t throttle_correction_value);
72 float getSinPitchAngle(void);
73 float getCosTiltAngle(void);
74 void getQuaternion(quaternion * q);
75 void imuUpdateAttitude(timeUs_t currentTimeUs);
77 void imuInit(void);
79 #ifdef SIMULATOR_BUILD
80 void imuSetAttitudeRPY(float roll, float pitch, float yaw); // in deg
81 void imuSetAttitudeQuat(float w, float x, float y, float z);
82 #if defined(SIMULATOR_IMU_SYNC)
83 void imuSetHasNewData(uint32_t dt);
84 #endif
85 #endif
87 bool imuQuaternionHeadfreeOffsetSet(void);
88 void imuQuaternionHeadfreeTransformVectorEarthToBody(t_fp_vector_def * v);
89 bool shouldInitializeGPSHeading(void);
90 bool isUpright(void);