Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_bebop.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van Tienen <freek.v.tienen@gmail.com>
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #include "subsystems/imu.h"
28 #include "subsystems/abi.h"
29 #include "mcu_periph/i2c.h"
30 
31 
32 /* defaults suitable for Bebop */
33 #ifndef BEBOP_MAG_I2C_DEV
34 #define BEBOP_MAG_I2C_DEV i2c1
35 #endif
36 PRINT_CONFIG_VAR(BEBOP_MAG_I2C_DEV)
37 
38 #ifndef BEBOP_MPU_I2C_DEV
39 #define BEBOP_MPU_I2C_DEV i2c2
40 #endif
41 PRINT_CONFIG_VAR(BEBOP_MPU_I2C_DEV)
42 
43 #if !defined BEBOP_LOWPASS_FILTER && !defined BEBOP_SMPLRT_DIV
44 #if (PERIODIC_FREQUENCY == 60) || (PERIODIC_FREQUENCY == 120)
45 /* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
46  * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
47  */
48 #define BEBOP_LOWPASS_FILTER MPU60X0_DLPF_42HZ
49 #define BEBOP_SMPLRT_DIV 9
50 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
51 #elif PERIODIC_FREQUENCY == 512
52 /* Accelerometer: Bandwidth 260Hz, Delay 0ms
53  * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
54  */
55 #define BEBOP_LOWPASS_FILTER MPU60X0_DLPF_256HZ
56 #define BEBOP_SMPLRT_DIV 3
57 PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
58 #endif
59 #endif
60 PRINT_CONFIG_VAR(BEBOP_SMPLRT_DIV)
61 PRINT_CONFIG_VAR(BEBOP_LOWPASS_FILTER)
62 
63 #ifndef BEBOP_GYRO_RANGE
64 #define BEBOP_GYRO_RANGE MPU60X0_GYRO_RANGE_1000
65 #endif
66 PRINT_CONFIG_VAR(BEBOP_GYRO_RANGE)
67 
68 #ifndef BEBOP_ACCEL_RANGE
69 #define BEBOP_ACCEL_RANGE MPU60X0_ACCEL_RANGE_8G
70 #endif
71 PRINT_CONFIG_VAR(BEBOP_ACCEL_RANGE)
72 
73 
75 
79 void imu_impl_init(void)
80 {
81  /* MPU-60X0 */
83  imu_bebop.mpu.config.smplrt_div = BEBOP_SMPLRT_DIV;
84  imu_bebop.mpu.config.dlpf_cfg = BEBOP_LOWPASS_FILTER;
87 
88  /* AKM8963 */
90 }
91 
96 void imu_periodic(void)
97 {
98  // Start reading the latest gyroscope data
100 
101  // AKM8963
103 }
104 
109 void imu_bebop_event(void)
110 {
111  uint32_t now_ts = get_sys_time_usec();
112 
113  /* MPU-60x0 event taks */
115 
117  /* default orientation of the MPU is upside down sor corrigate this here */
119  -imu_bebop.mpu.data_rates.rates.r);
121  -imu_bebop.mpu.data_accel.vect.z);
122 
126  AbiSendMsgIMU_GYRO_INT32(IMU_BOARD_ID, now_ts, &imu.gyro);
127  AbiSendMsgIMU_ACCEL_INT32(IMU_BOARD_ID, now_ts, &imu.accel);
128  }
129 
130  /* AKM8963 event task */
132 
134 #if BEBOP_VERSION2
135  // In the second bebop version the magneto is turned 90 degrees
137 #else //BEBOP regular first verion
139 #endif
140 
142  imu_scale_mag(&imu);
143  AbiSendMsgIMU_MAG_INT32(IMU_BOARD_ID, now_ts, &imu.mag);
144  }
145 }
void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
Definition: mpu60x0_i2c.c:82
void imu_scale_gyro(struct Imu *_imu)
Definition: ahrs_gx3.c:349
#define IMU_BOARD_ID
struct Mpu60x0_I2c mpu
The MPU gyro/accel device.
Definition: imu_bebop.h:74
void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu60x0_i2c.c:31
void imu_scale_accel(struct Imu *_imu)
Definition: ahrs_gx3.c:350
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
union Mpu60x0_I2c::@41 data_accel
void imu_impl_init(void)
Navstik IMU initializtion of the MPU-60x0 and HMC58xx.
Definition: imu_bebop.c:79
struct ImuBebop imu_bebop
Basic Navstik IMU data.
Definition: imu_bebop.c:74
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:124
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:329
Main include for ABI (AirBorneInterface).
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:74
#define BEBOP_MPU_I2C_DEV
Definition: imu_bebop.c:39
#define AK8963_ADDR
Definition: ak8963_regs.h:31
void ak8963_init(struct Ak8963 *ak, struct i2c_periph *i2c_p, uint8_t addr)
Initialize AK8963 struct.
Definition: ak8963.c:34
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:76
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:77
union Mpu60x0_I2c::@42 data_rates
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:75
#define FALSE
Definition: std.h:5
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.h:39
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:52
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:50
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:43
void imu_bebop_event(void)
Handle all the events of the Navstik IMU components.
Definition: imu_bebop.c:109
volatile bool_t data_available
data ready flag
Definition: ak8963.h:61
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:43
unsigned long uint32_t
Definition: types.h:18
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
struct Int32Vect3 mag
magnetometer measurements scaled to 1 in BFP with INT32_MAG_FRAC
Definition: imu.h:44
Inertial Measurement Unit interface.
#define MPU60X0_ADDR
Definition: mpu60x0_regs.h:32
void imu_periodic(void)
Handle all the periodic tasks of the Navstik IMU components.
Definition: imu_bebop.c:96
void ak8963_event(struct Ak8963 *ak)
Definition: ak8963.c:95
void imu_scale_mag(struct Imu *_imu)
Definition: ahrs_gx3.c:351
static void ak8963_periodic(struct Ak8963 *ak)
convenience function: read or start configuration if not already initialized
Definition: ak8963.h:75
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:51
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_i2c.h:79
#define BEBOP_MAG_I2C_DEV
Definition: imu_bebop.c:34
union Ak8963::@26 data
Everything that is in the bebop IMU.
Definition: imu_bebop.h:73
#define BEBOP_ACCEL_RANGE
Definition: imu_bebop.c:69
struct Ak8963 ak
The AK8963 mag.
Definition: imu_bebop.h:75
#define BEBOP_GYRO_RANGE
Definition: imu_bebop.c:64
volatile bool_t data_available
data ready flag
Definition: mpu60x0_i2c.h:57
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:42
Architecture independent I2C (Inter-Integrated Circuit Bus) API.