NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
instruments.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../config/imu.h"
4 #include "imu.h"
5 #include "acceleration.h"
6 #include "gyro.h"
7 #include "compass.h"
8 #include "boardalignment.h"
9 #include "barometer.h"
10 
11 struct instruments {
12  struct ins_acc acc;
13  struct ins_gyro gyro;
14  struct ins_mag mag;
15  struct baro baro;
16  struct imu imu;
17 
22 
23  uint8_t sensors;
24 
25  const struct config *config;
26 };
27 
28 void ins_init(struct instruments *self, const struct config *config);
29 
30 void ins_start_gyro_calibration(struct instruments *self);
31 void ins_start_acc_calibration(struct instruments *self);
32 void ins_start_mag_calibration(struct instruments *self);
33 
34 bool ins_is_calibrated(struct instruments *self);
35 void ins_process_gyro(struct instruments *self, int32_t x, int32_t y, int32_t z);
36 void ins_process_acc(struct instruments *self, int32_t x, int32_t y, int32_t z);
37 void ins_process_mag(struct instruments *self, int32_t x, int32_t y, int32_t z);
38 
39 void ins_update(struct instruments *self, float dt);
40 
41 static inline void ins_reset_imu(struct instruments *self) { imu_reset(&self->imu); }
42 
43 static inline int16_t ins_get_acc_x(struct instruments *self){ return ins_acc_get_x(&self->acc); }
44 static inline int16_t ins_get_acc_y(struct instruments *self){ return ins_acc_get_y(&self->acc); }
45 static inline int16_t ins_get_acc_z(struct instruments *self){ return ins_acc_get_z(&self->acc); }
46 
47 static inline int32_t ins_get_gyro_x(struct instruments *self){ return ins_gyro_get_x(&self->gyro); }
48 static inline int32_t ins_get_gyro_y(struct instruments *self){ return ins_gyro_get_y(&self->gyro); }
49 static inline int32_t ins_get_gyro_z(struct instruments *self){ return ins_gyro_get_z(&self->gyro); }
50 
51 static inline int32_t ins_get_mag_x(struct instruments *self){ return ins_mag_get_x(&self->mag); }
52 static inline int32_t ins_get_mag_y(struct instruments *self){ return ins_mag_get_y(&self->mag); }
53 static inline int32_t ins_get_mag_z(struct instruments *self){ return ins_mag_get_z(&self->mag); }
54 
55 static inline int16_t ins_get_roll_dd(struct instruments *self){ return imu_get_roll_dd(&self->imu); }
56 static inline int16_t ins_get_pitch_dd(struct instruments *self){ return imu_get_pitch_dd(&self->imu); }
57 static inline int16_t ins_get_yaw_dd(struct instruments *self){ return imu_get_yaw_dd(&self->imu); }
58 
60 uint32_t ins_get_altitude_cm(struct instruments *self);
61 
63 int16_t ins_get_vertical_speed_cms(struct instruments *self);
64 
65 static inline void ins_set_gyro_alignment(struct instruments *self, sensor_align_e align) { self->gyr_align = align; }
66 static inline void ins_set_acc_alignment(struct instruments *self, sensor_align_e align) { self->acc_align = align; }
67 static inline void ins_set_mag_alignment(struct instruments *self, sensor_align_e align) { self->mag_align = align; }
68 
69 static inline void ins_set_gyro_filter_hz(struct instruments *self, uint16_t hz) { ins_gyro_set_filter_hz(&self->gyro, hz); }
void ins_process_acc(struct instruments *self, int32_t x, int32_t y, int32_t z)
Definition: instruments.c:126
sensor_align_e
Definition: sensors.h:34
Definition: config.h:81
struct ins_acc acc
Definition: instruments.h:12
int16_t imu_get_roll_dd(struct imu *self)
Definition: imu.c:438
int16_t imu_get_pitch_dd(struct imu *self)
Definition: imu.c:442
sensor_align_e acc_align
Definition: instruments.h:21
const struct config * config
Definition: instruments.h:25
struct board_alignment alignment
Definition: instruments.h:18
void ins_start_gyro_calibration(struct instruments *self)
Definition: instruments.c:94
Definition: compass.h:26
uint8_t sensors
Definition: instruments.h:23
Definition: gyro.h:26
void ins_process_mag(struct instruments *self, int32_t x, int32_t y, int32_t z)
Definition: instruments.c:140
Definition: imu.h:49
Definition: acceleration.h:25
void ins_gyro_set_filter_hz(struct ins_gyro *self, uint16_t hz)
Definition: gyro.c:95
bool ins_is_calibrated(struct instruments *self)
Definition: instruments.c:73
struct ins_gyro gyro
Definition: instruments.h:13
int16_t imu_get_yaw_dd(struct imu *self)
Definition: imu.c:446
void ins_start_mag_calibration(struct instruments *self)
Definition: instruments.c:98
int16_t ins_get_vertical_speed_cms(struct instruments *self)
returns vertical speed in cm/s
Definition: instruments.c:164
uint32_t ins_get_altitude_cm(struct instruments *self)
returns estimated altitude above sea level in cm
Definition: instruments.c:157
void ins_init(struct instruments *self, const struct config *config)
Initializes all instruments using specified configuration.
Definition: instruments.c:46
uint8_t z
set the acc deadband for z-Axis, this ignores small accelerations
Definition: accelerometer.h:52
Definition: boardalignment.h:22
struct ins_mag mag
Definition: instruments.h:14
void imu_reset(struct imu *self)
Definition: imu.c:94
sensor_align_e gyr_align
Definition: instruments.h:20
void ins_update(struct instruments *self, float dt)
Definition: instruments.c:147
void ins_start_acc_calibration(struct instruments *self)
Definition: instruments.c:90
sensor_align_e mag_align
Definition: instruments.h:19
Definition: barometer.h:33
void ins_process_gyro(struct instruments *self, int32_t x, int32_t y, int32_t z)
Definition: instruments.c:102
Definition: instruments.h:11