Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static class DrivetrainConstants {

// Drive motor current limits (in Amps)
public static final double DRIVE_STATOR_CURRENT_LIMIT = 80;
public static final double DRIVE_SUPPLY_CURRENT_LIMIT = 45;
public static final double DRIVE_SUPPLY_CURRENT_LIMIT = 35;
public static final double DRIVE_SUPPLY_CURRENT_LIMIT_AUTO = 45;

// Steer motor current limits (in Amps)
public static final double STEER_STATOR_CURRENT_LIMIT = 60;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public void disabledPeriodic() {}
/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
public void autonomousInit() {
// Set drive motor current limit for autonomous
m_robotContainer.m_drivetrain.setAutoDriveMotorSupplyCurrentLimit();

m_autonomousCommand = m_robotContainer.getAutonomousCommand();
m_robotContainer.resetPosition();

Expand All @@ -134,6 +137,12 @@ public void autonomousInit() {
@Override
public void autonomousPeriodic() {}

@Override
public void autonomousExit() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

autonomousExit() is the only place that restores the default supply current limit; if that hook doesn’t run for any reason (unexpected restart / mode transition behavior), the higher auto limit could persist into teleop. Is there a reason you’re not also ensuring the default limit is restored on other transitions?

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

// Reset drive motor current limit to default when exiting autonomous
m_robotContainer.m_drivetrain.setDefaultDriveMotorSupplyCurrentLimit();
}

@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.ctre.phoenix6.SignalLogger;
import com.ctre.phoenix6.Utils;
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
import com.ctre.phoenix6.swerve.SwerveDrivetrainConstants;
import com.ctre.phoenix6.swerve.SwerveModuleConstants;
import com.ctre.phoenix6.swerve.SwerveRequest;
Expand Down Expand Up @@ -231,6 +232,32 @@ public CommandSwerveDrivetrain(
configureAutoBuilder();
}

/**
* Sets the supply current limit for all drive motors.
*
* @param currentLimit The supply current limit in amps
*/
private void setDriveMotorSupplyCurrentLimit(double currentLimit) {
var currentLimitsConfig = new CurrentLimitsConfigs()
.withStatorCurrentLimit(Amps.of(DrivetrainConstants.DRIVE_STATOR_CURRENT_LIMIT))
.withStatorCurrentLimitEnable(true)
.withSupplyCurrentLimit(currentLimit)
.withSupplyCurrentLimitEnable(true);

// Apply to all modules' drive motors
for (var module : getModules()) {
module.getDriveMotor().getConfigurator().apply(currentLimitsConfig);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

getConfigurator().apply(currentLimitsConfig) returns a status, but it’s ignored here; if CAN config application fails, the robot may silently keep the wrong current limit. That can make brownout/current-limit issues harder to diagnose in the pits.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

}
}

public void setAutoDriveMotorSupplyCurrentLimit() {
setDriveMotorSupplyCurrentLimit(DrivetrainConstants.DRIVE_SUPPLY_CURRENT_LIMIT_AUTO);
}

public void setDefaultDriveMotorSupplyCurrentLimit() {
setDriveMotorSupplyCurrentLimit(DrivetrainConstants.DRIVE_SUPPLY_CURRENT_LIMIT);
}

/**
* Returns a command that applies the specified control request to this swerve drivetrain.
*
Expand Down