diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..c6c747aa --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,127 @@ +# Contributing to lib2813 + +We welcome contributions! + +## What to Contribute + +- Bug reports +- Bug fixes (consider filing a bug report first) +- Feature additions (please create an issue first) + +## Pull Request Guidelines + +- Code should be well documented. +- Please consider writing tests. Tests give us assurance that new changes do not break older functionality. +- We loosely follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). Format the code + using `./gradlew spotlessApply`. +- Write a [good change description](https://google.github.io/eng-practices/review/developer/cl-descriptions.html) + +We may ask you to test locally on your robot code in simulation mode. + +## Getting Started + +If you need to make changes to lib213, you can either clone the repository directly, or you +can include it as a submodule for your robot code. + +### Option 1: Developing on a Clone + +To clone the repository, run: + +```shell +git clone --recurse-submodules https://github.com/Prospect-Robotics/Robot2025.git +``` + +### Option 2: Developing via Submodules + +#### 1. Adding the lib2813 repo as a submodule + +When making changes to lib2813, it is often helpful to build the code along with your robot code. +To do that, you can add the lib2813 repo as a submodule. + +Before adding the submodule, it is recommended that you set the `submodule.stickyRecursiveClone` +git config option to `true` to make working with submodule easier (see +[this StackOverflow answer](https://stackoverflow.com/a/53622660) for details about this option). +To do this, run the following command from any directory: +```shell +git config --global submodule.stickyRecursiveClone true +``` + +To add the lib2813 submodule, go to your robot project directory (where the `settings.gradle` file is), and run +this command: +```shell +git submodule add https://github.com/Prospect-Robotics/lib2813 +``` + +#### 2. Updating Gradle files + +Add the following lines needs to be added to your `settings.gradle`: +``` +includeBuild('lib2813') { + dependencySubstitution { + substitute module('com.team2813.lib2813:lib') using project(':lib') + } +} +``` + +Next, remove the version numbers for the lib2813 dependencies in your `build.gradle`: + +``` +implementation "com.team2813.lib2813:lib" +``` + +Finally, in order to guarantee that the library jars are created before GradleRIO referees to them, add the following +lines to your `build.gradle`: +```groovy +downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':lib:jar') +downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':testing:jar') +downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':limelight:jar') +``` + +#### 3. Fixing vscode jank +As of version 1.85.1, vscode doesn't work properly with gradle composite builds without the old buildServer. To use the old buildServer, add the following line +to your settings.json +``` +"java.gradle.buildServer.enabled": "off", +``` +This isn't strictly necessary, but without it vscode will not be able to do code completion from things in the library, and tell the user that there are errors, +when gradle builds fine. + +## Tips and Tricks + +### Publishing to Maven Local + +It can often be useful to publish jars locally and test with a real or simulated robot. + +To publish to Maven Local, run: + +```shell +./gradlew publishToMavenLocal -Pversion=2.0.0-test-123 +``` + +(replace "test-123" with some unique identifier) + +In your robot's `build.gradle` file, be sure to include Maven Local in your repositories: + +```groovy +repositories { + mavenLocal() + mavenCentral() +} +``` + +Then update your `libs.versions.toml` to reference the version that you published locally. + +### Cloning a repository with a git submodule +When cloning a repository with a git submodule, git will not automatically get the files in the submodules. in order to do this, run the command +``` +git submodule update --init --recursive +``` +This command will recursively initialize all submodules. + +### Getting blame data + +To ignore code reformatting when running `git blame` run: + +```shell +git config blame.ignoreRevsFile .git-blame-ignore-revs +``` diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 00000000..3bfa71be --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,12 @@ +# Maintainer Documentation + +## Publishing to Maven Central + +Before publishing to Maven Central, consider publishing to Maven Local. + +1. Run `./gradlew build` to build the code, run the tests, and verify that there are no formatting + issues +2. Update the version string in `publishing-conventions.gradle`. +3. Make sure all changes are pushed to GitHub +4. ??? +5. Celebrate! diff --git a/README.md b/README.md index 4ea5156e..bd029d03 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,63 @@ # User Documentation -## adding submodule -In order to use, go to your WPILib project directory (the inner one, where the build.gradle file is), and run the command -``` -git submodule add https://github.com/Prospect-Robotics/lib2813 -``` -## adding submodule to gradle -The following lines needs to be added to your settings.gradle to make the lib usable: +## Using the libraries + +### Updating your dependencies + +> [!NOTE] +> The lib2813 jars are not yet published to Maven Central. For the time being, you need to publish +> them to Maven Local. See [the Contributing page](CONTRIBUTING.md#publishing-to-maven-local) for details. + +In your project's "gradle" directory, create a file named `libs.versions.toml` with the following content: + +```toml +[versions] +lib2813 = "2.0.0-rc-1" + +[libraries] +lib2813-lib = { module = "com.team2813.lib2813:lib", version.ref="lib2813" } +lib2813-vision = { module = "com.team2813.lib2813:vision", version.ref="lib2813" } +lib2813-limelight = { module = "com.team2813.lib2813:limelight", version.ref="lib2813" } +lib2813-testing = { module = "com.team2813.lib2813:testing", version.ref="lib2813" } ``` -includeBuild('lib2813') { - dependencySubstitution { - substitute module('com.team2813:lib2813') using project(':lib') - } + +In your `build.gradle`, update the `dependencies` section: + +```groovy +dependencies { + // Existing dependencies + implementation libs.lib2813.lib + implementation libs.lib2813.vision + implementation libs.lib2813.limelight + testImplementation libs.lib2813.testing } ``` -Whatever text that is in the module parentheses is the text that will need to be in an `implementation` statement to depend on the library. -So, after adding the lines to the settings.gradle, this line in the dependencies block will refer to the library. -``` -implementation "com.team2813:lib2813" -``` -Finally, in order to guarantee that the library jars are created before GradleRIO referees to them, add the following line to your build.gradle -``` -downloadDepsPreemptively.dependsOn gradle.includedBuild("lib2813").task(":lib:jar") -``` -## Fixing vscode jank -As of version 1.85.1, vscode doesn't work properly with gradle composite builds without the old buildServer. To use the old buildServer, add the following line -to your settings.json -``` -"java.gradle.buildServer.enabled": "off", -``` -This isn't strictly necessary, but without it vscode will not be able to do code completion from things in the library, and tell the user that there are errors, -when gradle builds fine. +Note that you do not need to include all the dependencies. See the [Runtime dependencies](#runtime-dependencies) +section for details. -## Cloning a repository with a git submodule -When cloning a repository with a git submodule, git will not automatically get the files in the submodules. in order to do this, run the command -``` -git submodule update --init --recursive +In addition be sure to include Maven Local in the list of repositories in your `build.gradle` +(needed until we publish to Maven Central): + +```groovy +repositories { + mavenLocal() + mavenCentral() +} ``` -This command will recursively initialize all submodules. -This code is still in development, and apis are still subject to change. The most likely thing to get removed is the swerve api, as ctre recently released their own. +### Upgrading -## Developer Documentation +To upgrade the version of the lib2813 libraries you are using, simply update the version string for "lib2813" in +`libs.versions.toml`. -To ignore code reformatting when running `git blame` run: +### Vendordeps -```shell -git config blame.ignoreRevsFile .git-blame-ignore-revs -``` +- `com.team2813.lib2813:lib`: + - `WPILibNewCommands.json` + - `Phoenix6.json` (if using Phoenix motors) + - `REVLib.json` (if using REV Robotics motors) +- `com.team2813.lib2813:vision`: + - `photonlib.json` +- `com.team2813.lib2813:testing`: + - `WPILibNewCommands.json` diff --git a/buildSrc/src/main/groovy/java-common-conventions.gradle b/buildSrc/src/main/groovy/java-common-conventions.gradle index 69bd59e3..6cd4c9ac 100644 --- a/buildSrc/src/main/groovy/java-common-conventions.gradle +++ b/buildSrc/src/main/groovy/java-common-conventions.gradle @@ -7,6 +7,7 @@ plugins { // Apply the java-library plugin for API and implementation separation. id 'java-library' id 'com.diffplug.spotless' + id 'idea' } java { @@ -119,5 +120,23 @@ javadoc { links += "https://codedocs.revrobotics.com/java/" // PhotonVision links += "https://javadocs.photonvision.org/release/" + + // Converts `@apiNote` paragraph to "Note: " section in the generated javadoc + tags += 'apiNote:a:Api Note:' + + // Converts `@implSpec` paragraph to "Implementation Requirements: " section in the generated javadoc + tags += 'implSpec:a:Implementation Requirements:' + } +} + +task sourceJar(type: Jar) { + from sourceSets.main.allJava + archiveClassifier = 'sources' +} + +idea { + module { + downloadJavadoc = true + downloadSources = true } } diff --git a/buildSrc/src/main/groovy/publishing-conventions.gradle b/buildSrc/src/main/groovy/publishing-conventions.gradle new file mode 100644 index 00000000..a26d596b --- /dev/null +++ b/buildSrc/src/main/groovy/publishing-conventions.gradle @@ -0,0 +1,32 @@ +plugins { + id 'maven-publish' +} + +version = '2.0.0-rc-1' + +publishing { + publications { + lib2813(MavenPublication) { + groupId = 'com.team2813.lib2813' + from components.java + artifact sourceJar + pom { + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + scm { + connection = 'scm:git:git://github.com/Prospect-Robotics/lib2813.git' + developerConnection = 'scm:git:git://github.com/Prospect-Robotics/lib2813.git' + url = 'https://github.com/Prospect-Robotics/lib2813' + } + organization { + name = 'FRC 2813 Gear Heads' + url = 'https://team2813.com' + } + } + } + } +} diff --git a/lib/build.gradle b/lib/build.gradle index 462d9652..fb4f6e8b 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,11 +1,9 @@ plugins { id 'java-common-conventions' + id 'publishing-conventions' id 'edu.wpi.first.GradleRIO' version '2026.1.1' - id 'maven-publish' } -version = '2.0.0-alpha.1' - dependencies { implementation wpi.java.deps.wpilib() implementation wpi.java.vendor.java() @@ -39,41 +37,19 @@ tasks.named('test') { systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true' } -javadoc { - options.tags = [ - // Converts `@apiNote` paragraph to "Note: " section in the generated javadoc - 'apiNote:a:Api Note:', - // Converts `@implSpec` paragraph to "Implementation Requirements: " section in the generated javadoc - 'implSpec:a:Implementation Requirements:' - ] -} - -task sourceJar(type: Jar) { - from sourceSets.main.allJava - archiveClassifier = 'sources' -} - publishing { publications { lib2813(MavenPublication) { - groupId = 'com.team2813.lib2813' - artifactId = 'lib2813' - from components.java - artifact sourceJar pom { name = '2813 Library' description = 'Frequently reused code written by team 2813' developers { developer { - id = 'mango' - name = 'kyle' + id = 'cuttestkittensrule' + name = 'Kyle' email = 'mangoiscute95@gmail.com' } } - organization { - name = '2813 Gear Heads' - url = 'https://team2813.com' - } } } } diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java b/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java index 08425cf2..2bd11e13 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java @@ -119,6 +119,7 @@ public final void setSetpoint(T position) { * Returns a command that sets the desired setpoint to the provided value. * * @param setpoint the position to go to. + * @since 2.0.0 */ public final Command setSetpointCommand(T setpoint) { return new InstantCommand(() -> this.setSetpoint(setpoint), this); @@ -168,6 +169,8 @@ public final void enable() { * *
The motor voltage will be set to zero, and the motor will not adjust to move towards the * current setpoint. + * + * @since 2.0.0 */ @Override public final void stopMotor() { @@ -200,23 +203,13 @@ public final void set(ControlMode mode, double demand) { motor.set(mode, demand); } - /** - * Clamps the given output value and provides it to the motor. - * - * @param output The output calculated by the PID algorithm. - * @param setpoint Ignored. - */ - private void useOutput(double output, double setpoint) { - motor.set(controlMode, clampOutput(output)); - } - /** * Clamps the given output value and provides it to the motor. * *
This is called by {@link #periodic()} if this subsystem is enabled.
*/
private void useOutput(double output) {
- useOutput(output, controller.getSetpoint());
+ motor.set(controlMode, clampOutput(output));
}
/**
@@ -227,6 +220,7 @@ private void useOutput(double output) {
* @param output Output provided by the PID controller.
* @return Output to provide to the motor.
* @see edu.wpi.first.math.MathUtil#clamp(double, double, double)
+ * @since 2.0.0
*/
protected double clampOutput(double output) {
return output;
@@ -384,7 +378,12 @@ public MotorSubsystemConfiguration startingPosition(Supplier This class simulates motor behavior by storing the most recent control mode and demand value.
* It also includes methods that make it easier to verify the current state of the motor.
+ *
+ * @since 2.0.0
*/
public class FakeMotor implements Motor {
private boolean isStopped = true;
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/CommandTester.java b/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/CommandTester.java
index 0819ca69..645385b3 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/CommandTester.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/CommandTester.java
@@ -21,6 +21,8 @@
* Allows tests to run commands.
*
* Tests can get an instance by using {@link WPILibExtension}.
+ *
+ * @since 2.0.0
*/
public interface CommandTester {
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/IsolatedNetworkTablesExtension.java b/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/IsolatedNetworkTablesExtension.java
index 7c4b47ac..c9c300c3 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/IsolatedNetworkTablesExtension.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/IsolatedNetworkTablesExtension.java
@@ -41,6 +41,8 @@
* }
* }
* }
+ *
+ * @since 2.0.0
*/
public final class IsolatedNetworkTablesExtension
implements Extension, AfterEachCallback, ParameterResolver {
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/WPILibExtension.java b/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/WPILibExtension.java
index f89f9696..7e96ddb2 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/WPILibExtension.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/junit/jupiter/WPILibExtension.java
@@ -59,6 +59,8 @@
* }
* }
* }
+ *
+ * @since 2.0.0
*/
public final class WPILibExtension
implements Extension,
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java
index 235551f1..50f523f9 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java
@@ -28,6 +28,8 @@
*
* See Writing your own custom subject to learn about
* creating custom Truth subjects.
+ *
+ * @since 2.0.0
*/
public final class Pose2dSubject extends Subject {
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java
index ae84c9dd..6b151b34 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java
@@ -28,6 +28,8 @@
*
* See Writing your own custom subject to learn about
* creating custom Truth subjects.
+ *
+ * @since 2.0.0
*/
public final class Pose3dSubject extends Subject {
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java
index 58d9165a..428c3812 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java
@@ -24,7 +24,11 @@
import edu.wpi.first.math.geometry.Rotation2d;
import javax.annotation.Nullable;
-/** Truth Subject for making assertions about {@link Rotation2d} values. */
+/**
+ * Truth Subject for making assertions about {@link Rotation2d} values.
+ *
+ * @since 2.0.0
+ */
public final class Rotation2dSubject extends Subject {
// User-defined entry point
public static Rotation2dSubject assertThat(@Nullable Rotation2d rotation) {
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java
index a9e67047..daf085f1 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java
@@ -24,7 +24,11 @@
import edu.wpi.first.math.geometry.Rotation3d;
import javax.annotation.Nullable;
-/** Truth Subject for making assertions about {@link Rotation3d} values. */
+/**
+ * Truth Subject for making assertions about {@link Rotation3d} values.
+ *
+ * @since 2.0.0
+ */
public final class Rotation3dSubject extends Subject {
// User-defined entry point
public static Rotation3dSubject assertThat(@Nullable Rotation3d rotation) {
diff --git a/testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java
index 2dd80643..c487fa13 100644
--- a/testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java
+++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java
@@ -20,6 +20,8 @@
/**
* A partially specified check about an approximate relationship to a {@code double} subject using a
* tolerance.
+ *
+ * @since 2.0.0
*/
public abstract class TolerantComparison