Watchdog

class wpilib.Watchdog(timeout: wpimath.units.seconds, callback: collections.abc.Callable[[], None])

Bases: pybind11_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.

Watchdog constructor.

Parameters:
  • timeout – The watchdog’s timeout in seconds with microsecond resolution.

  • callback – This function is called when the timeout expires.

add_epoch(epoch_name: str) None

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:

epoch_name – The name to associate with the epoch.

disable() None

Disables the watchdog timer.

enable() None

Enables the watchdog timer.

get_time() wpimath.units.seconds

Returns the time since the watchdog was last fed.

get_timeout() wpimath.units.seconds

Returns the watchdog’s timeout.

is_expired() bool

Returns true if the watchdog timer has expired.

print_epochs() None

Prints list of epochs added so far and their times.

reset() None

Resets the watchdog timer.

This also enables the timer if it was previously disabled.

set_timeout(timeout: wpimath.units.seconds) None

Sets the watchdog’s timeout.

Parameters:

timeout – The watchdog’s timeout in seconds with microsecond resolution.

suppress_timeout_message(suppress: bool) None

Enable or disable suppression of the generic timeout message.

This may be desirable if the user-provided callback already prints a more specific message.

Parameters:

suppress – Whether to suppress generic timeout message.