Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Compass::getFieldStrength() & Acc::recalculatePitchRoll() to use floats. #177

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions source/driver-models/Accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions source/driver-models/Compass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down