Package edu.wpi.first.wpilibj
Class Watchdog
- java.lang.Object
-
- edu.wpi.first.wpilibj.Watchdog
-
public class Watchdog extends Object
A class that's a wrapper around a watchdog timer.When the timer expires, a message is printed to the console and an optional user-provided callback is invoked.
The watchdog is initialized disabled, so the user needs to call enable() before use.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEpoch(String epochName)
Adds time since last epoch to the list printed by printEpochs().void
disable()
Disable the watchdog.void
enable()
Enables the watchdog timer.double
getTime()
Get the time in seconds since the watchdog was last fed.boolean
isExpired()
Returns true if the watchdog timer has expired.void
printEpochs()
Prints list of epochs added so far and their times.void
reset()
Resets the watchdog timer.
-
-
-
Constructor Detail
-
Watchdog
public Watchdog(double timeout)
Watchdog constructor.- Parameters:
timeout
- The watchdog's timeout in seconds.
-
Watchdog
public Watchdog(double timeout, Runnable callback)
Watchdog constructor.- Parameters:
timeout
- The watchdog's timeout in seconds.callback
- This function is called when the timeout expires.
-
-
Method Detail
-
getTime
public double getTime()
Get the time in seconds since the watchdog was last fed.
-
isExpired
public boolean isExpired()
Returns true if the watchdog timer has expired.
-
addEpoch
public void addEpoch(String epochName)
Adds time since last epoch to the list printed by printEpochs().Epochs are a way to partition the time elapsed so that when overruns occur, one can determine which parts of an operation consumed the most time.
- Parameters:
epochName
- The name to associate with the epoch.
-
printEpochs
public void printEpochs()
Prints list of epochs added so far and their times.
-
reset
public void reset()
Resets the watchdog timer.This also enables the timer if it was previously disabled.
-
enable
public void enable()
Enables the watchdog timer.
-
disable
public void disable()
Disable the watchdog.
-
-