Package com.stuypulse.stuylib.util
Class StopWatch
java.lang.Object
com.stuypulse.stuylib.util.StopWatch
This StopWatch class helps classes who want their functions to be time independent do that by
giving them an easy way to get intervals of time.
This is better than just doing it in the class because it stores the time as a long to keep accuracy, but converts it into a double for convenience.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final com.stuypulse.stuylib.util.StopWatch.TimeEngine
This engine will return the same values as whatever is selected as the default enginestatic final com.stuypulse.stuylib.util.StopWatch.TimeEngine
This engine is used to get the current time with the WPI function Timer.getFPGATimestamp()static final com.stuypulse.stuylib.util.StopWatch.TimeEngine
This engine is used to get the current time with the system function System.currentTimeMillis()static final com.stuypulse.stuylib.util.StopWatch.TimeEngine
This engine is used to get the current time with the system function System.nanoTime() -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
getTime()
Gets the time since the stop watch was resetdouble
reset()
Resets the stop watch to the current time and returns time since last reset.static void
setDefaultEngine
(com.stuypulse.stuylib.util.StopWatch.TimeEngine defaultEngine) Set the default engine for the StopWatch
-
Field Details
-
kNanoEngine
public static final com.stuypulse.stuylib.util.StopWatch.TimeEngine kNanoEngineThis engine is used to get the current time with the system function System.nanoTime() -
kMillisEngine
public static final com.stuypulse.stuylib.util.StopWatch.TimeEngine kMillisEngineThis engine is used to get the current time with the system function System.currentTimeMillis()This may have a lower resolution, but it is stable.
-
kFPGAEngine
public static final com.stuypulse.stuylib.util.StopWatch.TimeEngine kFPGAEngineThis engine is used to get the current time with the WPI function Timer.getFPGATimestamp()This is more accurate when used on a real robot.
-
kDefaultEngine
public static final com.stuypulse.stuylib.util.StopWatch.TimeEngine kDefaultEngineThis engine will return the same values as whatever is selected as the default engine
-
-
Constructor Details
-
StopWatch
public StopWatch(com.stuypulse.stuylib.util.StopWatch.TimeEngine engine) Creates timer and reset it to now.- Parameters:
engine
- the method that is used to get the current time
-
StopWatch
public StopWatch()Creates timer and reset it to now.
-
-
Method Details
-
reset
public double reset()Resets the stop watch to the current time and returns time since last reset.- Returns:
- the time since the last reset was called in seconds. The result is always a non 0 positive number.
-
getTime
public double getTime()Gets the time since the stop watch was reset- Returns:
- the time since the last reset was called in seconds. The result is always a non 0 positive number.
-
setDefaultEngine
public static void setDefaultEngine(com.stuypulse.stuylib.util.StopWatch.TimeEngine defaultEngine) Set the default engine for the StopWatchThis will be the engine used by every PID Loop and IFilter
- Parameters:
defaultEngine
- the engine that you want to be used by default
-