Swerve Drive Programming

My team(Torbotics 2080) has recently gotten swerve drive. As lead programmer I am trying to program this type of drive. I found a few tutorials online, however the one I found was in Java. my team uses C++ I can’t figure out how to convert this bit of code to C++. Anyone that could help would be very appreciated. BTW the website we used as a guide was Part 2. Driving · FRC Swerve Drive Programming

Thanks

private WheelDrive backRight = new WheelDrive (0, 1, 0);
private WheelDrive backLeft = new WheelDrive (2, 3, 1);
private WheelDrive frontRight = new WheelDrive (4, 5, 2);
private WheelDrive frontLeft = new WheelDrive (6, 7, 3);

private SwerveDrive swerveDrive = new SwerveDrive (backRight, backLeft, frontRight, frontLeft);

private WheelDrive backRight;
private WheelDrive backLeft; 
private WheelDrive frontRight;
private WheelDrive frontLeft;

public SwerveDrive (WheelDrive backRight, WheelDrive backLeft, WheelDrive frontRight, 
WheelDrive frontLeft) {
    this.backRight = backRight;
    this.backLeft = backLeft;
    this.frontRight = frontRight;
    this.frontLeft = frontLeft;
 }

You’d have to reimplement the SwerveDrive, WheelDrive classes in C++

I’m not a programmer, but I did a little searching and found this C++ swerve implementation from 2481, if it helps.

1 Like

OK, thanks

WPILib has a swerve drive example (see “SwerveBot”) that has cleaner, more idiomatic C++.

https://docs.wpilib.org/en/stable/docs/software/examples-tutorials/wpilib-examples.html

Here’s the link from there: allwpilib/wpilibcExamples/src/main/cpp/examples/SwerveBot at master · wpilibsuite/allwpilib · GitHub. There’s been changes since the 2020.3.2 release that won’t build with 2020.3.2 (namely, splitting units.h into separate headers). If you don’t care about feedforward and slew rate limiting that were recently added, you could use the SwerveBot example that came with 2020.3.2.

4 Likes

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