Class CachedDouble
java.lang.Object
org.wpilib.command2.SubsystemBase
frc.spectrumLib.util.CachedDouble
- All Implemented Interfaces:
DoubleSupplier, Subsystem, org.wpilib.util.sendable.Sendable
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 SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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
-