WPILib Swerve Code

Looking over the Swerve Drive code sample from WPILIB (allwpilib/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java at main · wpilibsuite/allwpilib · GitHub). Most of it makes sense, but I’m struggling to understand what these lines do:

private final SwerveModule m_frontLeft = new SwerveModule(1, 2, 0, 1, 2, 3);
private final SwerveModule m_frontRight = new SwerveModule(3, 4, 4, 5, 6, 7);
private final SwerveModule m_backLeft = new SwerveModule(5, 6, 8, 9, 10, 11);
private final SwerveModule m_backRight = new SwerveModule(7, 8, 12, 13, 14, 15);

Any help on this would be most appreciated.

See this file (or below) for an explanation:

  public SwerveModule( 
       int driveMotorChannel, 
       int turningMotorChannel, 
       int driveEncoderChannelA, 
       int driveEncoderChannelB, 
       int turningEncoderChannelA, 
       int turningEncoderChannelB) {
2 Likes

These should probably be named constants in that example…

2 Likes

GitHub does have some tools for finding references but often it still feels like a treasure hunt. For the same but easier to follow code, create a new Java Project for the SwerveBot example in your VSCode. You get the whole robot program at once and it’s easy to find references including referenced library classes.

If you hover over the second SwerveModule word in the line of code you show, the explanation shows immediately with the good Java doc explanation. Even if no Java doc had been provided, it’s still fairly easy to see the parameter list of the called method with nicely named variables.

3 Likes

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