-
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
Swerve Sim - first pass #3374
Swerve Sim - first pass #3374
Conversation
My initial thoughts...
|
To get a scale of the level of configuration needed, Here's a strawman of a library class mirroring off of
|
Copying some additional discussion from Discord:
|
Here's the relevant section: https://en.wikipedia.org/wiki/Skew-symmetric_matrix#Cross_product |
A status update, nothing more: Progress is been made over in the test repo I'm using. https://github.com/RobotCasserole1736/TestSwervePlantModel/tree/wpilib_stripout/src/main/java/frc/sim/wpiClasses contains what I'm looking to submit (along with unit tests and a barebones usage example) |
We're closer... but azimuth basic test is still failing... going to 1.0 all the time????
Since this has been dead a while, wanted to make sure we marked off where we're at:
|
I started looking at this and had a few questions, though these may be more generic wpilibj questions. Should the classes the Vector2d and Force2d move to a separate folder instead of drive or swerve, something like math, or geometry etc? Maybe edu.wpi.first.math.geometry. We're getting fairly close to build season, not sure if this will get into the release or not. One suggestion to at least have this as an easy package that folks can drop into their projects would be to split out the changes to Vector2d into a separate PR. That way there is no longer a dependency to this change, and a user could simply drop the entire swerve folder in their project. |
Likely yes - I had not picked any specific location - agree a math/utils related location would be better. There was still an open question in my head whether creating such classes for general usage was the right path for wpilib (I don't have a great notion as to how they'd get used outside this particular swerve simulation). Per tyler's comments above, there are more matrix-friendly techniques that could be used instead. I know I likely won't have the bandwidth between now and kickoff to really bring this to being production quality. The fact that this hasn't been validated against real-world data makes me leery to put it out there for general consumption. While it's good to keep referencing this (and the other repos where it's been applied - I still owe @jasondaming a review and some debug), the key is that consumers are still part of active development, not consuming a full finished product. |
That's understandable. Would you be willing to submit your changes to wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/Vector2d.java in a separate PR then? That way the rest of the code could be included as a single folder into user code for the upcoming season. Would be a nice way to get feedback. |
So I think the best way to achieve that objective is to just reference this folder from this repo. The reason I say that is because, as-is, this PR represents a departure from the way WPILib has been approaching physics simulation. For most mechanisms so far, the physics work has been done offline and compressed into matrices, which in turn play nicely with existing solutions like LinearSystem and friends. The vector/force/force-at-pose classes in this PR are starting to build up a more "online" free body diagram solver. I haven't yet proven out this is required. It expands the complexity of support for WPILib (two simulation paradigms rather than one). |
In my project I already have all of the changes in a separate folder and expect that is what teams will need to do for this year while this solution matures as I don't think there is any hope that this will make it into 2022. My goal is to get this out before the start of the season that can be used as a submodule |
What's the status of this PR? It would be super helpful for offseason swerves. |
Great question! I've been meaning to post an update here. My current opinion: I don't think this is ready for prime-time yet, for a few reasons: The biggest - the functionality contained here is too complex and fraught for mass distribution and support. There's some real debugging and know-how required to integrate it properly, especially if 3rd party motors and motor controllers are used (which is like 99% of the use case). And I know there's use-cases it doesn't cover. Case in point: one of the issues Jason (see above) ran into was that a CAN bus packet rate being applied to a particular I don't think WPILib has the bandwidth to support that level of debug with teams, and I'm worried about merging PR's which would trigger that - "well that's not our issue" is a demoralizing answer to give to a student who's just trying to get their software working, and I worry this PR is going to cause a huge uptick in those sorts of answers. Additionally - The work of doing some real-world validation of the physics implemented is still not done, and I don't have line-of-sight to achieve it myself over the next ~8 months. Finally, part of what enabled this to work well for our team was a set of custom dashboard widgets that allowed for quick, visual debug of the system behavior. The Oblog and NT4 work in flight lays some of the groundwork for this, but we need to make these things I'm definitely not the one to make a final decision on this and would be happy to help. But the couple of folks who have tried to pick it up have definitely make me realize there's a lot of work to be done on the deployment side still. Finally, it's worth considering that I don't know if this is significantly better than just assuming perfect kinematics and using that for simulation. This PR adds some motor dynamics and a frictional model.... but for a good swerve system, these should be largely negligible. And, I would gander to say that if you're doing swerve simulation, you probably have some good hardware too. One possible alternate approach- Incorporating this with SDS's libraries, and path planning (like what @jasondaming mentioned above) could help encapsulate it better to where teams won't have to worry about it. But, as we've been going back and forth, there's enough difficulty with dealing with vendor sim support that even this is fraught. |
If anyone came here looking for the "perfect kinematics" approach, you could use |
Alrighty. I got something that smells decent, looks correct..... But very purposefully putting this out there as a draft for discussion.
This PR adds a java example for simulating swerve drive, including vision processing for odometery correction.
Open questions in my mind:
. I like reusability, but the number of cross-dependent configurations makes me worry that folks are gonna struggle to configure it to be meaningful for their setup. I don't believe it would be nearly as "drop-in" as the other simulated mechanisms.
Ongoing work prior to a full release would probably involve some cleanup of constants (make sure everything the user should be touching for their bot is moved to one spot), trim out a few utility classes that I don't believe are actually needed currently, and review how well sim architecture was applied. I know I'd picked an alternate way of wrapping the gyro - there's probably a few architecture layers that could be trimmed away.
Discuss or reject as needed! Thanks folks!