Skip to content

86 drive heading#87

Merged
thatnerdjack merged 9 commits into
mainfrom
86-drive-heading
Oct 18, 2025
Merged

86 drive heading#87
thatnerdjack merged 9 commits into
mainfrom
86-drive-heading

Conversation

@arcadeArchitect
Copy link
Copy Markdown
Contributor

@arcadeArchitect arcadeArchitect commented Oct 18, 2025

drive heading, slow mode multiplier updated to 0.5

Summary by CodeRabbit

  • New Features

    • Configurable slow-mode multiplier (adjustable slow driving)
    • Snap-to-heading with right-stick toggle and coral-station alignment via triggers (lock/unlock rotation)
  • Refactor

    • Internal package/namespace reorganization and import updates across subsystems and commands

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 18, 2025

Walkthrough

Adds PID-based heading snap and coral-station lock/unlock commands, updates RobotContainer bindings to use those commands and a slow-mode constant, renames CoralInAndOut package to lowercase, and refreshes build metadata.

Changes

Cohort / File(s) Summary
Build metadata
src/main/java/org/team5924/frc2025/BuildConstants.java
Updated build/git metadata: GIT_REVISION 270 → 278, GIT_SHA, GIT_DATE, GIT_BRANCH86-drive-heading, BUILD_DATE, BUILD_UNIX_TIME; DIRTY unchanged.
Configuration constants
src/main/java/org/team5924/frc2025/Constants.java
Added public static final double SLOW_MODE_MULTI = 0.5.
Robot container / bindings
src/main/java/org/team5924/frc2025/RobotContainer.java
Use SLOW_MODE_MULTI for slow mode; added trigger bindings for lockOnCoralStation/unlockRotation, right-stick toggle for snap-to-heading; updated CoralInAndOut import paths (package casing change).
Drive subsystem heading control
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java
Added PID-based heading snap state/controller, desiredHeading and snapToHeading, methods toggleSnapToHeading(), setSnapToHeading(boolean), setDesiredHeading(double), updateSpeedsWithDesiredHeading(...); integrated snap behavior into velocity update.
Drive command helpers
src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java
Added isFlipped(), getCoralStationRotation(boolean), lockOnCoralStation(Drive,boolean), and unlockRotation(Drive) helper commands.
CoralInAndOut package rename
src/main/java/org/team5924/frc2025/subsystems/rollers/...
Package declarations changed from org.team5924.frc2025.subsystems.rollers.CoralInAndOutorg.team5924.frc2025.subsystems.rollers.coralInAndOut across: CoralInAndOut.java, CoralInAndOutIO.java, CoralInAndOutIOKrakenFOC.java, CoralInAndOutIOSim.java.
CoralInAndOut command imports
src/main/java/org/team5924/frc2025/commands/coralInAndOut/*
Updated import paths (casing/package) in RunIntake.java, RunShooter.java, TeleopShoot.java.
Robot state imports
src/main/java/org/team5924/frc2025/RobotState.java
Updated import path for CoralState to match package rename.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Driver
    participant RobotContainer
    participant Drive
    participant PID as PIDController

    Driver->>RobotContainer: press right trigger
    RobotContainer->>Drive: lockOnCoralStation(right=true)
    Drive->>Drive: setDesiredHeading(targetHeading)
    Drive->>Drive: setSnapToHeading(true)

    loop snap-to-heading enabled
        Drive->>PID: compute heading error
        PID-->>Drive: angular correction (omega)
        Drive->>Drive: updateSpeedsWithDesiredHeading(apply omega)
    end

    Driver->>RobotContainer: press/release left trigger
    RobotContainer->>Drive: unlockRotation()
    Drive->>Drive: setSnapToHeading(false)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • marisa07
  • thatnerdjack

Poem

🐰 I hopped through code at break of day,
I nudged a PID to find the way,
Coral locks and headings true,
Packages tidy, bindings new,
Hooray — the rabbit shipped a play! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title "86 drive heading" appears to be derived directly from the branch name "86-drive-heading" and includes the branch number as part of the title, which introduces noise. While the changes do include drive heading functionality (specifically, heading snapping capabilities added to the Drive subsystem), the title is overly abbreviated and does not clearly convey what was actually implemented. A teammate scanning the history might not immediately understand whether this is adding a feature, fixing an issue, or simply updating logic related to drive heading without additional context from the PR description. Consider revising the title to be more descriptive and remove the branch number prefix. A clearer alternative would be something like "Add heading snapping to Drive subsystem" or "Implement coral station alignment with heading control" which better communicates the specific technical changes and makes the commit history more informative.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 86-drive-heading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

thatnerdjack
thatnerdjack previously approved these changes Oct 18, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (2)

147-161: Public snap state API is clear; consider using Rotation2d for type safety.

Optional: make desiredHeading a Rotation2d and expose getters to avoid rad/deg mix-ups.


410-413: Snap overrides driver omega; confirm intended behavior.

With snapToHeading true, joystick rotation is ignored. If you want manual override within tolerance, gate the override with joystick magnitude.

src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java (3)

75-80: Duplicate alliance logic; reuse helper consistently.

You already provide isFlipped(). Replace local re-computations elsewhere (e.g., joystickDrive, turnTo* helpers) to reduce drift.


86-96: getCoralStationRotation OK; consider returning Rotation2d.

Returning a Rotation2d avoids sign/radian mistakes and reads better at call sites.


359-414: Legacy turnToLeft/Right duplicate snapping math.

Now that getCoralStationRotation exists and Drive handles snapping, consider removing or delegating these to reduce duplication.

Also applies to: 416-469

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 871c7ab and 62b7b64.

⛔ Files ignored due to path filters (3)
  • vendordeps/AdvantageKit.json is excluded by none and included by none
  • vendordeps/PathplannerLib-2025.2.7.json is excluded by none and included by none
  • vendordeps/Phoenix6-frc2025-latest.json is excluded by none and included by none
📒 Files selected for processing (13)
  • src/main/java/org/team5924/frc2025/BuildConstants.java (1 hunks)
  • src/main/java/org/team5924/frc2025/Constants.java (1 hunks)
  • src/main/java/org/team5924/frc2025/RobotContainer.java (3 hunks)
  • src/main/java/org/team5924/frc2025/RobotState.java (1 hunks)
  • src/main/java/org/team5924/frc2025/commands/coralInAndOut/RunIntake.java (1 hunks)
  • src/main/java/org/team5924/frc2025/commands/coralInAndOut/RunShooter.java (1 hunks)
  • src/main/java/org/team5924/frc2025/commands/coralInAndOut/TeleopShoot.java (1 hunks)
  • src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java (1 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (3 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOut.java (1 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIO.java (1 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIOKrakenFOC.java (1 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIOSim.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java (1)
src/main/java/org/team5924/frc2025/Constants.java (1)
  • Constants (42-284)
src/main/java/org/team5924/frc2025/RobotContainer.java (4)
src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIOKrakenFOC.java (1)
  • CoralInAndOutIOKrakenFOC (27-119)
src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIOSim.java (1)
  • CoralInAndOutIOSim (23-31)
src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java (1)
  • DriveCommands (47-470)
src/main/java/org/team5924/frc2025/Constants.java (1)
  • Constants (42-284)
🔇 Additional comments (13)
src/main/java/org/team5924/frc2025/BuildConstants.java (1)

24-30: LGTM! Auto-generated build metadata.

These changes are automatically generated build constants that reflect the current repository state, branch name, and build timestamp. The updates are expected and appropriate for a build constants file.

src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIOSim.java (1)

17-17: Package rename follows Java naming conventions.

The package rename from CoralInAndOut to coralInAndOut correctly follows Java conventions where package names should be lowercase.

src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIO.java (1)

17-17: Package rename follows Java naming conventions.

Consistent with the broader refactoring to use lowercase package names per Java conventions.

src/main/java/org/team5924/frc2025/RobotState.java (1)

28-28: Import updated to match package rename.

The import correctly reflects the new lowercase package structure.

src/main/java/org/team5924/frc2025/Constants.java (1)

59-59: New slow mode constant looks good.

The SLOW_MODE_MULTI constant is well-named, appropriately typed, and the value of 0.5 is reasonable for slow mode operation (50% speed reduction).

src/main/java/org/team5924/frc2025/commands/coralInAndOut/RunShooter.java (1)

21-22: Imports updated to match package rename.

Both import statements correctly reference the new lowercase package structure.

src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOut.java (1)

17-17: Package rename applied consistently.

The core subsystem class correctly uses the new lowercase package name per Java conventions.

src/main/java/org/team5924/frc2025/commands/coralInAndOut/RunIntake.java (1)

21-22: Imports updated to match package rename.

Import statements correctly reference the new lowercase package structure.

src/main/java/org/team5924/frc2025/commands/coralInAndOut/TeleopShoot.java (1)

23-24: Imports updated to match package rename.

Import statements correctly reference the new lowercase package structure, completing the consistent refactoring across all affected files.

src/main/java/org/team5924/frc2025/subsystems/rollers/CoralInAndOut/CoralInAndOutIOKrakenFOC.java (1)

17-17: Package path rename looks good; verify folder casing on disk.

Ensure the directory is actually renamed to rollers/coralInAndOut to match the new package on case-sensitive filesystems and CI agents. Also confirm all imports/usages were updated across the repo.

src/main/java/org/team5924/frc2025/RobotContainer.java (3)

53-58: CoralInAndOut import path rename LGTM.

Matches the package change; build should resolve.


220-229: Slow mode uses Constants.SLOW_MODE_MULTI = 0.5 — good centralization.

Change is clear and consistent across axes.


266-274: Trigger orchestration depends on lock/unlock being one-shot.

Given current DriveCommands.lockOnCoralStation/unlockRotation use run(), locking persists after release. After switching to runOnce (see suggested diff), this binding set works as intended: press to lock, release both triggers to unlock.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (1)

147-151: Make fields private and add proper documentation.

The heading-related fields should be private to encapsulate internal state. Additionally, headingPid should be final since it's never reassigned, and all fields should have javadoc comments explaining their purpose.

Apply this diff:

-  // in radians
-  private double desiredHeading = 0.0;
-  private boolean snapToHeading = false;
-
-  PIDController headingPid = new PIDController(3, 0, 0);
+  /** Desired heading in radians for snap-to-heading control. */
+  private double desiredHeading = 0.0;
+  
+  /** Whether snap-to-heading control is currently enabled. */
+  private boolean snapToHeading = false;
+  
+  /** PID controller for heading correction with continuous input enabled. */
+  private final PIDController headingPid = new PIDController(3, 0, 0);
🧹 Nitpick comments (1)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (1)

153-163: Add javadoc and consider normalizing the heading input.

These public methods lack documentation and setDesiredHeading doesn't validate or normalize the input angle, which could lead to unexpected behavior if values outside the [-π, π] range are passed.

Apply this diff:

+  /** Toggles snap-to-heading control on/off. */
   public boolean toggleSnapToHeading() {
     return snapToHeading = !snapToHeading;
   }
 
+  /** 
+   * Enables or disables snap-to-heading control.
+   * @param snap true to enable, false to disable
+   */
   public void setSnapToHeading(boolean snap) {
     snapToHeading = snap;
   }
 
+  /** 
+   * Sets the desired heading for snap-to-heading control.
+   * @param heading the target heading in radians
+   */
   public void setDesiredHeading(double heading) {
-    desiredHeading = heading;
+    desiredHeading = MathUtil.angleModulus(heading);
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62b7b64 and 8a97b9b.

📒 Files selected for processing (3)
  • src/main/java/org/team5924/frc2025/BuildConstants.java (1 hunks)
  • src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java (1 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/org/team5924/frc2025/commands/drive/DriveCommands.java
  • src/main/java/org/team5924/frc2025/BuildConstants.java
🔇 Additional comments (3)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (3)

34-34: LGTM!

The imports are necessary for the heading snapping implementation.

Also applies to: 36-36


252-252: LGTM!

Continuous input is correctly enabled for the heading PID controller, which properly handles angle wrap-around at ±π.


415-417: LGTM!

The heading snapping integration is correctly implemented with a conditional check to only apply it when enabled.

Comment thread src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/org/team5924/frc2025/BuildConstants.java (1)

24-29: Consider excluding auto-generated build files from version control.

This file is explicitly marked as automatically generated (Line 19) and contains build metadata that changes with every build. Committing it creates noisy diffs, frequent merge conflicts, and makes code review harder. Additionally, DIRTY = 1 (Line 30) indicates uncommitted changes, which shouldn't be reflected in a committed build file.

Add this file to .gitignore:

+# Auto-generated build constants
+src/main/java/org/team5924/frc2025/BuildConstants.java

Then remove it from the repository:

git rm --cached src/main/java/org/team5924/frc2025/BuildConstants.java

The build system will regenerate this file automatically when needed, ensuring each developer and CI build has accurate metadata without polluting version control.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a97b9b and 55b0919.

📒 Files selected for processing (2)
  • src/main/java/org/team5924/frc2025/BuildConstants.java (1 hunks)
  • src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (1)

384-402: Fix critical PID usage error and extract magic number.

Some issues from the previous review have been addressed (passing raw angle to PID, consistent object creation), but two remain:

  1. Line 399: Calling headingPid.close() every cycle is incorrect. The close() method is for resource cleanup and should only be called once when the controller is no longer needed. Calling it repeatedly will cause the PID controller to malfunction.

  2. Line 388: The tolerance value Math.toRadians(3.0) is a magic number and should be a named constant.

Apply this diff:

+  private static final double HEADING_TOLERANCE_RAD = Math.toRadians(3.0); // ±3 degrees
+
   /**
    * rotates the speeds towards the desired heading with a ±3 degree tolerance
    *
    * @param speeds input speeds that will be updated
    * @param targetHeading the desired heading (rotation)
    * @return updated speeds
    */
   public ChassisSpeeds updateSpeedsWithDesiredHeading(ChassisSpeeds speeds, double targetHeading) {
-    // tolerance of ±3 deg
     double currentHeading = getRotation().getRadians();
     double error = MathUtil.angleModulus(targetHeading - currentHeading);
-    boolean isWithinTolerance = Math.abs(error) <= Math.toRadians(3.0);
+    boolean isWithinTolerance = Math.abs(error) <= HEADING_TOLERANCE_RAD;

     if (isWithinTolerance)
       return new ChassisSpeeds(
           speeds.vxMetersPerSecond,
           speeds.vyMetersPerSecond,
           0.0); // within tolerance; don't rotate

-    // calculate omega
     double omega = headingPid.calculate(currentHeading, targetHeading);
     omega = MathUtil.clamp(omega, -getMaxAngularSpeedRadPerSec(), getMaxAngularSpeedRadPerSec());
-    headingPid.close();

     return new ChassisSpeeds(speeds.vxMetersPerSecond, speeds.vyMetersPerSecond, omega);
   }
🧹 Nitpick comments (3)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (3)

147-149: Make fields private.

These fields should be private instead of package-private for better encapsulation.

Apply this diff:

-  // in radians
-  private double desiredHeading = 0.0;
-  private boolean snapToHeading = false;
+  // in radians
+  private double desiredHeading = 0.0;
+  private boolean snapToHeading = false;

151-151: Extract PID gains to named constants.

The PID gains (3, 0, 0) are magic numbers and should be extracted to named constants for maintainability and tuning.

Apply this diff:

+  private static final double HEADING_KP = 3.0;
+  private static final double HEADING_KI = 0.0;
+  private static final double HEADING_KD = 0.0;
+
-  PIDController headingPid = new PIDController(3, 0, 0);
+  private PIDController headingPid = new PIDController(HEADING_KP, HEADING_KI, HEADING_KD);

161-163: Consider adding validation for heading parameter.

The method accepts any double value without validation. Consider adding a check or documentation about expected range (e.g., radians in [-π, π]).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55b0919 and 1bad658.

📒 Files selected for processing (1)
  • src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (3)
src/main/java/org/team5924/frc2025/subsystems/drive/Drive.java (3)

34-36: LGTM!

The imports are appropriate for the heading snap functionality.


252-252: LGTM!

Enabling continuous input for the heading PID controller is correct for angle control.


412-414: LGTM!

The integration of heading snap into runVelocity is clean and correct.

@thatnerdjack thatnerdjack merged commit aa68bc4 into main Oct 18, 2025
3 checks passed
@thatnerdjack thatnerdjack deleted the 86-drive-heading branch October 18, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants