From 724731e5363607a45b729584315b1edab73f8b66 Mon Sep 17 00:00:00 2001 From: spoopr Date: Wed, 3 Jun 2026 16:06:56 -0500 Subject: [PATCH 1/3] centralize CANIDs --- src/main/java/frc/robot/Constants.java | 63 ++++++++++--------- .../subsystems/drive/SwerveSubsystem.java | 26 ++++---- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index cbe5f99..93aa99f 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -68,6 +68,39 @@ public static final class RobotConstants { public static final Mass TOTAL_MASS = Kilogram.of(107); public static final MomentOfInertia MOMENT_OF_INERTIA = KilogramSquareMeters.of(6.883); + + + public static final class CANIDs { + public static final class Drive { + public static final int IMU = 0; + + public static final class FL { + public static final int DRIVE = 10; + public static final int STEER = 11; + public static final int ENCODER = 12; + } + + public static final class FR { + public static final int DRIVE = 7; + public static final int STEER = 8; + public static final int ENCODER = 9; + } + + public static final class BL { + public static final int DRIVE = 4; + public static final int STEER = 5; + public static final int ENCODER = 6; + } + + public static final class BR { + public static final int DRIVE = 1; + public static final int STEER = 2; + public static final int ENCODER = 3; + } + } + + public static final int PDH = 13; + } } public static final class DriveConstants { @@ -216,36 +249,6 @@ public static final class Angle { } } } - - public static class CANIDs { - public static final int IMU = 0; - - public static class Modules { - public static final class FL { - public static final int DRIVE = 10; - public static final int STEER = 11; - public static final int CANCODER = 12; - } - - public static final class FR { - public static final int DRIVE = 7; - public static final int STEER = 8; - public static final int CANCODER = 9; - } - - public static final class BL { - public static final int DRIVE = 4; - public static final int STEER = 5; - public static final int CANCODER = 6; - } - - public static final class BR { - public static final int DRIVE = 1; - public static final int STEER = 2; - public static final int CANCODER = 3; - } - } - } } public static final class LimelightConstants { diff --git a/src/main/java/frc/robot/subsystems/drive/SwerveSubsystem.java b/src/main/java/frc/robot/subsystems/drive/SwerveSubsystem.java index 5934dc0..2532b87 100644 --- a/src/main/java/frc/robot/subsystems/drive/SwerveSubsystem.java +++ b/src/main/java/frc/robot/subsystems/drive/SwerveSubsystem.java @@ -200,18 +200,18 @@ public SwerveSubsystem() { SwerveModuleConfiguration modules[] = { new SwerveModuleConfiguration( new TalonFXSwerve( - DriveConstants.CANIDs.Modules.FL.DRIVE, + RobotConstants.CANIDs.Drive.FL.DRIVE, true, DCMotor.getKrakenX60Foc(1) ), new TalonFXSwerve( - DriveConstants.CANIDs.Modules.FL.STEER, + RobotConstants.CANIDs.Drive.FL.STEER, false, DCMotor.getKrakenX44Foc(1) ), conversionFactors, new CANCoderSwerve( - DriveConstants.CANIDs.Modules.FL.CANCODER + RobotConstants.CANIDs.Drive.FL.ENCODER ), DriveConstants.Modules.Offsets.FL.ANGLE.in(Degrees), DriveConstants.Modules.Offsets.FL.X.in(Meters), @@ -227,18 +227,18 @@ public SwerveSubsystem() { ), new SwerveModuleConfiguration( new TalonFXSwerve( - DriveConstants.CANIDs.Modules.FR.DRIVE, + RobotConstants.CANIDs.Drive.FR.DRIVE, true, DCMotor.getKrakenX60Foc(1) ), new TalonFXSwerve( - DriveConstants.CANIDs.Modules.FR.STEER, + RobotConstants.CANIDs.Drive.FR.STEER, false, DCMotor.getKrakenX44Foc(1) ), conversionFactors, new CANCoderSwerve( - DriveConstants.CANIDs.Modules.FR.CANCODER + RobotConstants.CANIDs.Drive.FR.ENCODER ), DriveConstants.Modules.Offsets.FR.ANGLE.in(Degrees), DriveConstants.Modules.Offsets.FR.X.in(Meters), @@ -252,18 +252,18 @@ public SwerveSubsystem() { ), new SwerveModuleConfiguration( new TalonFXSwerve( - DriveConstants.CANIDs.Modules.BL.DRIVE, + RobotConstants.CANIDs.Drive.BL.DRIVE, true, DCMotor.getKrakenX60Foc(1) ), new TalonFXSwerve( - DriveConstants.CANIDs.Modules.BL.STEER, + RobotConstants.CANIDs.Drive.BL.STEER, false, DCMotor.getKrakenX44Foc(1) ), conversionFactors, new CANCoderSwerve( - DriveConstants.CANIDs.Modules.BL.CANCODER + RobotConstants.CANIDs.Drive.BL.ENCODER ), DriveConstants.Modules.Offsets.BL.ANGLE.in(Degrees), DriveConstants.Modules.Offsets.BL.X.in(Meters), @@ -277,18 +277,18 @@ public SwerveSubsystem() { ), new SwerveModuleConfiguration( new TalonFXSwerve( - DriveConstants.CANIDs.Modules.BR.DRIVE, + RobotConstants.CANIDs.Drive.BR.DRIVE, true, DCMotor.getKrakenX60Foc(1) ), new TalonFXSwerve( - DriveConstants.CANIDs.Modules.BR.STEER, + RobotConstants.CANIDs.Drive.BR.STEER, false, DCMotor.getKrakenX44Foc(1) ), conversionFactors, new CANCoderSwerve( - DriveConstants.CANIDs.Modules.BR.CANCODER + RobotConstants.CANIDs.Drive.BR.ENCODER ), DriveConstants.Modules.Offsets.BR.ANGLE.in(Degrees), DriveConstants.Modules.Offsets.BR.X.in(Meters), @@ -305,7 +305,7 @@ public SwerveSubsystem() { SwerveDriveConfiguration driveConfiguration = new SwerveDriveConfiguration( modules, - new Pigeon2Swerve(DriveConstants.CANIDs.IMU), + new Pigeon2Swerve(RobotConstants.CANIDs.Drive.IMU), DriveConstants.IMU.INVERTED, physicalCharacteristics ); From ccdd3a1e5e55771a61636c21a206bfac966b303a Mon Sep 17 00:00:00 2001 From: spoopr Date: Wed, 3 Jun 2026 16:22:30 -0500 Subject: [PATCH 2/3] pdh subsystem --- .../commands/util/VoltageStatusCommand.java | 20 -------- .../robot/subsystems/util/PDHSubsystem.java | 51 +++++++++++++++++++ 2 files changed, 51 insertions(+), 20 deletions(-) delete mode 100644 src/main/java/frc/robot/commands/util/VoltageStatusCommand.java create mode 100644 src/main/java/frc/robot/subsystems/util/PDHSubsystem.java diff --git a/src/main/java/frc/robot/commands/util/VoltageStatusCommand.java b/src/main/java/frc/robot/commands/util/VoltageStatusCommand.java deleted file mode 100644 index fe1c3d2..0000000 --- a/src/main/java/frc/robot/commands/util/VoltageStatusCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package frc.robot.commands.util; - -import edu.wpi.first.wpilibj.RobotController; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.Command; - -public class VoltageStatusCommand extends Command { - @Override - public void execute() { - SmartDashboard.putNumber( - "Meta/batteryVoltage", - RobotController.getBatteryVoltage() - ); - } - - @Override - public boolean isFinished() { - return false; - } -} \ No newline at end of file diff --git a/src/main/java/frc/robot/subsystems/util/PDHSubsystem.java b/src/main/java/frc/robot/subsystems/util/PDHSubsystem.java new file mode 100644 index 0000000..3c35c28 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/util/PDHSubsystem.java @@ -0,0 +1,51 @@ +package frc.robot.subsystems.util; + +import edu.wpi.first.wpilibj.PowerDistribution; +import edu.wpi.first.wpilibj.PowerDistribution.ModuleType; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +import frc.robot.Constants.RobotConstants; + +public class PDHSubsystem extends SubsystemBase { + + private static final PowerDistribution PDH = new PowerDistribution( + RobotConstants.CANIDs.PDH, + ModuleType.kRev + ); + + @Override + public void periodic() { + // wattage and joule draw is not supported on the rev pdh + SmartDashboard.putNumber( + "PDH/totalCurrentDraw", + PDH.getTotalCurrent() + ); + + // [documentation](https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/PowerDistribution.html#getAllCurrents()) + // only specifies that this works for the PDP, does not mention rev PDH + // but i don't see why not + SmartDashboard.putNumberArray( + "PDH/channelCurrents", + PDH.getAllCurrents() + ); + + SmartDashboard.putNumber( + "PDH/batteryVoltage", + PDH.getVoltage() + ); + + SmartDashboard.putBoolean( + "PDH/switchableChannelEnabled", + getSwitchableChannel() + ); + } + + public boolean getSwitchableChannel() { + return PDH.getSwitchableChannel(); + } + + public void setSwitchableChannel(boolean value) { + PDH.setSwitchableChannel(value); + } +} From b3d3983800172d8c50d5b7c4cc9f407b0963506d Mon Sep 17 00:00:00 2001 From: spoopr Date: Thu, 4 Jun 2026 14:15:06 -0500 Subject: [PATCH 3/3] add pdh subsytem to `RobotContainer.java` --- src/main/java/frc/robot/RobotContainer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 918d124..ee669be 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -47,6 +47,7 @@ import frc.robot.subsystems.drive.SwerveSubsystem; import frc.robot.util.AllianceFlipUtil; import frc.robot.util.Elastic; +import frc.robot.subsystems.util.PDHSubsystem; /** * This class is where the bulk of the robot should be declared. Since @@ -74,6 +75,9 @@ public class RobotContainer { public static final SwerveSubsystem swerveDriveSubsystem = new SwerveSubsystem(); + @Logged + public static final PDHSubsystem pdhSubsystem = new PDHSubsystem(); + @Logged public static final DriveCommand normalDrive = new DriveCommand( swerveDriveSubsystem,