Change to new timer definitions
[inav.git] / src / main / flight / imu.h
blob7a07c4c287e624b6dedbe2b9d56500231f07b6c6
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/maths.h"
21 #include "common/time.h"
22 #include "config/parameter_group.h"
24 #define GRAVITY_CMSS 980.665f
26 extern int16_t throttleAngleCorrection;
27 extern int16_t smallAngle;
29 extern t_fp_vector imuMeasuredAccelBF; // cm/s/s
30 extern t_fp_vector imuMeasuredRotationBF; // rad/s
32 typedef union {
33 int16_t raw[XYZ_AXIS_COUNT];
34 struct {
35 // absolute angle inclination in multiple of 0.1 degree 180 deg = 1800
36 int16_t roll;
37 int16_t pitch;
38 int16_t yaw;
39 } values;
40 } attitudeEulerAngles_t;
42 extern attitudeEulerAngles_t attitude;
44 typedef struct imuConfig_s {
45 uint16_t dcm_kp_acc; // DCM filter proportional gain ( x 10000) for accelerometer
46 uint16_t dcm_ki_acc; // DCM filter integral gain ( x 10000) for accelerometer
47 uint16_t dcm_kp_mag; // DCM filter proportional gain ( x 10000) for magnetometer and GPS heading
48 uint16_t dcm_ki_mag; // DCM filter integral gain ( x 10000) for magnetometer and GPS heading
49 uint8_t small_angle;
50 } imuConfig_t;
52 PG_DECLARE(imuConfig_t, imuConfig);
54 typedef struct imuRuntimeConfig_s {
55 float dcm_kp_acc;
56 float dcm_ki_acc;
57 float dcm_kp_mag;
58 float dcm_ki_mag;
59 uint8_t small_angle;
60 } imuRuntimeConfig_t;
62 void imuConfigure(void);
64 void imuUpdateAttitude(timeUs_t currentTimeUs);
65 void imuUpdateAccelerometer(void);
66 void imuUpdateGyroscope(timeUs_t gyroUpdateDeltaUs);
67 float calculateCosTiltAngle(void);
68 bool isImuReady(void);
69 bool isImuHeadingValid(void);
71 void imuTransformVectorBodyToEarth(t_fp_vector * v);
72 void imuTransformVectorEarthToBody(t_fp_vector * v);
74 void imuInit(void);