NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
compass.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 // TODO: remove dependency on compass
21 #include "drivers/compass.h"
22 #include "../common/axis.h"
23 #include "../config/sensors.h"
24 #include "../config/compass.h"
25 
26 struct ins_mag {
28 
30 
31  float mag_scale[3];
32  int16_t mag_max[3];
33  int16_t mag_min[3];
34 
35  const struct mag_config *config;
36 
38 
39  int16_t calibratingM;
40 };
41 
42 void ins_mag_init(struct ins_mag *self, const struct mag_config *config, const struct sensor_trims_config *trims);
43 void ins_mag_process_sample(struct ins_mag *self, int32_t x, int32_t y, int32_t z);
44 
45 void ins_mag_save_trims(const struct ins_mag *self, struct config *config);
46 
47 void ins_mag_start_calibration(struct ins_mag *self);
48 static inline bool ins_mag_is_calibrated(struct ins_mag *self) { return self->calibratingM == 0; }
49 
50 static inline int32_t ins_mag_get_x(struct ins_mag *self) { return self->magADC[X]; }
51 static inline int32_t ins_mag_get_y(struct ins_mag *self) { return self->magADC[Y]; }
52 static inline int32_t ins_mag_get_z(struct ins_mag *self) { return self->magADC[Z]; }
#define XYZ_AXIS_COUNT
Definition: axis.h:26
Definition: config.h:81
void ins_mag_save_trims(const struct ins_mag *self, struct config *config)
Definition: compass.c:64
int16_t mag_min[3]
Definition: compass.h:33
Definition: compass.h:26
int16_t mag_max[3]
Definition: compass.h:32
const struct mag_config * config
Definition: compass.h:35
Definition: axis.h:23
void ins_mag_init(struct ins_mag *self, const struct mag_config *config, const struct sensor_trims_config *trims)
Definition: compass.c:39
Definition: compass.h:24
int16_t calibratingM
Definition: compass.h:39
struct sensor_trims_config trims
Definition: compass.h:37
uint8_t z
set the acc deadband for z-Axis, this ignores small accelerations
Definition: accelerometer.h:52
Definition: sensors.h:69
Definition: axis.h:21
rollAndPitchTrims_t trims
accelerometer trim
Definition: accelerometer.h:51
void ins_mag_start_calibration(struct ins_mag *self)
Definition: compass.c:55
void ins_mag_process_sample(struct ins_mag *self, int32_t x, int32_t y, int32_t z)
Definition: compass.c:68
float mag_scale[3]
Definition: compass.h:31
int32_t magADC[XYZ_AXIS_COUNT]
Definition: compass.h:27
float magneticDeclination
Definition: compass.h:29
Definition: axis.h:22