Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
imu_bmi088_i2c.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
28 #include "subsystems/imu.h"
29 #include "mcu_periph/i2c.h"
30 #include "mcu_periph/sys_time.h"
31 #include "subsystems/abi.h"
32 
33 PRINT_CONFIG_VAR(IMU_BMI088_GYRO_RANGE)
34 PRINT_CONFIG_VAR(IMU_BMI088_ACCEL_RANGE)
35 
36 #ifndef IMU_BMI088_GYRO_ODR
37 #define IMU_BMI088_GYRO_ODR BMI088_GYRO_ODR_1000_BW_116
38 #endif
39 PRINT_CONFIG_VAR(IMU_BMI088_GYRO_ODR)
40 
41 #ifndef IMU_BMI088_ACCEL_ODR
42 #define IMU_BMI088_ACCEL_ODR BMI088_ACCEL_ODR_1600
43 #endif
44 PRINT_CONFIG_VAR(IMU_BMI088_ACCEL_ODR)
45 
46 #ifndef IMU_BMI088_ACCEL_BW
47 #define IMU_BMI088_ACCEL_BW BMI088_ACCEL_BW_OSR4
48 #endif
49 PRINT_CONFIG_VAR(IMU_BMI088_ACCEL_BW)
50 
51 #ifndef IMU_BMI088_GYRO_I2C_ADDR
52 #define IMU_BMI088_GYRO_I2C_ADDR BMI088_GYRO_ADDR
53 #endif
54 PRINT_CONFIG_VAR(IMU_BMI088_GYRO_I2C_ADDR)
55 
56 #ifndef IMU_BMI088_ACCEL_I2C_ADDR
57 #define IMU_BMI088_ACCEL_I2C_ADDR BMI088_ACCEL_ADDR
58 #endif
59 PRINT_CONFIG_VAR(IMU_BMI088_ACCEL_I2C_ADDR)
60 
61 // Default channels order
62 #ifndef IMU_BMI088_CHAN_X
63 #define IMU_BMI088_CHAN_X 0
64 #endif
65 PRINT_CONFIG_VAR(IMU_BMI088_CHAN_X)
66 #ifndef IMU_BMI088_CHAN_Y
67 #define IMU_BMI088_CHAN_Y 1
68 #endif
69 PRINT_CONFIG_VAR(IMU_BMI088_CHAN_Y)
70 #ifndef IMU_BMI088_CHAN_Z
71 #define IMU_BMI088_CHAN_Z 2
72 #endif
73 PRINT_CONFIG_VAR(IMU_BMI088_CHAN_Z)
74 
75 #ifndef IMU_BMI088_X_SIGN
76 #define IMU_BMI088_X_SIGN 1
77 #endif
78 PRINT_CONFIG_VAR(IMU_BMI088_X_SIGN)
79 #ifndef IMU_BMI088_Y_SIGN
80 #define IMU_BMI088_Y_SIGN 1
81 #endif
82 PRINT_CONFIG_VAR(IMU_BMI088_Y_SIGN)
83 #ifndef IMU_BMI088_Z_SIGN
84 #define IMU_BMI088_Z_SIGN 1
85 #endif
86 PRINT_CONFIG_VAR(IMU_BMI088_Z_SIGN)
87 
88 
90 
91 void imu_bmi088_init(void)
92 {
93  /* BMI088 */
95  // change the default configuration
101 }
102 
104 {
106 }
107 
109 {
110  uint32_t now_ts = get_sys_time_usec();
111 
112  // If the BMI088 I2C transaction has succeeded: convert the data
114 
116  struct Int32Rates rates = {
120  };
121  // unscaled vector
122  RATES_COPY(imu.gyro_unscaled, rates);
123 
124  imu_bmi088.bmi.gyro_available = false;
125 
127  AbiSendMsgIMU_GYRO_INT32(IMU_BMI088_ID, now_ts, &imu.gyro);
128  }
130  // set channel order
131  struct Int32Vect3 accel = {
135  };
136  // unscaled vector
137  VECT3_COPY(imu.accel_unscaled, accel);
138 
140 
142  AbiSendMsgIMU_ACCEL_INT32(IMU_BMI088_ID, now_ts, &imu.accel);
143  }
144 }
145 
Imu::gyro_unscaled
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:46
IMU_BMI088_CHAN_X
#define IMU_BMI088_CHAN_X
Definition: imu_bmi088_i2c.c:63
IMU_BMI088_GYRO_I2C_ADDR
#define IMU_BMI088_GYRO_I2C_ADDR
Definition: imu_bmi088_i2c.c:52
IMU_BMI088_Y_SIGN
#define IMU_BMI088_Y_SIGN
Definition: imu_bmi088_i2c.c:80
Bmi088_I2c::config
struct Bmi088Config config
Definition: bmi088_i2c.h:51
Bmi088Config::accel_bw
enum Bmi088AccelBW accel_bw
bandwidth
Definition: bmi088.h:118
Int32Rates
angular rates
Definition: pprz_algebra_int.h:179
bmi088_i2c_init
void bmi088_i2c_init(struct Bmi088_I2c *bmi, struct i2c_periph *i2c_p, uint8_t gyro_addr, uint8_t accel_addr)
Definition: bmi088_i2c.c:30
abi.h
Imu::accel
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:39
Bmi088_I2c::accel_available
volatile bool accel_available
accel data ready flag
Definition: bmi088_i2c.h:42
bmi088_i2c_periodic
static void bmi088_i2c_periodic(struct Bmi088_I2c *bmi)
convenience function: read or start configuration if not already initialized
Definition: bmi088_i2c.h:61
Bmi088_I2c::data_accel
union Bmi088_I2c::@308 data_accel
uint32_t
unsigned long uint32_t
Definition: types.h:18
imu_bmi088_periodic
void imu_bmi088_periodic(void)
Definition: imu_bmi088_i2c.c:103
Bmi088Config::gyro_range
enum Bmi088GyroRanges gyro_range
deg/s Range
Definition: bmi088.h:114
Bmi088_I2c::data_rates
union Bmi088_I2c::@309 data_rates
imu_bmi088
struct ImuBmi088 imu_bmi088
Definition: imu_bmi088_i2c.c:89
Imu::accel_unscaled
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:47
IMU_BMI088_X_SIGN
#define IMU_BMI088_X_SIGN
Definition: imu_bmi088_i2c.c:76
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
ImuBmi088::bmi
struct Bmi088_I2c bmi
Definition: imu_bmi088_i2c.h:74
IMU_BMI088_ACCEL_I2C_ADDR
#define IMU_BMI088_ACCEL_I2C_ADDR
Definition: imu_bmi088_i2c.c:57
imu.h
ImuBmi088
Definition: imu_bmi088_i2c.h:73
IMU_BMI088_CHAN_Y
#define IMU_BMI088_CHAN_Y
Definition: imu_bmi088_i2c.c:67
Bmi088Config::accel_odr
enum Bmi088AccelODR accel_odr
output data rate
Definition: bmi088.h:117
IMU_BMI088_GYRO_RANGE
#define IMU_BMI088_GYRO_RANGE
Definition: imu_bmi088_i2c.h:39
bmi088_i2c_event
void bmi088_i2c_event(struct Bmi088_I2c *bmi)
Definition: bmi088_i2c.c:93
Int32Vect3
Definition: pprz_algebra_int.h:88
sys_time.h
Architecture independent timing functions.
imu_scale_gyro
void imu_scale_gyro(struct Imu *_imu)
Definition: imu_vectornav.c:43
IMU_BMI088_ACCEL_RANGE
#define IMU_BMI088_ACCEL_RANGE
Definition: imu_bmi088_i2c.h:43
Bmi088_I2c::gyro_available
volatile bool gyro_available
gyro data ready flag
Definition: bmi088_i2c.h:41
imu
struct Imu imu
global IMU state
Definition: imu.c:108
Bmi088Config::gyro_odr
enum Bmi088GyroODR gyro_odr
output data rate
Definition: bmi088.h:115
IMU_BMI088_ACCEL_BW
#define IMU_BMI088_ACCEL_BW
Definition: imu_bmi088_i2c.c:47
imu_bmi088_init
void imu_bmi088_init(void)
Definition: imu_bmi088_i2c.c:91
IMU_BMI088_CHAN_Z
#define IMU_BMI088_CHAN_Z
Definition: imu_bmi088_i2c.c:71
int32_t
signed long int32_t
Definition: types.h:19
IMU_BMI088_ID
#define IMU_BMI088_ID
Definition: abi_sender_ids.h:347
Bmi088Config::accel_range
enum Bmi088AccelRanges accel_range
g Range
Definition: bmi088.h:116
RATES_COPY
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:337
IMU_BMI088_GYRO_ODR
#define IMU_BMI088_GYRO_ODR
Definition: imu_bmi088_i2c.c:37
imu_bmi088_event
void imu_bmi088_event(void)
Definition: imu_bmi088_i2c.c:108
IMU_BMI088_Z_SIGN
#define IMU_BMI088_Z_SIGN
Definition: imu_bmi088_i2c.c:84
i2c.h
imu_scale_accel
void imu_scale_accel(struct Imu *_imu)
Definition: imu_vectornav.c:44
VECT3_COPY
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:140
IMU_BMI088_ACCEL_ODR
#define IMU_BMI088_ACCEL_ODR
Definition: imu_bmi088_i2c.c:42
Imu::gyro
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:38