Class BatteryLogger
Key derivation (splitting a channel name into its parent keys) and log-key construction are cached per channel name, so steady-state operation performs no string splitting or concatenation. The set of channel names is small and fixed after the first loop.
Current is published at 10 Hz (Telemetry.slowLogThisLoop()) and power and energy every
SLOW_LOG_PERIOD_SECONDS, because this class was the largest single producer of records
on the robot and the loop period tracks that volume closely. In the 2026-09-05 18:38 log it wrote
32.3 of 94 records per loop, a third of everything. Current is the channel worth watching live;
power is current times pack voltage and energy is its integral, so neither needs 50 Hz to stay
useful.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleRunning total of current draw accumulated since the lastlogPower()call, in amps.doubleCumulative energy consumed over the entire enabled session, in joules.doubleTotal power drawn on the most recentlogPower()call, in watts.voidlogPower()Appends control-overhead current consumers (roboRIO, CANcoders, Pigeon, CANivore, radio), integrates energy over the elapsed loop, then logs current on the slow tier and power and energy everySLOW_LOG_PERIOD_SECONDS.voidreportCurrentUsage(String key, double... amps) Records the current draw for a named subsystem channel and accumulates it into the running totals.voidsetBatteryVoltage(double batteryVoltage) Battery terminal voltage used to convert current to power, in volts.voidsetEnabled(boolean enabled) Whenfalseall methods are no-ops, allowing the logger to be disabled at runtime.voidsetRioCurrent(double rioCurrent) Estimated current drawn by the RoboRIO itself, in amps.
-
Constructor Details
-
BatteryLogger
public BatteryLogger()
-
-
Method Details
-
reportCurrentUsage
Records the current draw for a named subsystem channel and accumulates it into the running totals. Thekeymay use "/" or "-" as separators; parent keys are automatically aggregated.Power and energy are computed from these currents in
logPower(), which knows this loop's pack voltage and its true elapsed time.- Parameters:
key- Hierarchical name for the current consumer (e.g."Drive/FrontLeft")amps- One or more current readings in amps; absolute values are summed
-
logPower
public void logPower()Appends control-overhead current consumers (roboRIO, CANcoders, Pigeon, CANivore, radio), integrates energy over the elapsed loop, then logs current on the slow tier and power and energy everySLOW_LOG_PERIOD_SECONDS. Resets the per-loop current accumulators afterward; cumulative energy is preserved across calls. -
setEnabled
public void setEnabled(boolean enabled) Whenfalseall methods are no-ops, allowing the logger to be disabled at runtime. -
getTotalCurrent
public double getTotalCurrent()Running total of current draw accumulated since the lastlogPower()call, in amps. -
getTotalPower
public double getTotalPower()Total power drawn on the most recentlogPower()call, in watts. -
getTotalEnergy
public double getTotalEnergy()Cumulative energy consumed over the entire enabled session, in joules. -
setBatteryVoltage
public void setBatteryVoltage(double batteryVoltage) Battery terminal voltage used to convert current to power, in volts. -
setRioCurrent
public void setRioCurrent(double rioCurrent) Estimated current drawn by the RoboRIO itself, in amps.
-