From 1309b7332a47323949f23f87be1d13074fc267d2 Mon Sep 17 00:00:00 2001 From: James Bielman Date: Fri, 4 Jan 2013 15:43:17 -0800 Subject: [PATCH] MPU6000: Use signed addition when accumulating readings. - Fixes very erratic accel readings on the PX4 board. --- libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp index e824695152..b7016fad93 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp @@ -374,9 +374,9 @@ void AP_InertialSensor_MPU6000::_read_data_transaction() { memset(tx,0,15); tx[0] = MPUREG_ACCEL_XOUT_H | 0x80; _spi->transaction(tx, rx, 15); - + for (uint8_t i = 0; i < 7; i++) { - _sum[i] += ((rx[2*i+1] << 8) | rx[2*i+2]); + _sum[i] += (int16_t)(((uint16_t)rx[2*i+1] << 8) | rx[2*i+2]); } _count++;