Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
imu_swing.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van Tienen <freek.v.tienen@gmail.com>
3  * Copyright (C) 2017 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
28 #include "subsystems/imu.h"
29 #include "subsystems/abi.h"
30 #include "mcu_periph/i2c.h"
31 
32 
33 /* defaults suitable for Swing */
34 #ifndef SWING_MPU_I2C_DEV
35 #define SWING_MPU_I2C_DEV i2c0
36 #endif
37 PRINT_CONFIG_VAR(SWING_MPU_I2C_DEV)
38 
39 #if !defined SWING_LOWPASS_FILTER && !defined SWING_SMPLRT_DIV
40 #if (PERIODIC_FREQUENCY == 60) || (PERIODIC_FREQUENCY == 120)
41 /* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
42  * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
43  */
44 #define SWING_LOWPASS_FILTER MPU60X0_DLPF_42HZ
45 #define SWING_SMPLRT_DIV 9
46 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
47 #elif PERIODIC_FREQUENCY == 512
48 /* Accelerometer: Bandwidth 260Hz, Delay 0ms
49  * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
50  */
51 #define SWING_LOWPASS_FILTER MPU60X0_DLPF_256HZ
52 #define SWING_SMPLRT_DIV 3
53 PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
54 #endif
55 #endif
56 PRINT_CONFIG_VAR(SWING_SMPLRT_DIV)
57 PRINT_CONFIG_VAR(SWING_LOWPASS_FILTER)
58 
59 PRINT_CONFIG_VAR(SWING_GYRO_RANGE)
60 PRINT_CONFIG_VAR(SWING_ACCEL_RANGE)
61 
62 
64 
68 void imu_swing_init(void)
69 {
70  /* MPU-60X0 */
72  imu_swing.mpu.config.smplrt_div = SWING_SMPLRT_DIV;
73  imu_swing.mpu.config.dlpf_cfg = SWING_LOWPASS_FILTER;
76 }
77 
83 {
84  // Start reading the latest gyroscope data
86 }
87 
92 void imu_swing_event(void)
93 {
94  uint32_t now_ts = get_sys_time_usec();
95 
96  /* MPU-60x0 event taks */
98 
100  /* default orientation of the MPU is upside down and in plane mode
101  * turn it to have rotorcraft mode by default */
103  -imu_swing.mpu.data_rates.rates.r,
104  -imu_swing.mpu.data_rates.rates.q,
105  -imu_swing.mpu.data_rates.rates.p);
107  -imu_swing.mpu.data_accel.vect.z,
108  -imu_swing.mpu.data_accel.vect.y,
109  -imu_swing.mpu.data_accel.vect.x);
110 
111  imu_swing.mpu.data_available = false;
114  AbiSendMsgIMU_GYRO_INT32(IMU_BOARD_ID, now_ts, &imu.gyro);
115  AbiSendMsgIMU_ACCEL_INT32(IMU_BOARD_ID, now_ts, &imu.accel);
116  }
117 }
118 
Imu::gyro_unscaled
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:46
ImuSwing::mpu
struct Mpu60x0_I2c mpu
The MPU gyro/accel device.
Definition: imu_swing.h:74
Mpu60x0Config::smplrt_div
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:140
mpu60x0_i2c_periodic
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_i2c.h:79
Mpu60x0Config::gyro_range
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:143
abi.h
Imu::accel
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:39
ImuSwing
Everything that is in the swing IMU.
Definition: imu_swing.h:73
SWING_ACCEL_RANGE
#define SWING_ACCEL_RANGE
Definition: imu_swing.h:42
uint32_t
unsigned long uint32_t
Definition: types.h:18
Mpu60x0Config::accel_range
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:144
IMU_BOARD_ID
#define IMU_BOARD_ID
Definition: abi_sender_ids.h:275
Mpu60x0Config::dlpf_cfg
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:141
Imu::accel_unscaled
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:47
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
imu.h
RATES_ASSIGN
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:330
SWING_MPU_I2C_DEV
#define SWING_MPU_I2C_DEV
Definition: imu_swing.c:35
imu_swing_periodic
void imu_swing_periodic(void)
Handle all the periodic tasks of the Navstik IMU components.
Definition: imu_swing.c:82
mpu60x0_i2c_init
void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu60x0_i2c.c:31
imu_swing
struct ImuSwing imu_swing
Basic Navstik IMU data.
Definition: imu_swing.c:63
imu_scale_gyro
void imu_scale_gyro(struct Imu *_imu)
Definition: imu_vectornav.c:43
mpu60x0_i2c_event
void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
Definition: mpu60x0_i2c.c:82
Mpu60x0_I2c::config
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
imu_swing_init
void imu_swing_init(void)
Navstik IMU initializtion of the MPU-60x0 and HMC58xx.
Definition: imu_swing.c:68
imu
struct Imu imu
global IMU state
Definition: imu.c:108
PRINT_CONFIG_MSG
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
Mpu60x0_I2c::data_accel
union Mpu60x0_I2c::@331 data_accel
MPU60X0_ADDR
#define MPU60X0_ADDR
Definition: mpu60x0_regs.h:32
Mpu60x0_I2c::data_rates
union Mpu60x0_I2c::@332 data_rates
Mpu60x0_I2c::data_available
volatile bool data_available
data ready flag
Definition: mpu60x0_i2c.h:57
SWING_GYRO_RANGE
#define SWING_GYRO_RANGE
Definition: imu_swing.h:38
VECT3_ASSIGN
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
i2c.h
imu_scale_accel
void imu_scale_accel(struct Imu *_imu)
Definition: imu_vectornav.c:44
Imu::gyro
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:38
imu_swing_event
void imu_swing_event(void)
Handle all the events of the Navstik IMU components.
Definition: imu_swing.c:92