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_navstik.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 "mcu_periph/i2c.h"
29 
30 
31 /* defaults suitable for Navstik */
32 #ifndef NAVSTIK_MAG_I2C_DEV
33 #define NAVSTIK_MAG_I2C_DEV i2c3
34 #endif
36 
37 #ifndef NAVSTIK_MPU_I2C_DEV
38 #define NAVSTIK_MPU_I2C_DEV i2c1
39 #endif
41 
42 #if !defined NAVSTIK_LOWPASS_FILTER && !defined NAVSTIK_SMPLRT_DIV
43 #if (PERIODIC_FREQUENCY == 60) || (PERIODIC_FREQUENCY == 120)
44 /* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
45  * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
46  */
47 #define NAVSTIK_LOWPASS_FILTER MPU60X0_DLPF_42HZ
48 #define NAVSTIK_SMPLRT_DIV 9
49 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
50 #elif PERIODIC_FREQUENCY == 512
51 /* Accelerometer: Bandwidth 260Hz, Delay 0ms
52  * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
53  */
54 #define NAVSTIK_LOWPASS_FILTER MPU60X0_DLPF_256HZ
55 #define NAVSTIK_SMPLRT_DIV 3
56 PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
57 #endif
58 #endif
59 PRINT_CONFIG_VAR(NAVSTIK_SMPLRT_DIV)
60 PRINT_CONFIG_VAR(NAVSTIK_LOWPASS_FILTER)
61 
62 #ifndef NAVSTIK_GYRO_RANGE
63 #define NAVSTIK_GYRO_RANGE MPU60X0_GYRO_RANGE_1000
64 #endif
66 
67 #ifndef NAVSTIK_ACCEL_RANGE
68 #define NAVSTIK_ACCEL_RANGE MPU60X0_ACCEL_RANGE_8G
69 #endif
71 
72 
74 
78 void imu_impl_init(void)
79 {
80  imu_navstik.accel_valid = FALSE;
81  imu_navstik.gyro_valid = FALSE;
82  imu_navstik.mag_valid = FALSE;
83 
84  /* MPU-60X0 */
86  imu_navstik.mpu.config.smplrt_div = NAVSTIK_SMPLRT_DIV;
87  imu_navstik.mpu.config.dlpf_cfg = NAVSTIK_LOWPASS_FILTER;
90 
91  /* HMC58XX */
93 }
94 
99 void imu_periodic(void)
100 {
101  // Start reading the latest gyroscope data
103 
104  // Read HMC58XX at 50Hz (main loop for rotorcraft: 512Hz)
105  RunOnceEvery(10, hmc58xx_periodic(&imu_navstik.hmc));
106 }
107 
113 {
114  /* MPU-60x0 event taks */
116 
118  /* default orientation as should be printed on the pcb, z-down, ICs down */
121 
125  }
126 
127  /* HMC58XX event task */
133 
136  }
137 }
void imu_navstik_event(void)
Handle all the events of the Navstik IMU components.
Definition: imu_navstik.c:112
void imu_impl_init(void)
Navstik IMU initializtion of the MPU-60x0 and HMC58xx.
Definition: imu_navstik.c:78
void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
Definition: mpu60x0_i2c.c:81
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:75
struct Mpu60x0_I2c mpu
Definition: imu_navstik.h:104
void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu60x0_i2c.c:31
#define NAVSTIK_ACCEL_RANGE
Definition: imu_navstik.c:68
#define MPU60X0_ADDR_ALT
Definition: mpu60x0_regs.h:33
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:326
struct Hmc58xx hmc
Definition: imu_navstik.h:105
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:49
union Mpu60x0_I2c::@38 data_rates
void imu_periodic(void)
Handle all the periodic tasks of the Navstik IMU components.
Definition: imu_navstik.c:99
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:74
#define NAVSTIK_MPU_I2C_DEV
Definition: imu_navstik.c:38
union Hmc58xx::@29 data
#define HMC58XX_ADDR
Definition: hmc58xx_regs.h:31
#define FALSE
Definition: imu_chimu.h:141
volatile uint8_t mag_valid
Definition: imu_navstik.h:103
volatile uint8_t gyro_valid
Definition: imu_navstik.h:102
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:50
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:77
volatile uint8_t accel_valid
Definition: imu_navstik.h:101
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:47
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:76
Inertial Measurement Unit interface.
volatile bool_t data_available
data ready flag
Definition: mpu60x0_i2c.h:57
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:51
struct Int16Rates rates
rates data as angular rates in gyro coordinate system
Definition: mpu60x0_i2c.h:63
struct Int16Vect3 vect
data vector in mag coordinate system
Definition: hmc58xx.h:67
#define TRUE
Definition: imu_chimu.h:144
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:67
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:84
struct Int16Vect3 vect
accel data vector in accel coordinate system
Definition: mpu60x0_i2c.h:59
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
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:129
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_i2c.h:78
union Mpu60x0_I2c::@37 data_accel
struct ImuNavstik imu_navstik
Basic Navstik IMU data.
Definition: imu_navstik.c:73
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:151
volatile bool_t data_available
data ready flag
Definition: hmc58xx.h:65
#define NAVSTIK_MAG_I2C_DEV
Definition: imu_navstik.c:33
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
#define NAVSTIK_GYRO_RANGE
Definition: imu_navstik.c:63