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

Replace iterative solver in SwerveSetpointGenerator with direct solutions #944

Merged

Conversation

rmheuer
Copy link
Contributor

@rmheuer rmheuer commented Dec 20, 2024

This replaces the iterative root finder in SwerveSetpoint generator, used for findDriveMaxS and findSteeringMaxS, with direct solutions for each of them.
This is currently a draft because:

  • I derived these about 6 months ago so I don't remember the exact details, I will try to re-derive them and add explanations later.
  • It is currently untested as I am writing this on a Chromebook.

@github-actions github-actions bot added the PathPlannerLib Changes to PathPlannerLib label Dec 20, 2024
@rmheuer
Copy link
Contributor Author

rmheuer commented Dec 21, 2024

I have now added the derivations alongside the implementations, and verified that PathPlannerLib still builds. I have not yet tested this implementation with a robot project, although the solutions themselves have been tested and seem correct in my original implementation here.

@rmheuer
Copy link
Contributor Author

rmheuer commented Dec 21, 2024

I've noticed an oversight in my findSteeringMaxS implementation due to the domain of tan(x). That one may need some rethinking.

@rmheuer rmheuer marked this pull request as ready for review December 21, 2024 06:47
@mjansen4857
Copy link
Owner

Just out of curiosity, do you have any data on how this affects setpoints (if at all) and the performance?

Also, this will need to be added to the python version (maybe the c++ version as well depending on which gets merged first). I can help do the translation if you need it.

@rmheuer
Copy link
Contributor Author

rmheuer commented Dec 22, 2024

I wrote a small test that runs each implementation 1 million times with random inputs (source here), the results on my laptop are:

Steering:
Avg. time for iterative method: 813.218286 ns
Avg. time for direct method: 84.401104 ns
Drive:
Avg. time for iterative method: 514.946105 ns
Avg. time for direct method: 66.917233 ns

I don't currently have access to a RoboRIO to test on-robot performance, but I assume the results would be similar.

@mjansen4857 mjansen4857 enabled auto-merge (squash) December 23, 2024 00:48
@mjansen4857 mjansen4857 disabled auto-merge December 23, 2024 00:48
@mjansen4857 mjansen4857 enabled auto-merge (squash) December 23, 2024 00:48
@mjansen4857 mjansen4857 merged commit b39acb1 into mjansen4857:main Dec 23, 2024
24 checks passed
@rmheuer rmheuer deleted the setpoint-generator-direct-solutions branch December 23, 2024 01:11
Luis-Leyva added a commit to Luis-Leyva/pathplanner that referenced this pull request Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PathPlannerLib Changes to PathPlannerLib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants