Skip to content

Improve drivetrain calculations#14

Open
Kyle-Eldridge wants to merge 5 commits intomainfrom
improve_drivetrain
Open

Improve drivetrain calculations#14
Kyle-Eldridge wants to merge 5 commits intomainfrom
improve_drivetrain

Conversation

@Kyle-Eldridge
Copy link
Contributor

This PR will improve the drivetrain speed and angle calculations. Previously, we made the wheels turn to turn the robot, which allowed the robot to drive without completely breaking the simulator physics. However, it still wasn't completely accurate, since the outer wheels have to travel a longer distance than the inner wheels, while the current code just drives them at the same speed.
To fix this, I modeled the robot's driving as following a circular path directly to the left or right of the center wheels. I calculate the radius of that circle, then figure out the speeds needed for each wheel to follow that path. The front and back wheels now rotate to be tangent to that circle as well.
The code in SlugbotDriver will not need to change if we switch to 4 wheels instead of 6., since the back wheels follow the circle the same way as the front ones. The center of the circle will be in line with the non-turning wheels instead of the center wheels.
This might not be perfect yet since there is a constant at the top of the code for the distance between wheels on the same side, but I don't want to try to get that from the proto file when we are getting the real CAD soon.

@Kyle-Eldridge
Copy link
Contributor Author

This PR also creates an empty Drivetrain class and a new launch file to make it easier to add to later.

@Kyle-Eldridge Kyle-Eldridge marked this pull request as draft January 21, 2026 22:43
@Kyle-Eldridge
Copy link
Contributor Author

Apparently, we have a rectangular swerve drive, so we need to rewrite the code for that.

@Kyle-Eldridge
Copy link
Contributor Author

Swerve finished

@Kyle-Eldridge Kyle-Eldridge marked this pull request as ready for review January 22, 2026 20:26
Copy link
Member

@GalexY727 GalexY727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make it through pose2d, translation2d, or rotation2d, and think that it might be beneficial to have unit tests for them which we can probably steal from wpilib directly. We would want that on some other directory, but still accessible from the main repository, most likely. Maybe it would be enough to have them ran through GitHub Actions, but that seems a little extra.

Overall, looks good! I left a lot of mostly cosmetic comments, but do want you to quickly look at the one regarding swerve::optimize, regarding the modulus operator. Well done Kyle!

@GalexY727 GalexY727 added the enhancement New feature or request label Jan 29, 2026
@GalexY727
Copy link
Member

Regarding the switch to swerve, however, I think it might be useful to keep the legacy drivetrain code in case we ever decide to switch off of swerve, even if it is in a year. I don't think it's as easy as just making an IO implementation, but it can still be a lone, untouched file without causing any collateral damage.

@Kyle-Eldridge
Copy link
Contributor Author

I added the old SlugbotDriver code in a commented out file so we can reference it in the future if needed. I don't think we need the Webots code, since it basically just sets the motors.

@GalexY727
Copy link
Member

Great judgment, thank you!

@GalexY727
Copy link
Member

Is this ready for merging or should we wait for something like cad so we can set track width?

@Kyle-Eldridge
Copy link
Contributor Author

We should not merge this yet.
Apparently, since the video is due next week, this version of the drivetrain will not have swerve. It is either 4 wheel tank drive (which might or might not be able to turn) or 45 degree pivots. I reimplemented tank drive on the prototype branch, and we can use the older version of the code on this branch if it has pivots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants