Skip to content

Commit

Permalink
imu drivers: do not set on-chip filter based on driver filter setting
Browse files Browse the repository at this point in the history
The description of IMU_GYRO_CUTOFF was incorrectly saying that it only
affects the driver filtering, but in fact it also set the on-chip filter
to the next higher supported value. This patch fixes that.

And because the IMU_GYRO_CUTOFF and not the IMU_ACCEL_CUTOFF was used for
the on-chip filter, after #9070 which sets the default gyro filter to 80,
we were effectively using a dlpf of 98 Hz.
For this reason this patch changes the on-chip cutoff frequency to 98 as
well, so that the overall default behavior is unchanged.
  • Loading branch information
bkueng authored and LorenzMeier committed Apr 25, 2018
1 parent fbbe1f5 commit 4ef3d25
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/drivers/imu/bmi160/bmi160.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,12 @@ BMI160::ioctl(struct file *filp, int cmd, unsigned long arg)
// adjust filters
float cutoff_freq_hz = _accel_filter_x.get_cutoff_freq();
float sample_rate = 1.0e6f / ticks;
_set_dlpf_filter(cutoff_freq_hz);
_accel_filter_x.set_cutoff_frequency(sample_rate, cutoff_freq_hz);
_accel_filter_y.set_cutoff_frequency(sample_rate, cutoff_freq_hz);
_accel_filter_z.set_cutoff_frequency(sample_rate, cutoff_freq_hz);


float cutoff_freq_hz_gyro = _gyro_filter_x.get_cutoff_freq();
_set_dlpf_filter(cutoff_freq_hz_gyro);
_gyro_filter_x.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
_gyro_filter_y.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
_gyro_filter_z.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
Expand Down
10 changes: 0 additions & 10 deletions src/drivers/imu/mpu6000/mpu6000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,6 @@ int MPU6000::reset()
_set_sample_rate(_sample_rate);
usleep(1000);

// FS & DLPF FS=2000 deg/s, DLPF = 20Hz (low pass filter)
// was 90 Hz, but this ruins quality and does not improve the
// system response
_set_dlpf_filter(MPU6000_DEFAULT_ONCHIP_FILTER_FREQ);

if (is_icm_device()) {
Expand Down Expand Up @@ -1409,19 +1406,12 @@ MPU6000::ioctl(struct file *filp, int cmd, unsigned long arg)
// adjust filters
float cutoff_freq_hz = _accel_filter_x.get_cutoff_freq();
float sample_rate = 1.0e6f / ticks;
_set_dlpf_filter(cutoff_freq_hz);

if (is_icm_device()) {
_set_icm_acc_dlpf_filter(cutoff_freq_hz);
}

_accel_filter_x.set_cutoff_frequency(sample_rate, cutoff_freq_hz);
_accel_filter_y.set_cutoff_frequency(sample_rate, cutoff_freq_hz);
_accel_filter_z.set_cutoff_frequency(sample_rate, cutoff_freq_hz);


float cutoff_freq_hz_gyro = _gyro_filter_x.get_cutoff_freq();
_set_dlpf_filter(cutoff_freq_hz_gyro);
_gyro_filter_x.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
_gyro_filter_y.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
_gyro_filter_z.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
Expand Down
16 changes: 8 additions & 8 deletions src/drivers/imu/mpu6000/mpu6000.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@
#define MPUREG_TRIM2 0x0E
#define MPUREG_TRIM3 0x0F
#define MPUREG_TRIM4 0x10
#define MPU_GYRO_DLPF_CFG_256HZ_NOLPF2 0x00
#define MPU_GYRO_DLPF_CFG_188HZ 0x01
#define MPU_GYRO_DLPF_CFG_98HZ 0x02
#define MPU_GYRO_DLPF_CFG_42HZ 0x03
#define MPU_GYRO_DLPF_CFG_20HZ 0x04
#define MPU_GYRO_DLPF_CFG_10HZ 0x05
#define MPU_GYRO_DLPF_CFG_5HZ 0x06
#define MPU_GYRO_DLPF_CFG_256HZ_NOLPF2 0x00 // delay: 0.98ms
#define MPU_GYRO_DLPF_CFG_188HZ 0x01 // delay: 1.9ms
#define MPU_GYRO_DLPF_CFG_98HZ 0x02 // delay: 2.8ms
#define MPU_GYRO_DLPF_CFG_42HZ 0x03 // delay: 4.8ms
#define MPU_GYRO_DLPF_CFG_20HZ 0x04 // delay: 8.3ms
#define MPU_GYRO_DLPF_CFG_10HZ 0x05 // delay: 13.4ms
#define MPU_GYRO_DLPF_CFG_5HZ 0x06 // delay: 18.6ms
#define MPU_GYRO_DLPF_CFG_2100HZ_NOLPF 0x07
#define MPU_DLPF_CFG_MASK 0x07

Expand Down Expand Up @@ -210,7 +210,7 @@
#define MPU6000_GYRO_MAX_OUTPUT_RATE MPU6000_ACCEL_MAX_OUTPUT_RATE
#define MPU6000_GYRO_DEFAULT_DRIVER_FILTER_FREQ 30

#define MPU6000_DEFAULT_ONCHIP_FILTER_FREQ 42
#define MPU6000_DEFAULT_ONCHIP_FILTER_FREQ 98

#ifdef PX4_SPI_BUS_EXT
#define EXTERNAL_BUS PX4_SPI_BUS_EXT
Expand Down
5 changes: 0 additions & 5 deletions src/drivers/imu/mpu9250/mpu9250.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,6 @@ int MPU9250::reset_mpu()
// SAMPLE RATE
_set_sample_rate(_sample_rate);

// FS & DLPF FS=2000 deg/s, DLPF = 20Hz (low pass filter)
// was 90 Hz, but this ruins quality and does not improve the
// system response
_set_dlpf_filter(MPU9250_DEFAULT_ONCHIP_FILTER_FREQ);

// Gyro scale 2000 deg/s ()
Expand Down Expand Up @@ -830,14 +827,12 @@ MPU9250::ioctl(struct file *filp, int cmd, unsigned long arg)
// adjust filters
float cutoff_freq_hz = _accel_filter_x.get_cutoff_freq();
float sample_rate = 1.0e6f / ticks;
_set_dlpf_filter(cutoff_freq_hz);
_accel_filter_x.set_cutoff_frequency(sample_rate, cutoff_freq_hz);
_accel_filter_y.set_cutoff_frequency(sample_rate, cutoff_freq_hz);
_accel_filter_z.set_cutoff_frequency(sample_rate, cutoff_freq_hz);


float cutoff_freq_hz_gyro = _gyro_filter_x.get_cutoff_freq();
_set_dlpf_filter(cutoff_freq_hz_gyro);
_gyro_filter_x.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
_gyro_filter_y.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
_gyro_filter_z.set_cutoff_frequency(sample_rate, cutoff_freq_hz_gyro);
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/imu/mpu9250/mpu9250.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
#define MPU9250_GYRO_MAX_OUTPUT_RATE MPU9250_ACCEL_MAX_OUTPUT_RATE
#define MPU9250_GYRO_DEFAULT_DRIVER_FILTER_FREQ 30

#define MPU9250_DEFAULT_ONCHIP_FILTER_FREQ 41
#define MPU9250_DEFAULT_ONCHIP_FILTER_FREQ 92

#define MPUIOCGIS_I2C (unsigned)(DEVIOCGDEVICEID+100)

Expand Down

0 comments on commit 4ef3d25

Please sign in to comment.