Class StopWatch

java.lang.Object
com.stuypulse.stuylib.util.StopWatch

public class StopWatch extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final com.stuypulse.stuylib.util.StopWatch.TimeEngine
    This engine will return the same values as whatever is selected as the default engine
    static 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

    Constructors
    Constructor
    Description
    Creates timer and reset it to now.
    StopWatch(com.stuypulse.stuylib.util.StopWatch.TimeEngine engine)
    Creates timer and reset it to now.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Gets the time since the stop watch was reset
    double
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • kNanoEngine

      public static final com.stuypulse.stuylib.util.StopWatch.TimeEngine kNanoEngine
      This engine is used to get the current time with the system function System.nanoTime()
    • kMillisEngine

      public static final com.stuypulse.stuylib.util.StopWatch.TimeEngine kMillisEngine
      This 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 kFPGAEngine
      This 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 kDefaultEngine
      This 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 StopWatch

      This will be the engine used by every PID Loop and IFilter

      Parameters:
      defaultEngine - the engine that you want to be used by default