From a06c1b9529d7fb321ff87fef5037288c9248c87c Mon Sep 17 00:00:00 2001 From: sfncrp Date: Thu, 17 Oct 2024 12:59:29 +0200 Subject: [PATCH 1/2] fixed resolution --- src/MPU6050.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/MPU6050.cpp b/src/MPU6050.cpp index c27f7a0..8f1c94e 100644 --- a/src/MPU6050.cpp +++ b/src/MPU6050.cpp @@ -66,10 +66,10 @@ void MPU6050_Base::initialize() { setClockSource(MPU6050_CLOCK_PLL_XGYRO); setFullScaleGyroRange(MPU6050_GYRO_FS_250); - gyroscopeResolution = 250.0 / 16384.0; + gyroscopeResolution = 250.0 / 32768.0; setFullScaleAccelRange(MPU6050_ACCEL_FS_2); - accelerationResolution = 2.0 / 16384.0; + accelerationResolution = 2.0 / 32768.0; setSleepEnabled(false); // thanks to Jack Elston for pointing this one out! } @@ -92,54 +92,54 @@ void MPU6050_Base::initialize(ACCEL_FS accelRange, GYRO_FS gyroRange) { { case ACCEL_FS::A2G: setFullScaleAccelRange(MPU6050_ACCEL_FS_2); - accelerationResolution = 2.0 / 16384.0; + accelerationResolution = 2.0 / 32768.0; break; case ACCEL_FS::A4G: setFullScaleAccelRange(MPU6050_ACCEL_FS_4); - accelerationResolution = 4.0 / 16384.0; + accelerationResolution = 4.0 / 32768.0; break; case ACCEL_FS::A8G: setFullScaleAccelRange(MPU6050_ACCEL_FS_8); - accelerationResolution = 8.0 / 16384.0; + accelerationResolution = 8.0 / 32768.0; break; case ACCEL_FS::A16G: setFullScaleAccelRange(MPU6050_ACCEL_FS_16); - accelerationResolution = 16.0 / 16384.0; + accelerationResolution = 16.0 / 32768.0; break; default: Serial.println("Init accelRange not valid, setting maximum accel range"); setFullScaleAccelRange(MPU6050_ACCEL_FS_16); - accelerationResolution = 16.0 / 16384.0; + accelerationResolution = 16.0 / 32768.0; } switch (gyroRange) { case GYRO_FS::G250DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_250); - gyroscopeResolution = 250.0 / 16384.0; + gyroscopeResolution = 250.0 / 32768.0; break; case GYRO_FS::G500DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_500); - gyroscopeResolution = 500.0 / 16384.0; + gyroscopeResolution = 500.0 / 32768.0; break; case GYRO_FS::G1000DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_1000); - gyroscopeResolution = 1000.0 / 16384.0; + gyroscopeResolution = 1000.0 / 32768.0; break; case GYRO_FS::G2000DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_2000); - gyroscopeResolution = 2000.0 / 16384.0; + gyroscopeResolution = 2000.0 / 32768.0; break; default: Serial.println("Init gyroRange not valid, setting maximum gyro range"); setFullScaleGyroRange(MPU6050_GYRO_FS_2000); - gyroscopeResolution = 2000.0 / 16384.0; + gyroscopeResolution = 2000.0 / 32768.0; } setSleepEnabled(false); // thanks to Jack Elston for pointing this one out! @@ -3415,7 +3415,7 @@ void MPU6050_Base::PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops){ int16_t eSample; uint32_t eSum; uint16_t gravity = 8192; // prevent uninitialized compiler warning - if (ReadAddress == 0x3B) gravity = 16384 >> getFullScaleAccelRange(); + if (ReadAddress == 0x3B) gravity = 32768 >> getFullScaleAccelRange(); Serial.write('>'); for (int i = 0; i < 3; i++) { I2Cdev::readWords(devAddr, SaveAddress + (i * shift), 1, (uint16_t *)&Data, I2Cdev::readTimeout, wireObj); // reads 1 or more 16 bit integers (Word) From fc862d14e8deed55ac54f11abb1f31993a895226 Mon Sep 17 00:00:00 2001 From: sfncrp Date: Thu, 17 Oct 2024 15:10:15 +0200 Subject: [PATCH 2/2] gravity value was correct --- src/MPU6050.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MPU6050.cpp b/src/MPU6050.cpp index 8f1c94e..81a3332 100644 --- a/src/MPU6050.cpp +++ b/src/MPU6050.cpp @@ -3415,7 +3415,7 @@ void MPU6050_Base::PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops){ int16_t eSample; uint32_t eSum; uint16_t gravity = 8192; // prevent uninitialized compiler warning - if (ReadAddress == 0x3B) gravity = 32768 >> getFullScaleAccelRange(); + if (ReadAddress == 0x3B) gravity = 16384 >> getFullScaleAccelRange(); Serial.write('>'); for (int i = 0; i < 3; i++) { I2Cdev::readWords(devAddr, SaveAddress + (i * shift), 1, (uint16_t *)&Data, I2Cdev::readTimeout, wireObj); // reads 1 or more 16 bit integers (Word)