-
Notifications
You must be signed in to change notification settings - Fork 611
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
[examples] Make swerve examples multiply desired module speeds by cosine of heading error #5758
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment describing what this does/why this is here. Also, don't forget to do this change for the C++ examples as well. Here's what the C++ code should roughly look like (haven't compiled it).
state.speed *= (state.angle - Rotation2d{m_turningEncoder.GetDistance()}).Cos();
You could even reuse the encoder Rotation2d object since it's needed by the step before this. That would make this line of code easier to read too.
For the record, the order of subtraction doesn't matter since cosine is symmetric for positive and negative inputs. I just prefer writing error as desired - actual.
wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
Outdated
Show resolved
Hide resolved
wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
Outdated
Show resolved
Hide resolved
/format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion for the comment.
wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
Outdated
Show resolved
Hide resolved
|
Completes issue #5749.