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 at
SLOW_LOG_PERIOD_SECONDS. This class produced the most log records on the robot, and the
loop period grows almost linearly with log volume. In the 2026-09-05 18:38 log it accounted for
32.3 of the 94 records written per loop, a third of everything, while the loop ran at 33 Hz with
a median period of 27.4 ms. 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 every loop 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 every loop 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.
-