Simple swerve drive implementation in java by Eric Engelhart
This was originally created for Team 1251 who can be found at team1251.org
Create 4 instances of SwerveWheel with 2 PIDControllers for each wheel.
SwerveWheel frontRight = new SwerveWheel(frontRightRotation, frontRightSpeed);
Create an instance of SwerveDrive using the 4 SwerveWheels intances from Step 1.
SwerveDrive driveTrain = new SwerveDrive(frontRight, frontLeft, backLeft, backRight);
Alternatively, add a gyro to the constructor for a field-oriented swerve drive.
SwerveDrive driveTrain = new SwerveDrive(frontRight, frontLeft, backLeft, backRight, horizontalGyro);
Set the robot's wheelbase and trackwidth using the setWheelbaseTrackwidth() method
driveTrain.setWheelbaseTrackwidth(ROBOT_WHEELBASE, ROBOT_TRACKWIDTH);
In your main robot loop add a call to the SwerveDrive drive() method and pass your two joysticks in.
driveTrain.drive(directionController, rotationController);
That's it! If your PIDs are tuned correctly, you should now have a working swerve drive. If not, make sure that the issue is in the library and not due to inaccurate sensors, or incorrect usage of the library.
If you can confirm that the issue exists in the library, feel free to open an issue.