Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
imu_px4fmu.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
26
28#include "modules/imu/imu.h"
29#include "modules/core/abi.h"
30#include "mcu_periph/spi.h"
32#include "generated/modules.h"
33
34/* MPU60x0 gyro/accel internal lowpass frequency */
35#if !defined PX4FMU_LOWPASS_FILTER && !defined PX4FMU_SMPLRT_DIV
36#if PERIODIC_FREQUENCY <= 120
37/* Accelerometer: Bandwidth 44Hz, Delay 4.9ms
38 * Gyroscope: Bandwidth 42Hz, Delay 4.8ms sampling 1kHz
39 */
40#define PX4FMU_LOWPASS_FILTER MPU60X0_DLPF_42HZ
41#define PX4FMU_SMPLRT_DIV 9
42PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
43
44#elif PERIODIC_FREQUENCY < 500
45/* Accelerometer: Bandwidth 94Hz, Delay 3ms
46 * Gyroscope: Bandwidth 98Hz, Delay 2.8ms sampling 1kHz
47 */
48#define PX4FMU_LOWPASS_FILTER MPU60X0_DLPF_98HZ
49#define PX4FMU_SMPLRT_DIV 1
50PRINT_CONFIG_MSG("Gyro/Accel output rate is 500Hz at 1kHz internal sampling")
51
52#else // PERIODIC_FREQUENCY >= 500
53/* Accelerometer: Bandwidth 260Hz, Delay 0ms
54 * Gyroscope: Bandwidth 256Hz, Delay 0.98ms sampling 8kHz
55 */
56#define PX4FMU_LOWPASS_FILTER MPU60X0_DLPF_256HZ
57#define PX4FMU_SMPLRT_DIV 3
58PRINT_CONFIG_MSG("Gyro/Accel output rate is 2kHz at 8kHz internal sampling")
59
60#endif
61#endif
62
67
69
71{
72 /* MPU is on spi1 and CS is SLAVE2 */
74 // change the default configuration
75 imu_px4fmu.mpu.config.smplrt_div = PX4FMU_SMPLRT_DIV;
76 imu_px4fmu.mpu.config.dlpf_cfg = PX4FMU_LOWPASS_FILTER;
77 imu_px4fmu.mpu.config.gyro_range = PX4FMU_GYRO_RANGE;
78 imu_px4fmu.mpu.config.accel_range = PX4FMU_ACCEL_RANGE;
79
80 // Set the default scaling
83
84 /* initialize mag on i2c2 and set default options */
86}
87
89{
91
92 // Read HMC58XX at 50Hz (main loop for rotorcraft: 512Hz)
93 RunOnceEvery(10, hmc58xx_periodic(&imu_px4fmu.hmc));
94}
95
97{
98 uint32_t now_ts = get_sys_time_usec();
99
101 if (imu_px4fmu.mpu.data_available) {
102 struct Int32Rates gyro = {
103 imu_px4fmu.mpu.data_rates.rates.q,
104 imu_px4fmu.mpu.data_rates.rates.p,
105 -imu_px4fmu.mpu.data_rates.rates.r
106 };
107 struct Int32Vect3 accel = {
108 imu_px4fmu.mpu.data_accel.vect.y,
109 imu_px4fmu.mpu.data_accel.vect.x,
110 -imu_px4fmu.mpu.data_accel.vect.z
111 };
112 imu_px4fmu.mpu.data_available = false;
113 AbiSendMsgIMU_GYRO_RAW(IMU_BOARD_ID, now_ts, &gyro, 1, IMU_PX4FMU_PERIODIC_FREQ, imu_px4fmu.mpu.temp);
114 AbiSendMsgIMU_ACCEL_RAW(IMU_BOARD_ID, now_ts, &accel, 1, IMU_PX4FMU_PERIODIC_FREQ, imu_px4fmu.mpu.temp);
115 }
116
117 /* HMC58XX event task */
119 if (imu_px4fmu.hmc.data_available) {
120 struct Int32Vect3 mag = {
121 imu_px4fmu.hmc.data.vect.y,
122 imu_px4fmu.hmc.data.vect.x,
123 -imu_px4fmu.hmc.data.vect.z
124 };
125 imu_px4fmu.hmc.data_available = false;
126 AbiSendMsgIMU_MAG_RAW(IMU_BOARD_ID, now_ts, &mag);
127 }
128}
129
Main include for ABI (AirBorneInterface).
#define IMU_BOARD_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
angular rates
struct spi_periph spi1
Definition spi.c:46
#define SPI_SLAVE2
Definition spi.h:191
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:83
void hmc58xx_event(struct Hmc58xx *hmc)
Definition hmc58xx.c:160
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition hmc58xx.h:87
Register defs for Honeywell HMC5843, HMC5883 and HMC5983 magnetometers.
#define HMC58XX_ADDR
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.
#define PX4FMU_SMPLRT_DIV
Definition imu_px4fmu.c:41
#define PX4FMU_LOWPASS_FILTER
Definition imu_px4fmu.c:40
void imu_px4fmu_periodic(void)
Definition imu_px4fmu.c:88
void imu_px4fmu_init(void)
Definition imu_px4fmu.c:70
struct ImuPx4fmu imu_px4fmu
Definition imu_px4fmu.c:68
void imu_px4fmu_event(void)
Definition imu_px4fmu.c:96
Driver for the PX4FMU SPI1 for the MPU6000 and I2C2 for the HMC5883.
#define PX4FMU_GYRO_RANGE
Definition imu_px4fmu.h:38
#define PX4FMU_ACCEL_RANGE
Definition imu_px4fmu.h:42
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
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_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
static void mpu60x0_spi_periodic(struct Mpu60x0_Spi *mpu)
convenience function: read or start configuration if not already initialized
Definition mpu60x0_spi.h:78
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Architecture independent SPI (Serial Peripheral Interface) API.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.