This library provides an easy-to-use abstraction over the core logic of a swerve drive. It is designed to be used with
FRC robots. This drive currently includes two main implementations: A FieldAwareSwerveDrive, which uses odometry to
track the position of the robot on the field, and a VisionAwareSwerveDrive, which uses odometry and vision measurements
to track the position of the robot on the field.
The primary interface, RunnymedeSwerve, provides a brief set of functions that allow the user to control the swerve
drive. It is designed to be used in a drive subsystem where the user can call drive to control the robot.
The current implementation only supports limited hardware configuration. Additional hardware configurations can be added when requested.
This library was heavily inspired by the FRC Swerve Library and the YAGSL libraries, but simplified to make it accessible to high school students.
It is designed to allow most FRC team members to be able to interact with it, and senior high school students to be able
to understand the code contained within it. With the exception of some edu.wpilib classes like SwerveDriveKinematics,
most of the code is written in a way that is easy to understand.
To use this library, add the following to your build.gradle file:
implementation 'ca.team1310:swerve:2.0.6'Then, configure the CoreSwerveConfig class to construct your swerve drive. If you are using VisionAwareSwerveDrive,
you will also need to configure the VisionConfig class.
There is no need to call any methods during your subsystem's periodic() method, as RunnymedeSwerve spints up
its own threads to perform all relevant periodic calculations.
...
public class SwerveSubsystem extends SubsystemBase {
...
private final RunnymedeSwerveDrive drive;
private final SubsystemConfig subsystemConfig;
private final CoreSwerveConfig coreConfig;
...
public SwerveSubsystem(SubsytemConfig subsystemConfig, CoreSwerveConfig coreConfig) {
this.drive = new FieldAwareSwerveDrive(coreConfig);
...
}
private void driveSafely(ChassisSpeeds robotOrientedVelocity) {
double x = robotOrientedVelocity.vxMetersPerSecond;
double y = robotOrientedVelocity.vyMetersPerSecond;
double w = robotOrientedVelocity.omegaRadiansPerSecond;
// Limit change in values. Note this may not scale
// evenly - one may reach desired speed before another.
// Use driveFieldOriented to avoid this.
x = xLimiter.calculate(x);
y = yLimiter.calculate(y);
w = omegaLimiter.calculate(w);
ChassisSpeeds safeVelocity = new ChassisSpeeds(x, y, w);
if (this.config.enabled()) {
this.drive.drive(safeVelocity);
}
}
...
}If you are actively developing this library, or require a local build for some reason, you can build the library locally.
./gradlew clean && \
./gradlew build && \
./gradlew publishToMavenLocalThis will publish the library to your local maven repository, which you can then reference in your project. However,
your project must include the mavenLocal() repository. WPILIB projects do not include this by default (they look for a
maven repository in a different location).
This project uses Google Java Format to format code. Please install the appropriate plugin for your IDE:
- IntelliJ IDEA: google-java-format
- And Add the following to your VM options (In
Help | Edit Custom VM Options):
- And Add the following to your VM options (In
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
- VSCode: google-java-format
- This will be suggested in
Extensionswhen you open the project in VSCode.
- This will be suggested in
- Eclipse: google-java-format
This project includes a pre-commit git hook that automatically checks code formatting before each commit. The hook works on both Mac and Windows.
To manually check formatting:
./gradlew spotlessCheckTo automatically fix formatting issues:
./gradlew spotlessApplyThe git hook is automatically installed when you run ./gradlew build. If a commit is blocked due to formatting issues, simply run ./gradlew spotlessApply to fix the formatting, then stage and commit your changes again.
You need to make a gradle.properties in the base directory, containing:
gpr.user=<github username>
gpr.token=<private access token>
To obtain a private access token, go to Tokens Classic and create a new Token with
write:packages and read:packages permissions.
Do Not Check This File In
We don't really know exactly what is required here yet but this seems to work
./gradlew clean && \
./gradlew publish && \
./gradlew jreleaserInit && \
./gradlew jreleaserDeploy./gradlew clean && \
./gradlew publish && \
./gradlew jreleaserDeploy