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 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
    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 on the slow tier 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 java.lang.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 on the slow tier 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.