From 6c3e68547f4eeecf94f72f1933f49bec52b23b52 Mon Sep 17 00:00:00 2001 From: Ishan1522 Date: Sun, 22 Sep 2024 17:40:13 -0400 Subject: [PATCH] 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) {