From f946f48dce26cdcb042b92ed8a03e2c3ff3fdfec Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Fri, 28 Aug 2015 10:35:53 -0300 Subject: [PATCH] AP_InertialSensor: LSM9DS0: apply correction on each new sample These changes are for enabling unified accelerometer vibration and clipping calculation. For that, we need the values "rotated and corrected" before they are filtered and the calculation must be called as soon as a new sample arrives as it takes the sample rate into account. Thus, move code that applies "corrections" to be executed as soon as accel data arrive and call _publish_accel() passing rotate_and_correct parameter as false. Also, do the same for gyro so we can keep it consistent. --- .../AP_InertialSensor_LSM9DS0.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_LSM9DS0.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_LSM9DS0.cpp index 51a0d505ca..4192859864 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_LSM9DS0.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_LSM9DS0.cpp @@ -739,6 +739,8 @@ void AP_InertialSensor_LSM9DS0::_read_data_transaction_a() _accel_raw_data(&raw_data); Vector3f accel_data(raw_data.x, -raw_data.y, -raw_data.z); + accel_data *= _accel_scale; + _rotate_and_correct_accel(_accel_instance, accel_data); _accel_filtered = _accel_filter.apply(accel_data); _accel_sample_available = true; } @@ -752,23 +754,19 @@ void AP_InertialSensor_LSM9DS0::_read_data_transaction_g() _gyro_raw_data(&raw_data); Vector3f gyro_data(raw_data.x, -raw_data.y, -raw_data.z); + gyro_data *= _gyro_scale; + _rotate_and_correct_gyro(_gyro_instance, gyro_data); _gyro_filtered = _gyro_filter.apply(gyro_data); _gyro_sample_available = true; } bool AP_InertialSensor_LSM9DS0::update() { - Vector3f gyro = _gyro_filtered; - Vector3f accel = _accel_filtered; - _accel_sample_available = false; _gyro_sample_available = false; - accel *= _accel_scale; - gyro *= _gyro_scale; - - _publish_gyro(_gyro_instance, gyro); - _publish_accel(_accel_instance, accel); + _publish_gyro(_gyro_instance, _gyro_filtered, false); + _publish_accel(_accel_instance, _accel_filtered, false); if (_last_accel_filter_hz != _accel_filter_cutoff()) { _set_accel_filter(_accel_filter_cutoff());