Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "modules/imu/imu_bebop.h"
28 #include "modules/imu/imu.h"
29 #include "modules/core/abi.h"
30 #include "mcu_periph/i2c.h"
31 #include "generated/modules.h"
32 
33 
34 /* defaults suitable for Bebop */
35 #ifndef BEBOP_MAG_I2C_DEV
36 #define BEBOP_MAG_I2C_DEV i2c1
37 #endif
39 
40 #ifndef BEBOP_MPU_I2C_DEV
41 #define BEBOP_MPU_I2C_DEV i2c2
42 #endif
44 
45 #if !defined BEBOP_LOWPASS_FILTER && !defined BEBOP_SMPLRT_DIV
46 #if (PERIODIC_FREQUENCY == 60) || (PERIODIC_FREQUENCY == 120)
47 /* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
48  * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
49  */
50 #define BEBOP_LOWPASS_FILTER MPU60X0_DLPF_42HZ
51 #define BEBOP_SMPLRT_DIV 9
52 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
53 #elif PERIODIC_FREQUENCY == 512
54 /* Accelerometer: Bandwidth 260Hz, Delay 0ms
55  * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
56  */
57 #define BEBOP_LOWPASS_FILTER MPU60X0_DLPF_256HZ
58 #define BEBOP_SMPLRT_DIV 3
59 PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
60 #endif
61 #endif
62 PRINT_CONFIG_VAR(BEBOP_SMPLRT_DIV)
63 PRINT_CONFIG_VAR(BEBOP_LOWPASS_FILTER)
64 
67 
69 
71 struct ImuBebop imu_bebop;
72 
76 void imu_bebop_init(void)
77 {
78  /* MPU-60X0 */
80  imu_bebop.mpu.config.smplrt_div = BEBOP_SMPLRT_DIV;
81  imu_bebop.mpu.config.dlpf_cfg = BEBOP_LOWPASS_FILTER;
84 
85  // Set the default scaling
88 
89  /* AKM8963 */
91 
92 #if BEBOP_VERSION2
93  //the magnetometer of the bebop2 is located on the gps board,
94  //which is under a slight angle
95  struct FloatEulers imu_to_mag_eulers =
96  { 0.0, RadOfDeg(8.5), M_PI };
97  orientationSetEulers_f(&imu_to_mag_bebop, &imu_to_mag_eulers);
98 #endif
99 }
100 
106 {
107  // Start reading the latest gyroscope data
109 
110  // AKM8963
112 }
113 
118 void imu_bebop_event(void)
119 {
120  uint32_t now_ts = get_sys_time_usec();
121 
122  /* MPU-60x0 event taks */
124 
126  /* default orientation of the MPU is upside down sor corrigate this here */
127  struct Int32Rates gyro;
128  struct Int32Vect3 accel;
129  RATES_ASSIGN(gyro, imu_bebop.mpu.data_rates.rates.p, -imu_bebop.mpu.data_rates.rates.q,
130  -imu_bebop.mpu.data_rates.rates.r);
132  -imu_bebop.mpu.data_accel.vect.z);
133 
134  imu_bebop.mpu.data_available = false;
135  AbiSendMsgIMU_GYRO_RAW(IMU_BOARD_ID, now_ts, &gyro, 1, IMU_BEBOP_PERIODIC_FREQ, imu_bebop.mpu.temp);
136  AbiSendMsgIMU_ACCEL_RAW(IMU_BOARD_ID, now_ts, &accel, 1, IMU_BEBOP_PERIODIC_FREQ, imu_bebop.mpu.temp);
137  }
138 
139  /* AKM8963 event task */
141 
143  struct Int32Vect3 mag;
144 #if BEBOP_VERSION2
145  struct Int32Vect3 mag_temp;
146  // In the second bebop version the magneto is turned 90 degrees
147  VECT3_ASSIGN(mag_temp, imu_bebop.ak.data.vect.x, imu_bebop.ak.data.vect.y, imu_bebop.ak.data.vect.z);
148  // Rotate the magneto
149  struct Int32RMat *imu_to_mag_rmat = orientationGetRMat_i(&imu_to_mag_bebop);
150  int32_rmat_vmult(&mag, imu_to_mag_rmat, &mag_temp);
151 #else //BEBOP regular first verion
152  VECT3_ASSIGN(mag, -imu_bebop.ak.data.vect.y, imu_bebop.ak.data.vect.x, imu_bebop.ak.data.vect.z);
153 #endif
154 
155  imu_bebop.ak.data_available = false;
156  AbiSendMsgIMU_MAG_RAW(IMU_BOARD_ID, now_ts, &mag);
157  }
158 }
Main include for ABI (AirBorneInterface).
#define IMU_BOARD_ID
void ak8963_event(struct Ak8963 *ak)
Definition: ak8963.c:95
void ak8963_init(struct Ak8963 *ak, struct i2c_periph *i2c_p, uint8_t addr)
Initialize AK8963 struct.
Definition: ak8963.c:34
volatile bool data_available
data ready flag
Definition: ak8963.h:61
union Ak8963::@310 data
static void ak8963_periodic(struct Ak8963 *ak)
convenience function: read or start configuration if not already initialized
Definition: ak8963.h:75
#define AK8963_ADDR
Definition: ak8963_regs.h:31
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
euler angles
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:330
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
void int32_rmat_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_a2b, struct Int32Vect3 *va)
rotate 3D vector by rotation matrix.
rotation matrix
angular rates
static struct Int32RMat * orientationGetRMat_i(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (int).
static void orientationSetEulers_f(struct OrientationReps *orientation, struct FloatEulers *eulers)
Set vehicle body attitude from euler angles (float).
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition: imu.c:610
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct Int32Rates *scale)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition: imu.c:580
Inertial Measurement Unit interface.
#define BEBOP_MPU_I2C_DEV
Definition: imu_bebop.c:41
#define BEBOP_MAG_I2C_DEV
Definition: imu_bebop.c:36
struct OrientationReps imu_to_mag_bebop
IMU to magneto rotation.
Definition: imu_bebop.c:68
void imu_bebop_periodic(void)
Handle all the periodic tasks of the Navstik IMU components.
Definition: imu_bebop.c:105
void imu_bebop_init(void)
Navstik IMU initializtion of the MPU-60x0 and HMC58xx.
Definition: imu_bebop.c:76
void imu_bebop_event(void)
Handle all the events of the Navstik IMU components.
Definition: imu_bebop.c:118
struct ImuBebop imu_bebop
Basic Navstik IMU data.
Definition: imu_bebop.c:71
Interface for the Bebop magnetometer, accelerometer and gyroscope.
#define BEBOP_ACCEL_RANGE
Definition: imu_bebop.h:42
#define BEBOP_GYRO_RANGE
Definition: imu_bebop.h:38
struct Ak8963 ak
The AK8963 mag.
Definition: imu_bebop.h:48
struct Mpu60x0_I2c mpu
The MPU gyro/accel device.
Definition: imu_bebop.h:47
Everything that is in the bebop IMU.
Definition: imu_bebop.h:46
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
const struct Int32Rates MPU60X0_GYRO_SENS_FRAC[4][2]
Definition: mpu60x0.c:38
const struct Int32Vect3 MPU60X0_ACCEL_SENS_FRAC[4][2]
Definition: mpu60x0.c:56
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:140
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:141
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:144
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:143
void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu60x0_i2c.c:31
void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
Definition: mpu60x0_i2c.c:82
union Mpu60x0_I2c::@341 data_accel
volatile bool data_available
data ready flag
Definition: mpu60x0_i2c.h:57
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_i2c.h:79
union Mpu60x0_I2c::@342 data_rates
float temp
temperature in degrees Celcius
Definition: mpu60x0_i2c.h:66
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
#define MPU60X0_ADDR
Definition: mpu60x0_regs.h:32
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78