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

[examples] Make swerve examples multiply desired module speeds by cosine of heading error #5758

Merged
merged 8 commits into from
Oct 13, 2023

Conversation

ori-coval
Copy link
Contributor

Completes issue #5749.

@ori-coval ori-coval requested review from a team as code owners October 11, 2023 23:12
@ori-coval ori-coval changed the title Make swerve examples multiply desired module speeds by cosine of heading error #5749 Make swerve examples multiply desired module speeds by cosine of heading error Oct 11, 2023
Copy link
Member

@calcmogul calcmogul left a 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.

@ori-coval
Copy link
Contributor Author

/format

Copy link
Member

@calcmogul calcmogul left a 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.

@calcmogul
Copy link
Member

calcmogul commented Oct 13, 2023

/format doesn't work if you use main as your PR branch. CI cancellations break too (other PRs who used the main branch can cancel your PR runs if they push changes to their PR).

@PeterJohnson PeterJohnson changed the title Make swerve examples multiply desired module speeds by cosine of heading error [examples] Make swerve examples multiply desired module speeds by cosine of heading error Oct 13, 2023
@PeterJohnson PeterJohnson merged commit 9a0aafd into wpilibsuite:main Oct 13, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make swerve examples multiply desired module speeds by cosine of heading error
4 participants