Package com.marslib.power
Class MARSPowerManager
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
com.marslib.power.MARSPowerManager
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable,edu.wpi.first.wpilibj2.command.Subsystem
public class MARSPowerManager
extends edu.wpi.first.wpilibj2.command.SubsystemBase
Subsystem responsible for monitoring the central Power Distribution Hub (PDH).
Students: This layer pulls input telemetry directly from the physical hardware (Voltage/Current) and actively manages structural alerts. Most importantly, it pushes real-time voltage down into the SwerveDrive subsystem allowing the robot to automatically execute "Load Shedding" to prevent brownouts.
-
Constructor Summary
ConstructorsConstructorDescriptionMARSPowerManager(PowerIO io, PowerConfig config) Initializes the Power Manager. -
Method Summary
Modifier and TypeMethodDescriptiondoubleHelper function for mechanisms to compute dynamically shedded voltage scaling based on the internal PowerConfig thresholds.doublecalculateVoltageScaleFactor(double nominalVoltage, double criticalVoltage) Helper function for mechanisms to compute dynamically shedded voltage scaling when battery sag impacts structural stability.doubleEvaluates the absolute bus voltage dynamically.booleanReturns true if the system voltage is currently below the critical threshold.booleanReturns true if the system voltage is currently below the warning threshold.voidperiodic()Processes IO loops periodically.Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
MARSPowerManager
Initializes the Power Manager.- Parameters:
io- The selected IO layer (Sim or Hardware PDH) pulling raw voltages.config- The power threshold configuration for the robot.
-
-
Method Details
-
periodic
public void periodic()Processes IO loops periodically. It triggers AdvantageScope "Alerts" if voltage falls below safe structural operating limits. -
getVoltage
public double getVoltage()Evaluates the absolute bus voltage dynamically.- Returns:
- The exact system voltage across the PDP/PDH. Usually ~12.5V, dropping during heavy loads.
-
isWarning
public boolean isWarning()Returns true if the system voltage is currently below the warning threshold. -
isCritical
public boolean isCritical()Returns true if the system voltage is currently below the critical threshold. -
calculateSheddingFactor
public double calculateSheddingFactor()Helper function for mechanisms to compute dynamically shedded voltage scaling based on the internal PowerConfig thresholds.- Returns:
- A multiplier [0.0 - 1.0].
-
calculateVoltageScaleFactor
public double calculateVoltageScaleFactor(double nominalVoltage, double criticalVoltage) Helper function for mechanisms to compute dynamically shedded voltage scaling when battery sag impacts structural stability.- Parameters:
nominalVoltage- The voltage at which shedding starts.criticalVoltage- The voltage at which output is zeroed.- Returns:
- A multiplier [0.0 - 1.0]. Returns 1.0 when nominal. Scales down towards 0.0 near critical voltage bounds.
-