Skip to content

Brown protection go!#129

Open
Mond-Mann wants to merge 4 commits intomainfrom
brownoutprevention
Open

Brown protection go!#129
Mond-Mann wants to merge 4 commits intomainfrom
brownoutprevention

Conversation

@Mond-Mann
Copy link
Contributor

BrownProtection runs every robot loop at runtime, reading battery voltage from RobotController and total robot current from CurrentDrawLogger, smooths both with a 10-sample moving average, and converts them into normalized budgets (voltage budget and current budget). It then takes the worst of those budgets, and that becomes protectionBudget. Then it generates a difference and separates it into driveScale and mechanismScale. The drivetrain is prioritized, while aiming and extension mechanisms are slowed more aggressively.

Copy link
Collaborator

@codeNinja-1 codeNinja-1 left a comment

Choose a reason for hiding this comment

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

Also delete emsdk.

* Dynamically slows drivetrain and lower-priority mechanism motion when battery voltage drops or
* robot is drawing too high of a current.
*/
public class BrownProtection extends SubsystemBase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Call this BrownoutProtection instead of BrownProtection.

@@ -0,0 +1,106 @@
package frc.robot.power;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put this in the subsystems folder.

private final CommandSwerveDrive swerveDrive;
private final Turret turret;
private final ShooterHood shooterHood;
private final IntakeExtension intakeExtension;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We also want to be limiting the roller floor and intake roller voltage.

return baseMotionMagicAcceleration * motionProfileConstraintScale;
}

private void applyMotionMagicConfig() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't reapply configurations on the fly, because that takes a long time. Instead use DynamicMotionMagicVoltage.

* Command to drive a swerve drive to a specified state using trapezoidal motion profiling and PID
* for translation and rotation.
*/
public class DriveToStateCommand extends Command {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to slow down the robot when running DriveToStateCommand.

DogLog.log("Brownout/CurrentBudget", currentBudget);
DogLog.log("Brownout/ProtectionBudget", protectionBudget);
DogLog.log("Brownout/DriveScale", driveScale);
DogLog.log("Brownout/MechanismScale", mechanismScale);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of Brownout/, nest these under BrownoutProtection/ to match the class name.

ShooterHoodConstants.MOTOR_CONFIGURATION.MotionMagic.MotionMagicAcceleration;
private double motionProfileConstraintScale = 1.0;
private double appliedCruiseVelocity = Double.NaN;
private double appliedAcceleration = Double.NaN;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These last two don't appear to be used, so you can just remove them.

@@ -1 +1 @@
package frc.robot.subsystems.intakeextension;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comments as ShooterHood.

}

public void setMotionProfileConstraintScale(double scale) {
motionProfileConstraintScale = MathUtil.clamp(Math.round(scale * 20.0) / 20.0, 0.1, 1.0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be rounded.

* clamp target angles within a safe range. The subsystem also includes extensive logging of status
* signals and control requests for debugging and tuning purposes.
*/
public class Turret extends SubsystemBase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comments as ShooterHood.

@codeNinja-1 codeNinja-1 linked an issue Mar 19, 2026 that may be closed by this pull request
@Mond-Mann Mond-Mann requested a review from a team March 19, 2026 18:24
@Mond-Mann Mond-Mann self-assigned this Mar 19, 2026
@Mond-Mann Mond-Mann requested a review from codeNinja-1 March 19, 2026 18: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.

Prevent brownouts

2 participants