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

Fix for incorrect display on gyro for negative degrees #373

Merged
merged 4 commits into from
Jan 20, 2018

Conversation

rlee287
Copy link
Contributor

@rlee287 rlee287 commented Jan 19, 2018

This PR fixes #372 by implementing a getWrappedValue function.

Pinging @SamCarlberg since he wrote the original gyro code.

@frcjenkins
Copy link

Can one of the admins verify this patch?

@rlee287 rlee287 changed the title Gyro negative Fix for incorrect display on gyro for negative degrees Jan 19, 2018
@SamCarlberg SamCarlberg added widget bugfix Fixes one or more bugs labels Jan 19, 2018
@SamCarlberg
Copy link
Member

SamCarlberg commented Jan 19, 2018

Huh, I thought I had fixed that at one point.

Regardless, I think would be better logic. No loops.

if (value < 0) {
  return (360 + value) % 360;
} else {
  return value % 360;
}

And there's no need to cache value, since the GyroData (and all other data classes) are immutable

@rlee287
Copy link
Contributor Author

rlee287 commented Jan 19, 2018

The if statement does not properly handle cases when the angle is less than -360 degrees (TIO link). I have committed an alternate if statement that avoids loops but properly handles these cases (TIO link).

@SamCarlberg
Copy link
Member

Ah, my math was off a bit. Should be

if (value < 0) {
  return ((value % 360) + 360) % 360;
} else {
  return value % 360;
}

@rlee287
Copy link
Contributor Author

rlee287 commented Jan 19, 2018

I pushed up an adjusted if statement as you suggested and believe that this is now ready to merge in.

@SamCarlberg SamCarlberg merged commit 155fe52 into wpilibsuite:master Jan 20, 2018
@SamCarlberg
Copy link
Member

Thanks for submitting this fix!

@rlee287 rlee287 deleted the gyroNegative branch January 23, 2018 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes one or more bugs widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gyro widget does not properly display negative values
3 participants