Skip to content

Final code#12

Open
GrahamSH-LLK wants to merge 10 commits intomainfrom
whyyyyyy
Open

Final code#12
GrahamSH-LLK wants to merge 10 commits intomainfrom
whyyyyyy

Conversation

@GrahamSH-LLK
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings May 28, 2025 01:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors path planning and integrates system-identification routines, while enhancing subsystem functionality and tuning.

  • Simplified RepulsorFieldPlanner API and removed deprecated network-table toggles.
  • Exposed open-loop interfaces in SwerveModule and added drive/steer SysId routines in DriveTrain.
  • Expanded LED subsystem with multiple flag-based patterns and introduced command wrappers.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
RepulsorFieldPlanner.java Unified force calculation, removed NT listeners, simplified sample API
SwerveModule.java Made motors public, added sysid flag and open-loop methods
LED.java Introduced LEDState enum, randomized and flag patterns
DriveTrain.java Added unit-safe SysId routines, updated autoAlign and stop command
Swerve.java Updated max speed, feedforward constants, PID tuning
Robot.java Registered SysId auto commands and LED-wrapped commands
Comments suppressed due to low confidence (3)

src/main/java/frc/robot/subsystems/SwerveModule.java:66

  • [nitpick] The field name sysid doesn’t follow typical camelCase or boolean naming conventions. Consider renaming it to isSysIdMode or sysIdEnabled for clarity.
public boolean sysid = false;

src/main/java/frc/robot/subsystems/DriveTrain.java:683

  • ChassisSpeeds is used but not imported in this file, which will lead to a compile error. Add import edu.wpi.first.math.kinematics.ChassisSpeeds;.
return runOnce(() -> { this.setChassisSpeeds(new ChassisSpeeds(0, 0, 0)); });

src/main/java/frc/robot/subsystems/DriveTrain.java:215

  • [nitpick] The delay 0.04 seconds is a magic number. Extract it into a named constant or add a comment explaining its purpose.
Commands.sequence(Commands.waitSeconds(0.04),Commands.waitUntil(driveTrain.atSetpoint))

Force getObstacleForce(Translation2d curLocation, Translation2d target) {
var force = Force.kZero;
for (Obstacle obs : FIELD_OBSTACLES) {
for (Obstacle obs : fixedObstacles) {
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

fixedObstacles is initialized as an empty list and never populated, so getObstacleForce (and walls) will always return zero. Consider initializing fixedObstacles with FIELD_OBSTACLES and WALLS or iterating over those constants directly.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

it's populated in ctor

Copy link
Member Author

Choose a reason for hiding this comment

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

@copilot it's populated in ctor, are you sure?

Comment on lines +35 to +36
public final SparkFlex m_drivingSpark;
public final SparkMax m_turningSpark;
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] Exposing the motor controllers as public fields breaks encapsulation. Consider keeping them private and providing getters or higher-level methods instead.

Suggested change
public final SparkFlex m_drivingSpark;
public final SparkMax m_turningSpark;
private final SparkFlex m_drivingSpark;
private final SparkMax m_turningSpark;

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
AddressableLEDBufferView m_right = m_ledBuffer.createView(0, 11);
AddressableLEDBufferView m_left = m_ledBuffer.createView(12, 22);
AddressableLEDBufferView m_middle = m_ledBuffer.createView(23, 34);
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The views m_right, m_left, and m_middle are created but never used in periodic(). Remove them or apply patterns to these views to avoid unused code.

Suggested change
AddressableLEDBufferView m_right = m_ledBuffer.createView(0, 11);
AddressableLEDBufferView m_left = m_ledBuffer.createView(12, 22);
AddressableLEDBufferView m_middle = m_ledBuffer.createView(23, 34);
// Removed unused views: m_right, m_left, and m_middle

Copilot uses AI. Check for mistakes.
ModuleConstants.kDrivingMotorReduction;
double turningFactor = 2 * Math.PI;
double drivingVelocityFeedForward = 1 / ModuleConstants.kDriveWheelFreeSpeedRps;
double drivingVelocityFeedForward = 2.0548;
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The hard-coded 2.0548 is a magic literal. Document its derivation or compute it explicitly to improve clarity.

Suggested change
double drivingVelocityFeedForward = 2.0548;
// Calculate driving velocity feed-forward gain based on motor free speed and wheel diameter.
double motorFreeSpeedMetersPerSecond = (MotorConstants.kFreeSpeedRpm / 60.0) *
(ModuleConstants.kWheelDiameterMeters * Math.PI / ModuleConstants.kDrivingMotorReduction);
double drivingVelocityFeedForward = 1.0 / motorFreeSpeedMetersPerSecond; // Inverse of max speed
// Explanation:
// - MotorConstants.kFreeSpeedRpm: Free speed of the motor in RPM.
// - ModuleConstants.kWheelDiameterMeters: Diameter of the wheel in meters.
// - ModuleConstants.kDrivingMotorReduction: Gear reduction factor for the driving motor.
// - motorFreeSpeedMetersPerSecond: Maximum speed of the robot in meters per second.
// - drivingVelocityFeedForward: Feed-forward gain calculated as the inverse of max speed.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +35 to +36
public final SparkFlex m_drivingSpark;
public final SparkMax m_turningSpark;
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

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

Making motor controllers public breaks encapsulation and exposes internal implementation details. Consider providing controlled access through getter methods instead of direct public field access.

Copilot uses AI. Check for mistakes.
* @param desiredState Desired state with speed and angle.
*/
public void setDesiredState(SwerveModuleState desiredState) {
if(sysid) return;
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

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

Missing space after 'if' keyword violates standard Java formatting conventions. Should be 'if (sysid) return;'.

Suggested change
if(sysid) return;
if (sysid) return;

Copilot uses AI. Check for mistakes.

// The gyro sensor
public final AHRS m_gyro = new AHRS(AHRS.NavXComType.kMXP_SPI);
public final AHRS m_gyro = new AHRS(AHRS.NavXComType.kUSB1);
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

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

Changing gyro connection from kMXP_SPI to kUSB1 is a significant hardware configuration change that should be documented or made configurable, as it affects robot hardware setup.

Suggested change
public final AHRS m_gyro = new AHRS(AHRS.NavXComType.kUSB1);
/**
* Hardware configuration: Set the NavX connection type here.
* If you change the physical connection (e.g., from USB to MXP), update this constant.
* Possible values: AHRS.NavXComType.kUSB1, AHRS.NavXComType.kMXP, etc.
*/
private static final AHRS.NavXComType GYRO_PORT_TYPE = AHRS.NavXComType.kUSB1;
public final AHRS m_gyro = new AHRS(GYRO_PORT_TYPE);

Copilot uses AI. Check for mistakes.
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.

3 participants