Class CachedDouble

All Implemented Interfaces:
Sendable, Subsystem, DoubleSupplier

public class CachedDouble extends SubsystemBase implements DoubleSupplier
Caches a DoubleSupplier value so it is computed at most once per scheduler iteration. Note: Subsystem periodic() is typically called after triggers are polled each iteration.
  • Constructor Details

    • CachedDouble

      public CachedDouble(DoubleSupplier source)
      Creates a CachedDouble wrapping the given supplier.
      Parameters:
      source - the underlying supplier whose value is cached each scheduler iteration
  • Method Details

    • periodic

      public void periodic()
      Called by the scheduler each iteration to invalidate the cached value so the next getAsDouble() call re-queries the source.
      Specified by:
      periodic in interface Subsystem
    • getAsDouble

      public double getAsDouble()
      Returns the cached value of the source supplier, querying the supplier at most once per scheduler iteration.
      Specified by:
      getAsDouble in interface DoubleSupplier
      Returns:
      the supplier's value for the current iteration