Any suggestions for Swerve Drive Code

Our team is going to use swerve drive next season and I need help with code.Can anyone share their example Java Code for swerve? Thanks.

1 Like

This github repo has code for a swerve drivebase.


Edit: dang got beat to it, I should really click links.


I’m great at giving unsolicited advice, so here ya go:

In the context of computer science, “Code” is actually a plural word! It’s awesome because it shaves off 20% of your keystrokes when talking about “more than one piece of code”. I’ve learned that if one speaks like an expert, people around them usually assume they are indeed an expert.

But, I’d say the above repo is the way to go to start.

Also, if you haven’t yet, I’d definitely recommend reaching out to the mentors on your team for more strategies on building up understanding of how swerve drives work, and how to program them. From what I hear, they are pretty good mentors.


I love this idea! Infinite Recharge III, #3fast3furious will definitely be well-suited to swerve drive. But we decided to go with a Killough platform design instead. The advantage being that no matter what happens to the robot in competition, you always know that it is pointing in the same direction.

1 Like

I’d also take a look at the WPILib classes for Swerve. SwerveDriveKinematics and SwerveDriveOdometry. Once you have your subsystem built out (basically just access to the drive and turn motors), it takes like 10 lines of code at most to get a field-centric swerve working with it.

We built it out the old-fashioned way first this year (using formulas derived way back by Ether), and then converted to WPILib. And I’d say doing it that way was valuable to understand some of the underlying math behind a swervedrive, but WPILib makes it downright trivial.


This paper by @Ether provides great resources for the math and theory behind swerve! Miss you, @Ether!


FWIW: I apologize for the snark in my initial message.

It was motivated because, at least according to your profile at the time, you claimed to be on team 254. Given they’d just put out swerve drive prototypes and info, it seemed like a very strange request, which confused me greatly. I’d assumed the intent was trolling, rather than a legitimate search for info - this was my mistake, and I apologize.

Hopefully the details from others have provided some direction!


Seeing that you have now changed your team number three times since the time you made this post, including claiming to be on 254… I don’t think you have the right to be snarky here.

Also… Stop pretending to be on teams.


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.