Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
imu_mpu6000.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013-2015 Felix Ruess <felix.ruess@gmail.com>
3 * Copyright (C) 2019 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
29#include "modules/imu/imu.h"
30#include "modules/core/abi.h"
31#include "mcu_periph/spi.h"
32#include "generated/modules.h"
33#if IMU_MPU_USE_MEDIAN_FILTER
35#endif
36
37/* SPI defaults set in subsystem makefile, can be configured from airframe file */
40
41/* MPU60x0 gyro/accel internal lowpass frequency */
42#if !defined IMU_MPU_LOWPASS_FILTER && !defined IMU_MPU_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 IMU_MPU_LOWPASS_FILTER MPU60X0_DLPF_42HZ
48#define IMU_MPU_SMPLRT_DIV 9
49PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
50#ifndef IMU_MPU_ACCEL_LOWPASS_FILTER
51#define IMU_MPU_ACCEL_LOWPASS_FILTER MPU60X0_DLPF_ACC_44HZ // for ICM sensors
52#endif
53#elif (PERIODIC_FREQUENCY == 512) || (PERIODIC_FREQUENCY == 500)
54/* Accelerometer: Bandwidth 260Hz, Delay 0ms
55 * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
56 */
57#define IMU_MPU_LOWPASS_FILTER MPU60X0_DLPF_256HZ
58#define IMU_MPU_SMPLRT_DIV 3
59PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
60#ifndef IMU_MPU_ACCEL_LOWPASS_FILTER
61#define IMU_MPU_ACCEL_LOWPASS_FILTER MPU60X0_DLPF_ACC_218HZ // for ICM sensors
62#endif
63#else
64/* By default, don't go too fast */
65#define IMU_MPU_LOWPASS_FILTER MPU60X0_DLPF_42HZ
66#define IMU_MPU_SMPLRT_DIV 9
67PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
68#ifndef IMU_MPU_ACCEL_LOWPASS_FILTER
69#define IMU_MPU_ACCEL_LOWPASS_FILTER MPU60X0_DLPF_ACC_44HZ // for ICM sensors
70#endif
71#warning "Non-default PERIODIC_FREQUENCY: please define IMU_MPU_LOWPASS_FILTER and IMU_MPU_SMPLRT_DIV."
72#endif
73#endif
77
80
81// Default channels order
82#ifndef IMU_MPU_CHAN_X
83#define IMU_MPU_CHAN_X 0
84#endif
86#ifndef IMU_MPU_CHAN_Y
87#define IMU_MPU_CHAN_Y 1
88#endif
90#ifndef IMU_MPU_CHAN_Z
91#define IMU_MPU_CHAN_Z 2
92#endif
94
95// Default channel signs
96#ifndef IMU_MPU_X_SIGN
97#define IMU_MPU_X_SIGN 1
98#endif
100#ifndef IMU_MPU_Y_SIGN
101#define IMU_MPU_Y_SIGN 1
102#endif
104#ifndef IMU_MPU_Z_SIGN
105#define IMU_MPU_Z_SIGN 1
106#endif
108
110
111#if IMU_MPU_USE_MEDIAN_FILTER
114#endif
115
136
141
143{
147
148 // set channel order
149 struct Int32Vect3 accel = {
153 };
154 struct Int32Rates rates = {
158 };
159
160 // In case sensor exhibits faulty large spike values in raw output remove them
161#if IMU_MPU_USE_MEDIAN_FILTER
164#endif
165
167
168 // Send the scaled values over ABI
171 }
172}
Main include for ABI (AirBorneInterface).
#define IMU_MPU6000_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
angular rates
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.
struct ImuMpu6000 imu_mpu_spi
#define IMU_MPU_Z_SIGN
#define IMU_MPU_LOWPASS_FILTER
Definition imu_mpu6000.c:65
#define IMU_MPU_SMPLRT_DIV
Definition imu_mpu6000.c:66
void imu_mpu_spi_periodic(void)
#define IMU_MPU_X_SIGN
Definition imu_mpu6000.c:97
#define IMU_MPU_ACCEL_LOWPASS_FILTER
Definition imu_mpu6000.c:69
void imu_mpu_spi_init(void)
#define IMU_MPU_CHAN_Y
Definition imu_mpu6000.c:87
#define IMU_MPU_CHAN_X
Definition imu_mpu6000.c:83
void imu_mpu_spi_event(void)
#define IMU_MPU_Y_SIGN
#define IMU_MPU_CHAN_Z
Definition imu_mpu6000.c:91
Driver for IMU with only MPU6000 via SPI.
struct Mpu60x0_Spi mpu
Definition imu_mpu6000.h:46
#define IMU_MPU_GYRO_RANGE
Definition imu_mpu6000.h:38
#define IMU_MPU_ACCEL_RANGE
Definition imu_mpu6000.h:42
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
uint16_t foo
Definition main_demo5.c:58
#define UpdateMedianFilterVect3Int(_f, _v)
#define InitMedianFilterVect3Int(_f, _n)
#define InitMedianFilterRatesInt(_f, _n)
#define UpdateMedianFilterRatesInt(_f, _v)
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 Mpu60x0ACCDLPF dlpf_cfg_acc
Digital Low Pass Filter for acceleremoter (ICM devices only)
Definition mpu60x0.h:142
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition mpu60x0.h:143
void mpu60x0_spi_event(struct Mpu60x0_Spi *mpu)
void mpu60x0_spi_init(struct Mpu60x0_Spi *mpu, struct spi_periph *spi_p, uint8_t slave_idx)
Definition mpu60x0_spi.c:31
volatile bool data_available
data ready flag
Definition mpu60x0_spi.h:56
struct Mpu60x0Config config
Definition mpu60x0_spi.h:67
float temp
temperature in degrees Celcius
Definition mpu60x0_spi.h:65
union Mpu60x0_Spi::@344 data_rates
static void mpu60x0_spi_periodic(struct Mpu60x0_Spi *mpu)
convenience function: read or start configuration if not already initialized
Definition mpu60x0_spi.h:78
union Mpu60x0_Spi::@343 data_accel
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Architecture independent SPI (Serial Peripheral Interface) API.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.