Ark
|
Convenience class for stepping a callback at a specified rate. More...
Public Member Functions | |
None | __init__ (self, float hz, callable callback, bool oneshot=False, bool reset=True, list callback_args=[]) |
Initializes the Stepper thread. | |
None | suspend (self) |
Signal the stepper thread to stop running. | |
None | run (self) |
Runs the callback at the specified rate until the thread is shut down. | |
restart (self) | |
Restart the stepper if it was previously suspended. |
Public Attributes | |
bool | daemon = True |
Protected Attributes | |
float | _hz = hz |
float | _period_ns = 1e9 / float(hz) |
callable | _callback = callback |
bool | _oneshot = oneshot |
bool | _reset = reset |
bool | _shutdown = False |
list | _callback_args = callback_args |
Convenience class for stepping a callback at a specified rate.
This class runs a callback function at a specified rate (in Hertz) on a separate thread. The callback can be executed continuously or only once, depending on the oneshot parameter. The rate is controlled using the Rate class, which ensures the callback is called at a consistent interval.
None stepper.Stepper.__init__ | ( | self, | |
float | hz, | ||
callable | callback, | ||
bool | oneshot = False, | ||
bool | reset = True, | ||
list | callback_args = [] ) |
Initializes the Stepper thread.
hz | The rate in Hertz (loops per second) at which to call the callback. |
callback | The callback function to be called at the specified rate. |
oneshot | If True, the callback is called only once; if False, it is called continuously until shutdown is called. Defaults to False. |
reset | If True, the timer is reset if the system time moves backward. Defaults to True. |
callback_args | Arguments to pass to the callback function when called. Defaults to an empty list. |
stepper.Stepper.restart | ( | self | ) |
Restart the stepper if it was previously suspended.
None stepper.Stepper.run | ( | self | ) |
Runs the callback at the specified rate until the thread is shut down.
The Rate class is used to ensure the callback is executed at the correct intervals. If oneshot is set to True, the callback will only be executed once.
None stepper.Stepper.suspend | ( | self | ) |
Signal the stepper thread to stop running.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
bool stepper.Stepper.daemon = True |