Package frc.spectrumLib.util
Class CachedDouble
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.spectrumLib.util.CachedDouble
- All Implemented Interfaces:
Sendable,Subsystem,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 Summary
ConstructorsConstructorDescriptionCachedDouble(DoubleSupplier source) Creates a CachedDouble wrapping the given supplier. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the cached value of the source supplier, querying the supplier at most once per scheduler iteration.voidperiodic()Called by the scheduler each iteration to invalidate the cached value so the nextgetAsDouble()call re-queries the source.Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
CachedDouble
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 nextgetAsDouble()call re-queries the source. -
getAsDouble
public double getAsDouble()Returns the cached value of the source supplier, querying the supplier at most once per scheduler iteration.- Specified by:
getAsDoublein interfaceDoubleSupplier- Returns:
- the supplier's value for the current iteration
-