Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 */
94  bmi088_i2c_init(&imu_bmi088.bmi, &(IMU_BMI088_I2C_DEV), IMU_BMI088_GYRO_I2C_ADDR, IMU_BMI088_ACCEL_I2C_ADDR);
95  // change the default configuration
100  imu_bmi088.bmi.config.accel_bw = IMU_BMI088_ACCEL_BW;
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 
struct ImuBmi088 imu_bmi088
void imu_bmi088_periodic(void)
angular rates
#define IMU_BMI088_ACCEL_I2C_ADDR
enum Bmi088GyroRanges gyro_range
deg/s Range
Definition: bmi088.h:114
struct Bmi088Config config
Definition: bmi088_i2c.h:51
enum Bmi088AccelRanges accel_range
g Range
Definition: bmi088.h:116
#define IMU_BMI088_GYRO_ODR
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
struct Bmi088_I2c bmi
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:140
enum Bmi088AccelODR accel_odr
output data rate
Definition: bmi088.h:117
Main include for ABI (AirBorneInterface).
#define IMU_BMI088_GYRO_RANGE
union Bmi088_I2c::@307 data_accel
#define IMU_BMI088_Y_SIGN
struct Imu imu
global IMU state
Definition: imu.c:108
union Bmi088_I2c::@308 data_rates
#define IMU_BMI088_CHAN_Z
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:46
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:39
#define IMU_BMI088_ACCEL_BW
void imu_bmi088_init(void)
Architecture independent timing functions.
unsigned long uint32_t
Definition: types.h:18
void imu_bmi088_event(void)
#define IMU_BMI088_Z_SIGN
#define IMU_BMI088_X_SIGN
Inertial Measurement Unit interface.
void imu_scale_gyro(struct Imu *_imu)
Definition: imu_vectornav.c:43
static void bmi088_i2c_periodic(struct Bmi088_I2c *bmi)
convenience function: read or start configuration if not already initialized
Definition: bmi088_i2c.h:61
signed long int32_t
Definition: types.h:19
#define IMU_BMI088_CHAN_Y
#define IMU_BMI088_CHAN_X
#define IMU_BMI088_ID
#define IMU_BMI088_ACCEL_ODR
volatile bool gyro_available
gyro data ready flag
Definition: bmi088_i2c.h:41
#define IMU_BMI088_GYRO_I2C_ADDR
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:47
#define IMU_BMI088_ACCEL_RANGE
void imu_scale_accel(struct Imu *_imu)
Definition: imu_vectornav.c:44
enum Bmi088AccelBW accel_bw
bandwidth
Definition: bmi088.h:118
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:337
volatile bool accel_available
accel data ready flag
Definition: bmi088_i2c.h:42
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
void bmi088_i2c_event(struct Bmi088_I2c *bmi)
Definition: bmi088_i2c.c:93
enum Bmi088GyroODR gyro_odr
output data rate
Definition: bmi088.h:115
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:38
Architecture independent I2C (Inter-Integrated Circuit Bus) API.