-
Notifications
You must be signed in to change notification settings - Fork 665
[wpimath] Add 2D variants of MathUtil.applyDeadband
and MathUtil.copySignPow
for circular joystick inputs
#8057
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
base: main
Are you sure you want to change the base?
[wpimath] Add 2D variants of MathUtil.applyDeadband
and MathUtil.copySignPow
for circular joystick inputs
#8057
Conversation
I feel like applyDeadband and copySignPow (both 1d and 2d) could be moved to their own file, like suggested by @calcmogul in #6903. Probably for 2027
But would want feedback to confirm. I was thinking JoystickMathUtil, or the suggested DriverUtil. |
MathUtil.applyDeadband
and MathUtil.copySignPow2d
for circular joystick inputsMathUtil.applyDeadband
and MathUtil.copySignPow2d
for circular joystick inputs
…aelLesirge/allwpilib into math-util-joystick-input-2d
Finally got back to this. I went with using Vectors, and made it work for 2d, 3d, etc, while on it. I could only figure out how to implement the function for vectors of doubles cause I am a bit of a template noob and trying to use units with vectors was giving difficult errors. |
Looks like Eigen assumes that the sqrt of the scalar type can be converted to the scalar type: allwpilib/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Core/MathFunctions.h Line 286 in 4e6b970
However, this isn't true for units, so I'm not sure what we should do. Also, the name CopySignPow doesn't really make sense for vectors, since vectors don't have signs. Maybe CopyDirectionPow or MagnitudePow? Ideally the name we pick can also be used for the scalar version. (Fortunately the original CopySignPow was added in #8013 after the last stable release, so we should have more leeway to change the name without going through a whole deprecation cycle) |
Could I do that in this pull request? |
You could probably use a different name for the new methods, but it might be nicer if changing the original version was a separate PR. I'm not really sure though- @calcmogul What do you think? |
Yea, if a feature hasn't been in a release yet, we can rename it to whatever we want with no warning.
Yes. |
This PR adds two new utility methods to Java/C++
MathUtil
for 2D joystick processingTranslation2d applyDeadband2d(Translation2d value, double deadband, double maxDistance)
Translation2d copySignPow2d(Translation2d value, double exponent, double maxDistance)
These functions are useful for teams using joysticks with circular input profiles, which is a common practice. Currently, MathUtil.deadband and MathUtil.copySignPow only support 1D inputs, so teams often end up writing custom logic that combines hypot, atan2, and Transform2d.
For example this:
Could be done like this:
I believe this is correct for WPILib because this is a pretty generic function which a lot of teams already do, but adding it here would increase visibility and allow newer teams to find this more easily and implement it, improving their performance.