From 2b3017d346d028745b9e8c10e508430461edfbe7 Mon Sep 17 00:00:00 2001 From: Ishan <98932677+Ishan1522@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:34:28 -0400 Subject: [PATCH 1/8] add linting --- build.gradle | 12 +++++ pmd-ruleset.xml | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 pmd-ruleset.xml diff --git a/build.gradle b/build.gradle index d6ad0d4..97d5e1c 100644 --- a/build.gradle +++ b/build.gradle @@ -150,3 +150,15 @@ spotless { endWithNewline() } } + +apply plugin: "pmd" + +pmd { + toolVersion = "7.3.0" + consoleOutput = true + sourceSets = [project.sourceSets["main"]] + reportsDir = file("${project.buildDir}/reports/pmd") + ruleSetFiles = files(file("$rootDir/pmd-ruleset.xml")) + ruleSets = [] +} + diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml new file mode 100644 index 0000000..18b81bb --- /dev/null +++ b/pmd-ruleset.xml @@ -0,0 +1,127 @@ + + + + PMD Ruleset for WPILib + + .*/*JNI.* + .*/*IntegrationTests.* + .*/math/proto.* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Use Objects.requireNonNull() instead of throwing a + NullPointerException yourself. + + + + + + + + 3 + + + + + \ No newline at end of file From 734767ec9a8e21c3aee898bdfca2efa3a4d7d9f8 Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sat, 14 Sep 2024 18:35:10 -0400 Subject: [PATCH 2/8] format --- .vscode/settings.json | 3 +++ build.gradle | 1 - pmd-ruleset.xml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 97d5e1c..f99f391 100644 --- a/build.gradle +++ b/build.gradle @@ -161,4 +161,3 @@ pmd { ruleSetFiles = files(file("$rootDir/pmd-ruleset.xml")) ruleSets = [] } - diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml index 18b81bb..b3a3741 100644 --- a/pmd-ruleset.xml +++ b/pmd-ruleset.xml @@ -124,4 +124,4 @@ ]]> - \ No newline at end of file + From 9d3aa5e4122589289b36dfe01cf034e22d9dc5fe Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sat, 14 Sep 2024 18:36:21 -0400 Subject: [PATCH 3/8] delete .vscode --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index c5f3f6b..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.configuration.updateBuildConfiguration": "interactive" -} \ No newline at end of file From bf480d2d93f6f9b5d4e2bc387ec934288c743c95 Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sat, 14 Sep 2024 19:53:01 -0400 Subject: [PATCH 4/8] things --- src/main/java/frc/robot/subsystems/vision/VisionSubsystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/vision/VisionSubsystem.java b/src/main/java/frc/robot/subsystems/vision/VisionSubsystem.java index 420129a..bcc2e04 100644 --- a/src/main/java/frc/robot/subsystems/vision/VisionSubsystem.java +++ b/src/main/java/frc/robot/subsystems/vision/VisionSubsystem.java @@ -27,7 +27,7 @@ public class VisionSubsystem extends SubsystemBase { * The pose estimates from the limelights in the following order {shooterLimelight, * frontLeftLimelight, frontRightLimelight} */ - private PoseEstimate[] limelightEstimates; + private final PoseEstimate[] limelightEstimates; public VisionSubsystem() { limelightEstimates = new PoseEstimate[3]; From 6c3e68547f4eeecf94f72f1933f49bec52b23b52 Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sun, 22 Sep 2024 17:40:13 -0400 Subject: [PATCH 5/8] idk --- .github/workflows/build.yml | 28 ++++++++++++++++++- pmd-ruleset.xml | 4 +-- src/main/java/frc/robot/Constants.java | 16 +++++------ src/main/java/frc/robot/RobotContainer.java | 12 ++++---- .../robot/commands/shooter/AutoSpinUp.java | 27 +++--------------- 5 files changed, 46 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2613331..7069b53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,4 +45,30 @@ jobs: java-version: 17 distribution: temurin - name: Run formatter - run: ./gradlew spotlessCheck \ No newline at end of file + run: ./gradlew spotlessCheck + + pmd-code-scan: + name: "Linter" + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + - name: Run PMD + id: pmd + uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 + with: + rulesets: 'pmd-ruleset.xml' + # sourcePath: 'src/main/java' + analyzeModifiedFilesOnly: false + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: pmd-report.sarif \ No newline at end of file diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml index b3a3741..6b724c8 100644 --- a/pmd-ruleset.xml +++ b/pmd-ruleset.xml @@ -6,9 +6,7 @@ PMD Ruleset for WPILib - .*/*JNI.* - .*/*IntegrationTests.* - .*/math/proto.* + .*/LimeligtHelpers.java diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index f29710f..0906b79 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -415,7 +415,7 @@ public static final class PivotConstants { public static final double SHOOT_TRAP_ANGLE = 0; public static final double PIVOT_ACCEPTABLE_ERROR = 0.015; - public static double[][] SPEAKER_PIVOT_POSITION = { + public static final double[][] SPEAKER_PIVOT_POSITION = { // Distance, Angle (rotations) {1.3, 0.029}, {1.5, 0.037265625}, @@ -438,7 +438,7 @@ public static final class PivotConstants { {4.9, 0.1135} }; - public static double[][] PASS_PIVOT_POSITION = { + public static final double[][] PASS_PIVOT_POSITION = { // Distance, Angle (rotations) {10.680643009839416, 0.037400390625}, {9.11398136590441, 0.038}, @@ -482,24 +482,24 @@ public static final class ShooterConstants { public static final double AUTO_SHOOT_P = 5; // 7 --> 4.5 --> 5 public static final double AUTO_SHOOT_I = 0.0; public static final double AUTO_SHOOT_D = 0.0; - public static Constraints AUTO_SHOOT_CONSTRAINTS = + public static final Constraints AUTO_SHOOT_CONSTRAINTS = new Constraints(DriveConstants.MAX_ANGULAR_SPEED_RADIANS_PER_SECOND, 2); public static final double AUTO_SHOOT_MOVE_P = 10.0; public static final double AUTO_SHOOT_MOVE_I = 0.0; public static final double AUTO_SHOOT_MOVE_D = 0.0; - public static Constraints AUTO_SHOOT_MOVE_CONSTRAINTS = new Constraints(10, 5); + public static final Constraints AUTO_SHOOT_MOVE_CONSTRAINTS = new Constraints(10, 5); public static final double AUTO_LINEUP_ROTATION_P = 3; public static final double AUTO_LINEUP_ROTATION_I = 0.0; public static final double AUTO_LINEUP_ROTATION_D = 0.0; - public static Constraints AUTO_LINEUP_ROTATION_CONSTRAINTS = + public static final Constraints AUTO_LINEUP_ROTATION_CONSTRAINTS = new Constraints(DriveConstants.MAX_ANGULAR_SPEED_RADIANS_PER_SECOND, 2); public static final double AUTO_LINEUP_TRANSLATION_P = 10; // 4.5, 4.0 public static final double AUTO_LINEUP_TRANSLATION_I = 0.0; public static final double AUTO_LINEUP_TRANSLATION_D = 0.0; - public static Constraints AUTO_LINEUP_TRANSLATION_CONSTRAINTS = new Constraints(1, 1); + public static final Constraints AUTO_LINEUP_TRANSLATION_CONSTRAINTS = new Constraints(1, 1); // TODO: calc public static final double NOTE_LAUNCH_VELOCITY_METERS_PER_SECOND = 10.8; @@ -552,13 +552,13 @@ public static final class TrajectoryConstants { public static final double AUTO_ALIGN_TRANSLATIONAL_I = 0; public static final double AUTO_ALIGN_TRANSLATIONAL_D = 0; - public static Constraints AUTO_ALIGN_TRANSLATION_CONSTRAINTS = new Constraints(5, 2); + public static final Constraints AUTO_ALIGN_TRANSLATION_CONSTRAINTS = new Constraints(5, 2); public static final double AUTO_ALIGN_ROTATIONAL_P = 3; public static final double AUTO_ALIGN_ROTATIONAL_I = 0; public static final double AUTO_ALIGN_ROTATIONAL_D = 0; - public static Constraints AUTO_ALIGN_ROTATIONAL_CONSTRAINTS = + public static final Constraints AUTO_ALIGN_ROTATIONAL_CONSTRAINTS = new Constraints(DriveConstants.MAX_ANGULAR_SPEED_RADIANS_PER_SECOND, 2); } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 3735de8..4193dcf 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -223,7 +223,7 @@ private void configureButtonBindings() { Trigger driverRightBumper = new Trigger(driverController::getRightBumper); Trigger driverRightDirectionPad = new Trigger(() -> driverController.getPOV() == 90); - Trigger driverDownDirectionPad = new Trigger(() -> driverController.getPOV() == 180); + // Trigger driverDownDirectionPad = new Trigger(() -> driverController.getPOV() == 180); Trigger driverLeftDirectionPad = new Trigger(() -> driverController.getPOV() == 270); // autodrive @@ -233,8 +233,8 @@ private void configureButtonBindings() { Trigger operatorLeftTrigger = new Trigger(() -> operatorController.getLeftTriggerAxis() > 0.2); Trigger operatorLeftBumper = new Trigger(operatorController::getLeftBumper); // amp and speaker - Trigger operatorBButton = new Trigger(operatorController::getBButton); - Trigger operatorRightBumper = new Trigger(operatorController::getRightBumper); + // Trigger operatorBButton = new Trigger(operatorController::getBButton); + // Trigger operatorRightBumper = new Trigger(operatorController::getRightBumper); Trigger operatorRightTrigger = new Trigger(() -> operatorController.getRightTriggerAxis() > 0.2); Trigger driverRightTrigger = new Trigger(() -> driverController.getRightTriggerAxis() > 0.2); @@ -246,13 +246,13 @@ private void configureButtonBindings() { DoubleSupplier operatorRightStickY = operatorController::getRightY; // unused Trigger operatorUpDirectionPad = new Trigger(() -> operatorController.getPOV() == 0); - Trigger operatorLeftDirectionPad = new Trigger(() -> operatorController.getPOV() == 270); + // Trigger operatorLeftDirectionPad = new Trigger(() -> operatorController.getPOV() == 270); Trigger operatorDownDirectionPad = new Trigger(() -> operatorController.getPOV() == 180); Trigger driverLeftTrigger = new Trigger(() -> driverController.getLeftTriggerAxis() > 0.2); Trigger driverLeftBumper = new Trigger(driverController::getLeftBumper); Trigger driverBButton = new Trigger(driverController::getBButton); - Trigger driverYButton = new Trigger(driverController::getYButton); - DoubleSupplier operatorLeftStickY = operatorController::getLeftY; + // Trigger driverYButton = new Trigger(driverController::getYButton); + // DoubleSupplier operatorLeftStickY = operatorController::getLeftY; // DRIVER BUTTONS diff --git a/src/main/java/frc/robot/commands/shooter/AutoSpinUp.java b/src/main/java/frc/robot/commands/shooter/AutoSpinUp.java index b6af24b..c6f42ab 100644 --- a/src/main/java/frc/robot/commands/shooter/AutoSpinUp.java +++ b/src/main/java/frc/robot/commands/shooter/AutoSpinUp.java @@ -26,16 +26,12 @@ public class AutoSpinUp extends DriveCommandBase { private final DriveSubsystem driveSubsystem; private final ShooterSubsystem shooterSubsystem; private final PivotSubsystem pivotSubsystem; - private final VisionSubsystem visionSubsystem; private final LEDSubsystem leds; private final DoubleSupplier leftX, leftY, rightX; private final BooleanSupplier isFieldRelative; - private double headingError = 0; - - private boolean isRed = false; - private double desiredHeading = 0; + private double desiredHeading; private Translation2d speakerPos; /** Creates a new SpinUpForSpeaker. */ @@ -53,7 +49,6 @@ public AutoSpinUp( this.driveSubsystem = driveSubsystem; this.shooterSubsystem = shooterSubsystem; this.pivotSubsystem = pivotSubsystem; - this.visionSubsystem = visionSubsystem; this.leftX = leftX; this.leftY = leftY; this.rightX = rightX; @@ -66,14 +61,8 @@ public AutoSpinUp( @Override public void initialize() { Optional alliance = DriverStation.getAlliance(); - // if alliance is detected - if (alliance.isPresent()) { - // and if it's red, we're red - isRed = alliance.get() == Alliance.Red; - } else { - // otherwise default to red alliance - isRed = true; - } + boolean isRed = alliance.get() == Alliance.Red; + // SmartDashboard.putBoolean("red", isRed); speakerPos = isRed @@ -89,15 +78,10 @@ public void execute() { // get positions of various things Translation2d robotPos = driveSubsystem.getPose().getTranslation(); - // distance (for speaker lookups) - double distance = robotPos.getDistance(speakerPos); // arctangent for desired heading desiredHeading = Math.atan2((robotPos.getY() - speakerPos.getY()), (robotPos.getX() - speakerPos.getX())); - // current - headingError = desiredHeading - driveSubsystem.getOdometryRotation2d().getRadians(); - // allow the driver to drive slowly (NOT full speed - will mess up shooter) driveSubsystem.drive( deadband(leftY.getAsDouble()) * DriveConstants.MAX_SPEED_METERS_PER_SECOND, @@ -129,10 +113,7 @@ public boolean isFinished() { } public boolean isInRange() { - if (desiredHeading > 25) { - return true; - } - return false; + return (desiredHeading > 25); } private double deadband(double val) { From 29d83aad6c287de68e999009403a29531f82bc4b Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sun, 22 Sep 2024 17:44:34 -0400 Subject: [PATCH 6/8] oki doiiiiiiikii --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7069b53..35f2bf6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,7 @@ jobs: - name: Run formatter run: ./gradlew spotlessCheck - pmd-code-scan: + lint: name: "Linter" permissions: contents: read # for actions/checkout to fetch code @@ -56,10 +56,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: - java-version: '11' + java-version: 17 distribution: 'temurin' - name: Run PMD id: pmd From cc3e1482296fa36a1571c7e7f694120e05ecf325 Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sun, 22 Sep 2024 17:49:46 -0400 Subject: [PATCH 7/8] ok this will work for sure --- .github/workflows/build.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 35f2bf6..d669b0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,13 +49,16 @@ jobs: lint: name: "Linter" + runs-on: ubuntu-latest permissions: contents: read # for actions/checkout to fetch code security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status - runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Grant execute permission for gradlew + run: chmod +x gradlew - name: Set up JDK 17 uses: actions/setup-java@v4 with: From 5a59a94f4c7457a926b306c221eef2d37792682d Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sun, 22 Sep 2024 17:58:19 -0400 Subject: [PATCH 8/8] try dis --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d669b0e..d6dd8c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,9 +50,9 @@ jobs: lint: name: "Linter" runs-on: ubuntu-latest - permissions: - contents: read # for actions/checkout to fetch code - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + # permissions: + # contents: read # for actions/checkout to fetch code + # security-events: write # for github/codeql-action/upload-sarif to upload SARIF results steps: - uses: actions/checkout@v4 with: