diff --git a/src/drivers/imu/mpu9250/mpu9250.cpp b/src/drivers/imu/mpu9250/mpu9250.cpp index 50a3381e07..2ed36591fb 100644 --- a/src/drivers/imu/mpu9250/mpu9250.cpp +++ b/src/drivers/imu/mpu9250/mpu9250.cpp @@ -139,11 +139,7 @@ MPU9250::MPU9250(device::Device *interface, device::Device *mag_interface, const _gyro_range_scale(0.0f), _gyro_range_rad_s(0.0f), _dlpf_freq(MPU9250_DEFAULT_ONCHIP_FILTER_FREQ), -#ifdef CONFIG_ARCH_BOARD_CRAZYFLIE - _sample_rate(200), -#else _sample_rate(1000), -#endif _accel_reads(perf_alloc(PC_COUNT, "mpu9250_acc_read")), _gyro_reads(perf_alloc(PC_COUNT, "mpu9250_gyro_read")), _sample_perf(perf_alloc(PC_ELAPSED, "mpu9250_read")), @@ -264,6 +260,17 @@ MPU9250::init() use_i2c(_interface->ioctl(MPUIOCGIS_I2C, dummy)); #endif + /* + * If the MPU is using I2C we should reduce the sample rate to 200Hz and + * make the integration autoreset faster so that we integrate just one + * sample since the sampling rate is already low. + */ + if (is_i2c()) { + _sample_rate = 200; + _accel_int.set_autoreset_interval(1000000 / MPU9250_ACCEL_MAX_OUTPUT_RATE / 4); + _gyro_int.set_autoreset_interval(1000000 / MPU9250_GYRO_MAX_OUTPUT_RATE / 4); + } + int ret = probe(); if (ret != OK) { diff --git a/src/drivers/imu/mpu9250/mpu9250.h b/src/drivers/imu/mpu9250/mpu9250.h index e82248a1e5..15f11927ae 100644 --- a/src/drivers/imu/mpu9250/mpu9250.h +++ b/src/drivers/imu/mpu9250/mpu9250.h @@ -181,11 +181,7 @@ #define MPU_WHOAMI_6500 0x70 #define MPU9250_ACCEL_DEFAULT_RATE 1000 -#ifdef CONFIG_ARCH_BOARD_CRAZYFLIE -#define MPU9250_ACCEL_MAX_OUTPUT_RATE 1000 -#else #define MPU9250_ACCEL_MAX_OUTPUT_RATE 280 -#endif #define MPU9250_ACCEL_DEFAULT_DRIVER_FILTER_FREQ 30 #define MPU9250_GYRO_DEFAULT_RATE 1000 /* rates need to be the same between accel and gyro */ diff --git a/src/lib/drivers/device/integrator.h b/src/lib/drivers/device/integrator.h index ecf1e649fa..30ef7a4f92 100644 --- a/src/lib/drivers/device/integrator.h +++ b/src/lib/drivers/device/integrator.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2015-2016 PX4 Development Team. All rights reserved. + * Copyright (c) 2015-2018 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -86,6 +86,7 @@ public: */ matrix::Vector3f get(bool reset, uint64_t &integral_dt); + /** * Get the current integral and reset the integrator if needed. Additionally give the * integral over the samples differentiated by the integration time (mean filtered values). @@ -97,6 +98,17 @@ public: */ matrix::Vector3f get_and_filtered(bool reset, uint64_t &integral_dt, matrix::Vector3f &filtered_val); + + /** + * Set auto reset interval during runtime. This won't reset the integrator. + * + * @param auto_reset_interval New reset time interval for the integrator. + */ + void set_autoreset_interval(uint64_t auto_reset_interval) + { + _auto_reset_interval = auto_reset_interval; + } + private: uint64_t _auto_reset_interval; /**< the interval after which the content will be published and the integrator reset, 0 if no auto-reset */