Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_drotek_10dof_v2.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 
35 #include "subsystems/imu.h"
36 
37 #include "mcu_periph/i2c.h"
38 
39 #if !defined DROTEK_2_LOWPASS_FILTER && !defined DROTEK_2_SMPLRT_DIV
40 #define DROTEK_2_LOWPASS_FILTER MPU60X0_DLPF_42HZ
41 #define DROTEK_2_SMPLRT_DIV 9
42 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz")
43 #endif
44 PRINT_CONFIG_VAR(DROTEK_2_SMPLRT_DIV)
45 PRINT_CONFIG_VAR(DROTEK_2_LOWPASS_FILTER)
46 
47 #ifndef DROTEK_2_GYRO_RANGE
48 #define DROTEK_2_GYRO_RANGE MPU60X0_GYRO_RANGE_1000
49 #endif
50 PRINT_CONFIG_VAR(DROTEK_2_GYRO_RANGE)
51 
52 #ifndef DROTEK_2_ACCEL_RANGE
53 #define DROTEK_2_ACCEL_RANGE MPU60X0_ACCEL_RANGE_8G
54 #endif
55 PRINT_CONFIG_VAR(DROTEK_2_ACCEL_RANGE)
56 
57 #ifndef DROTEK_2_MPU_I2C_ADDR
58 #define DROTEK_2_MPU_I2C_ADDR MPU60X0_ADDR_ALT
59 #endif
60 PRINT_CONFIG_VAR(DROTEK_2_MPU_I2C_ADDR)
61 
62 #ifndef DROTEK_2_HMC_I2C_ADDR
63 #define DROTEK_2_HMC_I2C_ADDR HMC58XX_ADDR
64 #endif
65 PRINT_CONFIG_VAR(DROTEK_2_HMC_I2C_ADDR)
66 
67 
69 
70 void imu_impl_init(void)
71 {
72  /* MPU-60X0 */
73  mpu60x0_i2c_init(&imu_drotek2.mpu, &(DROTEK_2_I2C_DEV), DROTEK_2_MPU_I2C_ADDR);
74  // change the default configuration
79 
80  /* HMC5883 magnetometer */
81  hmc58xx_init(&imu_drotek2.hmc, &(DROTEK_2_I2C_DEV), DROTEK_2_HMC_I2C_ADDR);
82 
83  /* mag is declared as slave to call the configure function,
84  * regardless if it is an actual MPU slave or passthrough
85  */
86  imu_drotek2.mpu.config.nb_slaves = 1;
87  /* set callback function to configure mag */
89 
90  // use hmc mag via passthrough
91  imu_drotek2.mpu.config.i2c_bypass = TRUE;
92 
93  imu_drotek2.gyro_valid = FALSE;
94  imu_drotek2.accel_valid = FALSE;
95  imu_drotek2.mag_valid = FALSE;
96 }
97 
98 void imu_periodic(void)
99 {
100  // Start reading the latest gyroscope data
102 
103  // Read HMC58XX at ~50Hz (main loop for rotorcraft: 512Hz)
105  RunOnceEvery(10, hmc58xx_read(&imu_drotek2.hmc));
106  }
107 }
108 
110 {
111  // If the MPU6050 I2C transaction has succeeded: convert the data
113 
115 #if IMU_DROTEK_2_ORIENTATION_IC_UP
116  /* change orientation, so if ICs face up, z-axis is down */
123 #else
124  /* default orientation as should be printed on the pcb, z-down, ICs down */
127 #endif
128 
132  }
133 
134  /* HMC58XX event task */
137 #if IMU_DROTEK_2_ORIENTATION_IC_UP
141 #else
143 #endif
146  }
147 }
148 
152 bool_t imu_drotek2_configure_mag_slave(Mpu60x0ConfigSet mpu_set __attribute__ ((unused)), void* mpu __attribute__ ((unused)))
153 {
156  return TRUE;
157  else
158  return FALSE;
159 }
void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
Definition: mpu60x0_i2c.c:81
union Hmc58xx::@20 data
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:75
void hmc58xx_start_configure(struct Hmc58xx *hmc)
Definition: hmc58xx.c:112
struct Hmc58xx hmc
int32_t p
in rad/s^2 with INT32_RATE_FRAC
void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu60x0_i2c.c:31
void imu_periodic(void)
bool_t imu_drotek2_configure_mag_slave(Mpu60x0ConfigSet mpu_set, void *mpu)
callback function to configure hmc5883 mag
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu60x0.h:89
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:301
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:48
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:74
volatile bool_t gyro_valid
#define DROTEK_2_GYRO_RANGE
union Mpu60x0_I2c::@23 data_accel
struct ImuDrotek2 imu_drotek2
#define FALSE
Definition: imu_chimu.h:141
Mpu60x0I2cSlaveConfigure configure
Definition: mpu60x0.h:70
volatile bool_t mag_valid
#define DROTEK_2_LOWPASS_FILTER
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:49
void hmc58xx_read(struct Hmc58xx *hmc)
Definition: hmc58xx.c:123
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:77
#define DROTEK_2_HMC_I2C_ADDR
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:50
bool_t initialized
config done flag
Definition: mpu60x0.h:82
struct Mpu60x0_I2c mpu
union Mpu60x0_I2c::@24 data_rates
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:76
#define DROTEK_2_ACCEL_RANGE
Inertial Measurement Unit interface.
struct Mpu60x0I2cSlave slaves[5]
I2C slaves.
Definition: mpu60x0.h:90
volatile bool_t data_available
data ready flag
Definition: mpu60x0_i2c.h:57
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:50
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
bool_t i2c_bypass
Bypass MPU I2C.
Definition: mpu60x0.h:87
#define DROTEK_2_MPU_I2C_ADDR
struct Int16Vect3 vect
accel data vector in accel coordinate system
Definition: mpu60x0_i2c.h:59
void imu_impl_init(void)
int32_t q
in rad/s^2 with INT32_RATE_FRAC
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:62
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:111
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_i2c.h:78
int32_t r
in rad/s^2 with INT32_RATE_FRAC
bool_t initialized
config done flag
Definition: hmc58xx.h:63
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:136
#define DROTEK_2_SMPLRT_DIV
volatile bool_t data_available
data ready flag
Definition: hmc58xx.h:65
void(* Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu60x0.h:64
volatile bool_t accel_valid
void imu_drotek2_event(void)
Architecture independent I2C (Inter-Integrated Circuit Bus) API.