Class BatteryLogger

java.lang.Object
frc.spectrumLib.telemetry.BatteryLogger

public class BatteryLogger extends Object
Tracks and logs current draw, power, and cumulative energy consumption across subsystems each robot loop cycle.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Running total of current draw accumulated since the last logPower() call, in amps.
    double
    Cumulative energy consumed over the entire enabled session, in joules.
    double
    Total power drawn on the most recent logPower() call, in watts.
    void
    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 every SLOW_LOG_PERIOD_SECONDS.
    void
    reportCurrentUsage(String key, double... amps)
    Records the current draw for a named subsystem channel and accumulates it into the running totals.
    void
    setBatteryVoltage(double batteryVoltage)
    Battery terminal voltage used to convert current to power, in volts.
    void
    setEnabled(boolean enabled)
    When false all methods are no-ops, allowing the logger to be disabled at runtime.
    void
    setRioCurrent(double rioCurrent)
    Estimated current drawn by the RoboRIO itself, in amps.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BatteryLogger

      public BatteryLogger()
  • Method Details

    • reportCurrentUsage

      public void reportCurrentUsage(String key, double... amps)
      Records the current draw for a named subsystem channel and accumulates it into the running totals. The key may 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 every SLOW_LOG_PERIOD_SECONDS. Resets the per-loop current accumulators afterward; cumulative energy is preserved across calls.
    • setEnabled

      public void setEnabled(boolean enabled)
      When false all methods are no-ops, allowing the logger to be disabled at runtime.
    • getTotalCurrent

      public double getTotalCurrent()
      Running total of current draw accumulated since the last logPower() call, in amps.
    • getTotalPower

      public double getTotalPower()
      Total power drawn on the most recent logPower() 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.