Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
imu_mpu60x0_i2c.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013-2015 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
26
27#include <math.h>
29#include "modules/imu/imu.h"
30#include "modules/core/abi.h"
31#include "mcu_periph/i2c.h"
32#include "led.h"
33#include "generated/modules.h"
34
35/* MPU60x0 gyro/accel internal lowpass frequency */
36#if !defined IMU_MPU60X0_LOWPASS_FILTER && !defined IMU_MPU60X0_SMPLRT_DIV
37#if PERIODIC_FREQUENCY <= 120
38/* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
39 * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
40 */
41#define IMU_MPU60X0_LOWPASS_FILTER MPU60X0_DLPF_42HZ
42#define IMU_MPU60X0_SMPLRT_DIV 9
43PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
44
45#elif PERIODIC_FREQUENCY < 500
46/* Accelerometer: Bandwidth 94Hz, Delay 3ms
47 * Gyroscope: Bandwidth 98Hz, Delay 2.8ms sampling 1kHz
48 */
49#define IMU_MPU60X0_LOWPASS_FILTER MPU60X0_DLPF_98HZ
50#define IMU_MPU60X0_SMPLRT_DIV 1
51PRINT_CONFIG_MSG("Gyro/Accel output rate is 500Hz at 1kHz internal sampling")
52
53#else // PERIODIC_FREQUENCY >= 500
54/* Accelerometer: Bandwidth 260Hz, Delay 0ms
55 * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
56 */
57#define IMU_MPU60X0_LOWPASS_FILTER MPU60X0_DLPF_256HZ
58#define IMU_MPU60X0_SMPLRT_DIV 3
59PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
60
61#endif
62#endif
63
68
69#ifndef IMU_MPU60X0_I2C_ADDR
70#define IMU_MPU60X0_I2C_ADDR MPU60X0_ADDR
71#endif
72
74
76{
77 mpu60x0_i2c_init(&imu_mpu_i2c.mpu, &(IMU_MPU60X0_I2C_DEV), IMU_MPU60X0_I2C_ADDR);
78 // change the default configuration
79 imu_mpu_i2c.mpu.config.smplrt_div = IMU_MPU60X0_SMPLRT_DIV;
80 imu_mpu_i2c.mpu.config.dlpf_cfg = IMU_MPU60X0_LOWPASS_FILTER;
81 imu_mpu_i2c.mpu.config.gyro_range = IMU_MPU60X0_GYRO_RANGE;
82 imu_mpu_i2c.mpu.config.accel_range = IMU_MPU60X0_ACCEL_RANGE;
83
84 // Set the default scaling
87}
88
93
95{
96 uint32_t now_ts = get_sys_time_usec();
97
98 // If the MPU60X0 I2C transaction has succeeded: convert the data
100 if (imu_mpu_i2c.mpu.data_available) {
101 AbiSendMsgIMU_GYRO_RAW(IMU_MPU60X0_ID, now_ts, &imu_mpu_i2c.mpu.data_rates.rates, 1, IMU_MPU_I2C_PERIODIC_FREQ, imu_mpu_i2c.mpu.temp);
102 AbiSendMsgIMU_ACCEL_RAW(IMU_MPU60X0_ID, now_ts, &imu_mpu_i2c.mpu.data_accel.vect, 1, IMU_MPU_I2C_PERIODIC_FREQ, imu_mpu_i2c.mpu.temp);
103 imu_mpu_i2c.mpu.data_available = false;
104 }
105}
Main include for ABI (AirBorneInterface).
#define IMU_MPU60X0_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct FloatRates *scale_f)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition imu.c:842
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition imu.c:871
Inertial Measurement Unit interface.
void imu_mpu_i2c_init(void)
#define IMU_MPU60X0_LOWPASS_FILTER
void imu_mpu_i2c_periodic(void)
#define IMU_MPU60X0_I2C_ADDR
void imu_mpu_i2c_event(void)
struct ImuMpu60x0 imu_mpu_i2c
#define IMU_MPU60X0_SMPLRT_DIV
Driver for IMU with only MPU60x0 via I2C.
#define IMU_MPU60X0_ACCEL_RANGE
#define IMU_MPU60X0_GYRO_RANGE
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
arch independent LED (Light Emitting Diodes) API
const struct FloatVect3 MPU60X0_ACCEL_SENS_F[4]
Definition mpu60x0.c:54
const struct FloatRates MPU60X0_GYRO_SENS_F[4]
Definition mpu60x0.c:38
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
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition mpu60x0_i2c.h:79
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.