Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_px4fmu.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Felix Ruess <felix.ruess@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 
29 #include "mcu_periph/spi.h"
31 
32 
33 /* MPU60x0 gyro/accel internal lowpass frequency */
34 #if !defined PX4FMU_LOWPASS_FILTER && !defined PX4FMU_SMPLRT_DIV
35 #if (PERIODIC_FREQUENCY == 60) || (PERIODIC_FREQUENCY == 120)
36 /* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
37  * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
38  */
39 #define PX4FMU_LOWPASS_FILTER MPU60X0_DLPF_42HZ
40 #define PX4FMU_SMPLRT_DIV 9
41 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
42 #elif PERIODIC_FREQUENCY == 512
43 /* Accelerometer: Bandwidth 260Hz, Delay 0ms
44  * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
45  */
46 #define PX4FMU_LOWPASS_FILTER MPU60X0_DLPF_256HZ
47 #define PX4FMU_SMPLRT_DIV 3
48 PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
49 #else
50 #error Non-default PERIODIC_FREQUENCY: please define PX4FMU_LOWPASS_FILTER and PX4FMU_SMPLRT_DIV.
51 #endif
52 #endif
53 PRINT_CONFIG_VAR(PX4FMU_LOWPASS_FILTER)
54 PRINT_CONFIG_VAR(PX4FMU_SMPLRT_DIV)
55 
56 #ifndef PX4FMU_GYRO_RANGE
57 #define PX4FMU_GYRO_RANGE MPU60X0_GYRO_RANGE_2000
58 #endif
60 
61 #ifndef PX4FMU_ACCEL_RANGE
62 #define PX4FMU_ACCEL_RANGE MPU60X0_ACCEL_RANGE_16G
63 #endif
65 
67 
68 void imu_impl_init(void)
69 {
70  imu_px4fmu.accel_valid = FALSE;
71  imu_px4fmu.gyro_valid = FALSE;
72  imu_px4fmu.mag_valid = FALSE;
73 
74  /* MPU is on spi1 and CS is SLAVE2 */
75  mpu60x0_spi_init(&imu_px4fmu.mpu, &spi1, SPI_SLAVE2);
76  // change the default configuration
77  imu_px4fmu.mpu.config.smplrt_div = PX4FMU_SMPLRT_DIV;
78  imu_px4fmu.mpu.config.dlpf_cfg = PX4FMU_LOWPASS_FILTER;
81 
82  /* initialize mag on i2c2 and set default options */
83  hmc58xx_init(&imu_px4fmu.hmc, &i2c2, HMC58XX_ADDR);
84 }
85 
86 
87 void imu_periodic(void)
88 {
90 
91  // Read HMC58XX at 50Hz (main loop for rotorcraft: 512Hz)
92  RunOnceEvery(10, hmc58xx_periodic(&imu_px4fmu.hmc));
93 }
94 
95 void imu_px4fmu_event(void)
96 {
110  }
111 
112  /* HMC58XX event task */
120  }
121 }
122 
void mpu60x0_spi_init(struct Mpu60x0_Spi *mpu, struct spi_periph *spi_p, uint8_t slave_idx)
Definition: mpu60x0_spi.c:31
struct Int16Rates rates
rates data as angular rates in gyro coordinate system
Definition: mpu60x0_spi.h:62
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:75
void mpu60x0_spi_event(struct Mpu60x0_Spi *mpu)
Definition: mpu60x0_spi.c:99
volatile bool_t mag_valid
Definition: imu_px4fmu.h:57
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:49
union Mpu60x0_Spi::@39 data_accel
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:74
struct Mpu60x0_Spi mpu
Definition: imu_px4fmu.h:58
union Hmc58xx::@29 data
#define HMC58XX_ADDR
Definition: hmc58xx_regs.h:31
#define FALSE
Definition: imu_chimu.h:141
Architecture independent SPI (Serial Peripheral Interface) API.
volatile bool_t accel_valid
Definition: imu_px4fmu.h:56
struct Mpu60x0Config config
Definition: mpu60x0_spi.h:66
static void mpu60x0_spi_periodic(struct Mpu60x0_Spi *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_spi.h:77
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:50
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:77
union Mpu60x0_Spi::@40 data_rates
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:47
volatile bool_t gyro_valid
Definition: imu_px4fmu.h:55
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:76
struct Hmc58xx hmc
Definition: imu_px4fmu.h:59
Inertial Measurement Unit interface.
#define PX4FMU_GYRO_RANGE
Definition: imu_px4fmu.c:57
struct ImuPx4fmu imu_px4fmu
Definition: imu_px4fmu.c:66
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:51
struct Int16Vect3 vect
data vector in mag coordinate system
Definition: hmc58xx.h:67
#define TRUE
Definition: imu_chimu.h:144
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:107
Register defs for Honeywell HMC5843 and HMC5883 magnetometers.
volatile bool_t data_available
data ready flag
Definition: mpu60x0_spi.h:56
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:319
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:84
void imu_periodic(void)
Handle all the periodic tasks of the Navstik IMU components.
Definition: imu_px4fmu.c:87
void hmc58xx_init(struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Hmc58xx struct and set default config options.
Definition: hmc58xx.c:75
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:151
volatile bool_t data_available
data ready flag
Definition: hmc58xx.h:65
void imu_px4fmu_event(void)
Definition: imu_px4fmu.c:95
void imu_impl_init(void)
Navstik IMU initializtion of the MPU-60x0 and HMC58xx.
Definition: imu_px4fmu.c:68
struct Int16Vect3 vect
accel data vector in accel coordinate system
Definition: mpu60x0_spi.h:58
#define SPI_SLAVE2
Definition: spi.h:188
process_rx_dma_interrupt & spi1
receive transferred over DMA
Definition: spi_arch.c:961
#define PX4FMU_ACCEL_RANGE
Definition: imu_px4fmu.c:62