Skip to content

Conversation

@SnappleRamen
Copy link
Contributor

This branch added Choreo autos that the robot can run in simulation.

@markpete
Copy link

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Choreo autonomous routines, which is a great addition. My review focuses on ensuring the new code is robust, maintainable, and free of bugs. I've found a critical compilation error in Robot.java due to an extra brace, along with a few high-severity issues related to shared state in PID controllers and incorrect use of units in the simulation code. There are also several medium-severity suggestions to improve code quality, such as removing unused code, fixing formatting, and improving encapsulation. Please review the detailed comments for suggestions on how to address these points.

Comment on lines 145 to 181
public void autonomousInit() {
Shuffleboard.startRecording();
if (SubsystemConstants.DRIVEBASE_ENABLED && AutoLogic.getSelectedAuto() != null) {
AutoLogic.getSelectedAuto().schedule();
}
//AutoLogic.getSelectedAuto().schedule();


new Routines().runRoutine().schedule();


if (subsystems.climbPivotSubsystem != null) {
subsystems.climbPivotSubsystem.moveCompleteFalse();
}
}
}

Choose a reason for hiding this comment

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

critical

This method has a few issues:

  1. Critical Syntax Error: There's an extra closing brace } on line 181 that will cause a compilation failure.
  2. High Severity Logic Change: The if (subsystems.climbPivotSubsystem != null) block has been nested inside the outer if block. This is likely unintentional and changes the behavior of the autonomous initialization, as moveCompleteFalse() will now only be called if a drivebase is enabled and an auto is selected.
  3. Readability: The code contains commented-out lines and excessive whitespace, which hurts readability.

I've provided a suggestion that fixes all these issues by cleaning up the code, removing the extra brace, and restoring the original logic for the conditional blocks.

  public void autonomousInit() {
    Shuffleboard.startRecording();
    if (SubsystemConstants.DRIVEBASE_ENABLED && AutoLogic.getSelectedAuto() != null) {
      new Routines().runRoutine().schedule();
    }

    if (subsystems.climbPivotSubsystem != null) {
      subsystems.climbPivotSubsystem.moveCompleteFalse();
    }
  }

(bottomZ + ((currentPositionRotations - minPos) / (maxPos - minPos)) * (topZ - bottomZ));
double wristPos = dblSub.get();
//System.out.println("Wrist pose is:" + wristPos);
m_posePublisher.set(new Pose3d(0.2, 0.0, targetZ, new Rotation3d(-90, wristPos,-0)));

Choose a reason for hiding this comment

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

high

The Rotation3d constructor expects angles in radians, but it appears you are passing degrees for the roll component (-90). This will result in an incorrect rotation in the simulation. You should convert the degree values to radians using Math.toRadians(). The wristPos value is also likely in degrees and should be converted as well.

Suggested change
m_posePublisher.set(new Pose3d(0.2, 0.0, targetZ, new Rotation3d(-90, wristPos,-0)));
m_posePublisher.set(new Pose3d(0.2, 0.0, targetZ, new Rotation3d(Math.toRadians(-90), Math.toRadians(wristPos), 0)));

Comment on lines 221 to 222
this.setControl(new SwerveRequest.ApplyFieldSpeeds().withSpeeds(speeds)
.withSpeeds(speeds));

Choose a reason for hiding this comment

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

high

The .withSpeeds(speeds) method is called twice here. This is redundant and likely a copy-paste error. The second call should be removed.

          this.setControl(new SwerveRequest.ApplyFieldSpeeds().withSpeeds(speeds));

Comment on lines 65 to 67
public PIDController pidX = AutoAlign.AutoAlignCommand.pidX;
public PIDController pidY = AutoAlign.AutoAlignCommand.pidX;
public PIDController pidRotate = AutoAlign.AutoAlignCommand.pidRotate;

Choose a reason for hiding this comment

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

high

There are a couple of issues with these PID controllers:

  1. pidY is incorrectly initialized with AutoAlign.AutoAlignCommand.pidX instead of pidY. This is a bug.
  2. These PID controllers are being shared from AutoAlign.AutoAlignCommand where they are public static. This is a poor design practice as it creates shared mutable state between different components (AutoAlignCommand and CommandSwerveDrivetrain), which can lead to unexpected behavior. This class should have its own private, final PID controller instances for trajectory following. The corresponding fields in AutoAlign.AutoAlignCommand should be reverted to be non-static instance fields.
Suggested change
public PIDController pidX = AutoAlign.AutoAlignCommand.pidX;
public PIDController pidY = AutoAlign.AutoAlignCommand.pidX;
public PIDController pidRotate = AutoAlign.AutoAlignCommand.pidRotate;
public PIDController pidX = new PIDController(4, 0, 0);
public PIDController pidY = new PIDController(4, 0, 0);
public PIDController pidRotate = new PIDController(8, 0, 0);

Comment on lines +187 to +189
public static PIDController pidX = new PIDController(4, 0, 0);
public static PIDController pidY = new PIDController(4, 0, 0);
public static PIDController pidRotate = new PIDController(8, 0, 0);

Choose a reason for hiding this comment

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

high

These PID controllers should not be public static. Making them static creates a shared, mutable state between all instances of AutoAlignCommand and other classes that use them (like CommandSwerveDrivetrain). This is a dangerous pattern that can lead to unpredictable behavior and hard-to-debug issues. They should be instance fields (e.g., private final) to ensure each command has its own state.

Suggested change
public static PIDController pidX = new PIDController(4, 0, 0);
public static PIDController pidY = new PIDController(4, 0, 0);
public static PIDController pidRotate = new PIDController(8, 0, 0);
private final PIDController pidX = new PIDController(4, 0, 0);
private final PIDController pidY = new PIDController(4, 0, 0);
private final PIDController pidRotate = new PIDController(8, 0, 0);

new SwerveRequest.SysIdSwerveSteerGains();
private final SwerveRequest.SysIdSwerveRotation m_rotationCharacterization =
new SwerveRequest.SysIdSwerveRotation();
/*AutoAlign PID used in constructor for folloiwing choreo trajectories */

Choose a reason for hiding this comment

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

medium

There's a typo in this comment. "folloiwing" should be "following".

Suggested change
/*AutoAlign PID used in constructor for folloiwing choreo trajectories */
/*AutoAlign PID used in constructor for following choreo trajectories */

private final TalonFXSimState m_motorOneSimState;
private final TalonFXSimState m_motorTwoSimState;
private final StructPublisher<Pose3d> m_posePublisher;
public DoubleTopic arm_Pivot = NetworkTableInstance.getDefault().getDoubleTopic("Arm Pivot");

Choose a reason for hiding this comment

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

medium

The field name arm_Pivot does not follow standard Java naming conventions (camelCase). It should be renamed to armPivot for consistency.

Suggested change
public DoubleTopic arm_Pivot = NetworkTableInstance.getDefault().getDoubleTopic("Arm Pivot");
public DoubleTopic armPivot = NetworkTableInstance.getDefault().getDoubleTopic("Arm Pivot");

public PIDController pidX = AutoAlign.AutoAlignCommand.pidX;
public PIDController pidY = AutoAlign.AutoAlignCommand.pidX;
public PIDController pidRotate = AutoAlign.AutoAlignCommand.pidRotate;
public PIDController headingController;

Choose a reason for hiding this comment

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

medium

The headingController field is declared but never initialized or used. It should be removed to avoid dead code.

Comment on lines 70 to 71
;
;

Choose a reason for hiding this comment

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

medium

These are stray semicolons and should be removed.

import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.StructPublisher;
import edu.wpi.first.wpilibj.simulation.ElevatorSim;
import frc.robot.Robot;

Choose a reason for hiding this comment

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

medium

This import of frc.robot.Robot is unused and can be removed.

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.

4 participants