NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gyro.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight 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.
8  *
9  * Ninjaflight 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include "drivers/accgyro.h"
21 #include "../common/filter.h"
22 #include "../common/maths.h"
23 #include "../config/gyro.h"
24 #include "../config/sensors.h"
25 
26 struct ins_gyro {
28 
30 
31  uint16_t calibratingG;
33 
35  bool use_filter;
36 
37  int32_t g[3];
39 
40  const struct gyro_config *config;
41 };
42 
43 void ins_gyro_init(struct ins_gyro *self, const struct gyro_config *config);
44 void ins_gyro_process_sample(struct ins_gyro *self, int32_t x, int32_t y, int32_t z);
45 void ins_gyro_calibrate(struct ins_gyro *self);
46 bool ins_gyro_is_calibrated(struct ins_gyro *self);
47 
48 static inline int32_t ins_gyro_get_x(struct ins_gyro *self) { return self->gyroADC[X]; }
49 static inline int32_t ins_gyro_get_y(struct ins_gyro *self) { return self->gyroADC[Y]; }
50 static inline int32_t ins_gyro_get_z(struct ins_gyro *self) { return self->gyroADC[Z]; }
51 
52 void ins_gyro_set_filter_hz(struct ins_gyro *self, uint16_t hz);
#define XYZ_AXIS_COUNT
Definition: axis.h:26
sensor_align_e
Definition: sensors.h:34
Definition: config.h:81
void ins_gyro_set_filter_hz(struct ins_gyro *self, uint16_t hz)
Definition: gyro.c:95
sensor_align_e align
Definition: gyro.h:27
stdev_t var[3]
Definition: gyro.h:38
void ins_gyro_calibrate(struct ins_gyro *self)
Definition: gyro.c:106
uint16_t calibratingG
Definition: gyro.h:31
Definition: gyro.h:26
Definition: axis.h:23
void ins_gyro_init(struct ins_gyro *self, const struct gyro_config *config)
Definition: gyro.c:40
const struct gyro_config * config
Definition: gyro.h:40
biquad_t gyroFilterState[3]
Definition: gyro.h:34
int32_t gyroZero[XYZ_AXIS_COUNT]
Definition: gyro.h:32
bool use_filter
Definition: gyro.h:35
uint8_t z
set the acc deadband for z-Axis, this ignores small accelerations
Definition: accelerometer.h:52
bool ins_gyro_is_calibrated(struct ins_gyro *self)
Definition: gyro.c:115
Definition: axis.h:21
Definition: gyro.h:24
int32_t gyroADC[XYZ_AXIS_COUNT]
Definition: gyro.h:29
Definition: axis.h:22
int32_t g[3]
Definition: gyro.h:37
Definition: maths.h:39
Definition: filter.h:27
void ins_gyro_process_sample(struct ins_gyro *self, int32_t x, int32_t y, int32_t z)
Definition: gyro.c:76