Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
27
29#include "modules/imu/imu.h"
30#include "mcu_periph/i2c.h"
31#include "mcu_periph/sys_time.h"
32#include "modules/core/abi.h"
33
36
37#ifndef IMU_BMI088_GYRO_ODR
38#define IMU_BMI088_GYRO_ODR BMI088_GYRO_ODR_1000_BW_116
39#endif
41
42#ifndef IMU_BMI088_ACCEL_ODR
43#define IMU_BMI088_ACCEL_ODR BMI088_ACCEL_ODR_1600
44#endif
46
47#ifndef IMU_BMI088_ACCEL_BW
48#define IMU_BMI088_ACCEL_BW BMI088_ACCEL_BW_OSR4
49#endif
51
52#ifndef IMU_BMI088_GYRO_I2C_ADDR
53#define IMU_BMI088_GYRO_I2C_ADDR BMI088_GYRO_ADDR
54#endif
56
57#ifndef IMU_BMI088_ACCEL_I2C_ADDR
58#define IMU_BMI088_ACCEL_I2C_ADDR BMI088_ACCEL_ADDR
59#endif
61
62// Default channels order
63#ifndef IMU_BMI088_CHAN_X
64#define IMU_BMI088_CHAN_X 0
65#endif
67#ifndef IMU_BMI088_CHAN_Y
68#define IMU_BMI088_CHAN_Y 1
69#endif
71#ifndef IMU_BMI088_CHAN_Z
72#define IMU_BMI088_CHAN_Z 2
73#endif
75
76#ifndef IMU_BMI088_X_SIGN
77#define IMU_BMI088_X_SIGN 1
78#endif
80#ifndef IMU_BMI088_Y_SIGN
81#define IMU_BMI088_Y_SIGN 1
82#endif
84#ifndef IMU_BMI088_Z_SIGN
85#define IMU_BMI088_Z_SIGN 1
86#endif
88
89
91
93{
94 /* BMI088 */
96 // change the default configuration
97 imu_bmi088.bmi.config.gyro_range = IMU_BMI088_GYRO_RANGE;
98 imu_bmi088.bmi.config.gyro_odr = IMU_BMI088_GYRO_ODR;
99 imu_bmi088.bmi.config.accel_range = IMU_BMI088_ACCEL_RANGE;
100 imu_bmi088.bmi.config.accel_odr = IMU_BMI088_ACCEL_ODR;
101 imu_bmi088.bmi.config.accel_bw = IMU_BMI088_ACCEL_BW;
102
103 // Set the default scaling
106}
107
109{
111}
112
114{
115 uint32_t now_ts = get_sys_time_usec();
116
117 // If the BMI088 I2C transaction has succeeded: convert the data
119
120 if (imu_bmi088.bmi.gyro_available) {
121 struct Int32Rates rates = {
122 IMU_BMI088_X_SIGN *(int32_t)(imu_bmi088.bmi.data_rates.value[IMU_BMI088_CHAN_X]),
123 IMU_BMI088_Y_SIGN *(int32_t)(imu_bmi088.bmi.data_rates.value[IMU_BMI088_CHAN_Y]),
124 IMU_BMI088_Z_SIGN *(int32_t)(imu_bmi088.bmi.data_rates.value[IMU_BMI088_CHAN_Z])
125 };
126
127 imu_bmi088.bmi.gyro_available = false;
128 AbiSendMsgIMU_GYRO_RAW(IMU_BMI088_ID, now_ts, &rates, 1, imu_bmi088.bmi.config.gyro_samplerate, NAN);
129 }
130 if (imu_bmi088.bmi.accel_available) {
131 // set channel order
132 struct Int32Vect3 accel = {
133 IMU_BMI088_X_SIGN *(int32_t)(imu_bmi088.bmi.data_accel.value[IMU_BMI088_CHAN_X]),
134 IMU_BMI088_Y_SIGN *(int32_t)(imu_bmi088.bmi.data_accel.value[IMU_BMI088_CHAN_Y]),
135 IMU_BMI088_Z_SIGN *(int32_t)(imu_bmi088.bmi.data_accel.value[IMU_BMI088_CHAN_Z])
136 };
137
138 imu_bmi088.bmi.accel_available = false;
139 AbiSendMsgIMU_ACCEL_RAW(IMU_BMI088_ID, now_ts, &accel, 1, imu_bmi088.bmi.config.accel_samplerate, NAN);
140 }
141}
142
Main include for ABI (AirBorneInterface).
#define IMU_BMI088_ID
const struct FloatRates BMI088_GYRO_SENS_F[5]
Definition bmi088.c:39
const struct FloatVect3 BMI088_ACCEL_SENS_F[4]
Definition bmi088.c:54
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
void bmi088_i2c_event(struct Bmi088_I2c *bmi)
Definition bmi088_i2c.c:93
static void bmi088_i2c_periodic(struct Bmi088_I2c *bmi)
convenience function: read or start configuration if not already initialized
Definition bmi088_i2c.h:61
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
angular rates
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct FloatRates *scale_f)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition imu.c:842
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition imu.c:871
Inertial Measurement Unit interface.
#define IMU_BMI088_ACCEL_I2C_ADDR
#define IMU_BMI088_Z_SIGN
void imu_bmi088_init(void)
#define IMU_BMI088_Y_SIGN
#define IMU_BMI088_ACCEL_BW
void imu_bmi088_event(void)
#define IMU_BMI088_X_SIGN
#define IMU_BMI088_CHAN_Y
#define IMU_BMI088_ACCEL_ODR
struct ImuBmi088 imu_bmi088
#define IMU_BMI088_GYRO_I2C_ADDR
void imu_bmi088_periodic(void)
#define IMU_BMI088_CHAN_Z
#define IMU_BMI088_CHAN_X
#define IMU_BMI088_GYRO_ODR
IMU driver for the BMI088 using I2C.
#define IMU_BMI088_GYRO_RANGE
#define IMU_BMI088_ACCEL_RANGE
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Architecture independent timing functions.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.