From 4d141d5dd51ab858e6e5a7dabfd7c9cc38ec6b3f Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Tue, 26 Nov 2024 17:59:04 +0000 Subject: [PATCH] Update `Compass::getFieldStrength()` & `Acc::recalculatePitchRoll()` to use floats. --- source/driver-models/Accelerometer.cpp | 14 +++++++------- source/driver-models/Compass.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/driver-models/Accelerometer.cpp b/source/driver-models/Accelerometer.cpp index 2b6072af..674b32e9 100644 --- a/source/driver-models/Accelerometer.cpp +++ b/source/driver-models/Accelerometer.cpp @@ -487,18 +487,18 @@ float Accelerometer::getRollRadians() */ void Accelerometer::recalculatePitchRoll() { - double x = (double) sample.x; - double y = (double) sample.y; - double z = (double) sample.z; + float x = sample.x; + float y = sample.y; + float z = sample.z; - roll = atan2(x, -z); - pitch = atan2(y, (x*sin(roll) - z*cos(roll))); + roll = atan2f(x, -z); + pitch = atan2f(y, (x*sinf(roll) - z*cosf(roll))); // Handle to the two "negative quadrants", such that we get an output in the +/- 18- degree range. // This ensures that the pitch values are consistent with the roll values. - if (z > 0.0) + if (z > 0.0f) { - double reference = pitch > 0.0 ? (PI / 2.0) : (-PI / 2.0); + float reference = pitch > 0.0f ? ((float)PI / 2.0f) : ((float)(-PI) / 2.0f); pitch = reference + (reference - pitch); } diff --git a/source/driver-models/Compass.cpp b/source/driver-models/Compass.cpp index 18a4a6bc..e39164d9 100644 --- a/source/driver-models/Compass.cpp +++ b/source/driver-models/Compass.cpp @@ -125,11 +125,11 @@ int Compass::getFieldStrength() { Sample3D s = getSample(); - double x = s.x; - double y = s.y; - double z = s.z; + float x = s.x; + float y = s.y; + float z = s.z; - return (int) sqrt(x*x + y*y + z*z); + return (int) sqrtf(x*x + y*y + z*z); } /**