Skip to content

Comments

Add Logging To Swerve#8

Open
JosephTLockwood wants to merge 1 commit into1-Swervefrom
2-Logging
Open

Add Logging To Swerve#8
JosephTLockwood wants to merge 1 commit into1-Swervefrom
2-Logging

Conversation

@JosephTLockwood
Copy link
Collaborator

@JosephTLockwood JosephTLockwood commented Oct 14, 2025

Summary by CodeRabbit

  • New Features

    • Introduces a swerve drivetrain with default driver controls and an autonomous mode chooser.
    • Adds PathPlanner integration with an example path and navigation grid.
    • Provides joystick/keyboard control presets and configurable robot settings.
    • Includes vision-aligned pose updates and simulation support for testing.
  • Improvements

    • Enables runtime data logging and telemetry annotations for better diagnostics.
  • Chores

    • Adds configuration assets for path planning and input mappings to support the new driving and autonomy features.

@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds PathPlanner vendor dependency and assets, introduces a new CommandSwerveDrivetrain subsystem with simulation, auto, and vision integration, updates Robot and RobotContainer for logging and control bindings, and adds driver station joystick mappings. No existing APIs are modified; new public class and field are introduced.

Changes

Cohort / File(s) Summary of changes
Driver Station GUI config
simgui-ds.json
New keyboard joystick mappings with axis/button/POV configurations; includes multiple profiles and an empty fallback profile.
PathPlanner assets
src/main/deploy/pathplanner/navgrid.json, src/main/deploy/pathplanner/paths/Example Path.path, src/main/deploy/pathplanner/settings.json
Adds navigation grid, example path definition, and robot/settings JSON for PathPlanner.
Drivetrain subsystem
src/main/java/frc/robot/subsystems/CommandSwerveDrivetrain.java
New public subsystem integrating Phoenix 6 swerve, simulation loop, AutoBuilder config, vision pose updates, command API, and accessors.
Robot init and container bindings
src/main/java/frc/robot/Robot.java, src/main/java/frc/robot/RobotContainer.java
Enables DataLog/Epilogue logging (@Logged), exposes public drivetrain, configures default teleop drive command, disabled idle, and autonomous chooser using PathPlanner.
Vendor dependency
vendordeps/PathplannerLib-2025.2.7.json
Adds PathPlannerLib vendor JSON with Java/C++ artifacts for 2025.2.7.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Driver as Driver (Joystick)
  participant RC as RobotContainer
  participant CDS as CommandSwerveDrivetrain
  participant PP as PathPlanner AutoBuilder

  rect rgb(240,248,255)
  note over RC: Initialization
  RC->>CDS: create drivetrain (constructors)
  RC->>PP: configureAutoBuilder(...)
  end

  alt Teleop enabled
    Driver->>RC: joystick axes/buttons
    RC->>CDS: applyRequest(SwerveRequest.Drive(...))
    CDS->>CDS: periodic() update & operator perspective
    CDS->>Swerve: set module states
  else Disabled
    RC->>CDS: Idle (brake/neutral per binding)
  end

  opt Vision updates
    Note over CDS: addVisionMeasurement(...)
    CDS->>CDS: fuse pose (odometry + vision)
  end

  rect rgb(245,255,245)
  note over RC: Autonomous
  RC->>PP: getSelectedAuto()
  PP-->>RC: Command (trajectory follower)
  RC->>CDS: execute generated commands
  CDS->>Swerve: follow path
  end
Loading
sequenceDiagram
  autonumber
  participant Robot as Robot
  participant DLM as DataLogManager
  participant Epi as Epilogue

  Robot->>DLM: start()
  Robot->>Epi: bind(this)
  Note over Robot: @Logged annotation active
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I wiggle my whiskers—paths align,
Grid cells twinkle, waypoints shine.
Logs now hum, the drivetrain sings,
AutoBuilder plots with springy wings.
With nimble hops and swervey zest,
This bunny debugs—then takes a rest. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title only mentions adding logging to the swerve subsystem, but the pull request also introduces multiple configuration JSON files, a new CommandSwerveDrivetrain class with PathPlanner integration, and epilogue setup, so it does not fully summarize the primary scope of changes. Revise the title to reflect the broader scope of this PR, for example “Integrate PathPlanner, Logging, and Configuration Resources in Swerve Subsystem,” so that it clearly conveys both the logging additions and the new drivetrain and JSON configuration files.
Docstring Coverage ⚠️ Warning Docstring coverage is 35.29% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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.

@JosephTLockwood
Copy link
Collaborator Author

@coderabbitai review

@JosephTLockwood JosephTLockwood changed the title 2 logging Add Logging To Swerver Oct 14, 2025
@JosephTLockwood JosephTLockwood changed the title Add Logging To Swerver Add Logging To Swerve Oct 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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

🧹 Nitpick comments (7)
src/main/java/frc/robot/RobotContainer.java (2)

40-40: Encapsulate drivetrain field

Expose via a getter instead of a public field to avoid leaking implementation details.

-  public final CommandSwerveDrivetrain drivetrain = TunerConstants.createDrivetrain();
+  private final CommandSwerveDrivetrain drivetrain = TunerConstants.createDrivetrain();

Add a getter (outside this hunk):

public CommandSwerveDrivetrain getDrivetrain() {
  return drivetrain;
}

79-82: Handle null autonomous selection

autoChooser.getSelected() can return null. Ensure caller handles this gracefully or provide a safe fallback command.

src/main/java/frc/robot/subsystems/CommandSwerveDrivetrain.java (5)

121-145: AutoBuilder wiring LGTM; consider externalizing gains

Configuration and feedforward hooks look correct. Consider moving the PID gains (10/0/0 and 7/0/0) to constants or config for easier tuning without code changes.


145-148: Improve error reporting content

Include the exception message to aid troubleshooting.

-      DriverStation.reportError(
-          "Failed to load PathPlanner config and configure AutoBuilder", ex.getStackTrace());
+      DriverStation.reportError(
+          "Failed to load PathPlanner config and configure AutoBuilder: " + ex.getMessage(),
+          ex.getStackTrace());

183-199: Notifier lifecycle: optional cleanup

Consider closing m_simNotifier when shutting down to prevent background thread leaks in long-running sims/tests.

Add:

public void close() {
  if (m_simNotifier != null) {
    m_simNotifier.close();
    m_simNotifier = null;
  }
}

207-210: Clarify timestamp timebase for vision

You convert FPGA timestamps to current time. Ensure callers pass FPGA time; otherwise this double-converts and skews timestamps. Add Javadoc note stating the expected timebase (FPGA).

Also applies to: 225-232


238-244: Defensive copies for array getters

Return copies to prevent external mutation of internal arrays.

-  public SwerveModuleState[] getModuleStates() {
-    return getState().ModuleStates;
-  }
+  public SwerveModuleState[] getModuleStates() {
+    return getState().ModuleStates.clone();
+  }
 
-  public SwerveModuleState[] getModuleTargets() {
-    return getState().ModuleTargets;
-  }
+  public SwerveModuleState[] getModuleTargets() {
+    return getState().ModuleTargets.clone();
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d1df75 and e1c58c5.

⛔ Files ignored due to path filters (1)
  • src/main/java/frc/robot/generated/TunerConstants.java is excluded by !**/generated/**
📒 Files selected for processing (8)
  • simgui-ds.json (1 hunks)
  • src/main/deploy/pathplanner/navgrid.json (1 hunks)
  • src/main/deploy/pathplanner/paths/Example Path.path (1 hunks)
  • src/main/deploy/pathplanner/settings.json (1 hunks)
  • src/main/java/frc/robot/Robot.java (1 hunks)
  • src/main/java/frc/robot/RobotContainer.java (1 hunks)
  • src/main/java/frc/robot/subsystems/CommandSwerveDrivetrain.java (1 hunks)
  • vendordeps/PathplannerLib-2025.2.7.json (1 hunks)
🔇 Additional comments (4)
src/main/deploy/pathplanner/paths/Example Path.path (1)

35-42: Verify constraints source

useDefaultConstraints is true, so globalConstraints are ignored. Confirm this is intended and that settings.json has the desired defaults.

Also applies to: 53-54

src/main/java/frc/robot/RobotContainer.java (1)

55-77: Drive bindings look correct

Axis directions and deadbands align with WPILib conventions; idle-on-disable is a good touch.

src/main/java/frc/robot/subsystems/CommandSwerveDrivetrain.java (2)

157-159: applyRequest helper is clean

Simple and idiomatic; no issues.


170-180: Alliance perspective application is robust

Applies once or on disable; avoids mid-match flips. Good pattern.

Comment on lines 46 to 48
autoChooser = AutoBuilder.buildAutoChooser("Tests");
SmartDashboard.putData("Auto Mode", autoChooser);

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Default auto likely mismatched

The chooser uses "Tests" as default. The repo adds "Example Path.path". Align the default to an existing auto to avoid null selection.

-    autoChooser = AutoBuilder.buildAutoChooser("Tests");
+    autoChooser = AutoBuilder.buildAutoChooser("Example Path");

🏁 Script executed:

#!/bin/bash
# Locate AutoBuilder file
rg --files-with-matches 'class AutoBuilder' -t java

# Show buildAutoChooser signature and surrounding lines
rg -nP --type=java -C5 'buildAutoChooser\('

# Search for 'Tests' literal in Java sources
rg -n '"Tests"' -t java

# Search for 'Example Path' literal in Java sources
rg -n '"Example Path"' -t java

# List any .path files in the repository
find . -type f -name "*.path"

Length of output: 965


Align default auto chooser to an existing path
Replace "Tests" with "Example Path" since only Example Path.path is present:

-    autoChooser = AutoBuilder.buildAutoChooser("Tests");
+    autoChooser = AutoBuilder.buildAutoChooser("Example Path");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
autoChooser = AutoBuilder.buildAutoChooser("Tests");
SmartDashboard.putData("Auto Mode", autoChooser);
autoChooser = AutoBuilder.buildAutoChooser("Example Path");
SmartDashboard.putData("Auto Mode", autoChooser);
🤖 Prompt for AI Agents
In src/main/java/frc/robot/RobotContainer.java around lines 46 to 48, the auto
chooser default string "Tests" does not match any existing path; change the
argument passed to AutoBuilder.buildAutoChooser from "Tests" to "Example Path"
so the chooser defaults to the existing Example Path.path, then keep putting the
chooser to SmartDashboard as before.

@JosephTLockwood JosephTLockwood changed the base branch from 1-Subsystem to 1-Swerve October 14, 2025 19:24
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.

1 participant