Ark
Loading...
Searching...
No Matches
stepper.Stepper Class Reference

Convenience class for stepping a callback at a specified rate. More...

Inheritance diagram for stepper.Stepper:

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

None stepper.Stepper.__init__ ( self,
float hz,
callable callback,
bool oneshot = False,
bool reset = True,
list callback_args = [] )

Initializes the Stepper thread.

Parameters
hzThe rate in Hertz (loops per second) at which to call the callback.
callbackThe callback function to be called at the specified rate.
oneshotIf True, the callback is called only once; if False, it is called continuously until shutdown is called. Defaults to False.
resetIf True, the timer is reset if the system time moves backward. Defaults to True.
callback_argsArguments to pass to the callback function when called. Defaults to an empty list.

Member Function Documentation

◆ restart()

stepper.Stepper.restart ( self)

Restart the stepper if it was previously suspended.

◆ run()

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.

◆ suspend()

None stepper.Stepper.suspend ( self)

Signal the stepper thread to stop running.

Returns
: None

Member Data Documentation

◆ _callback

callable stepper.Stepper._callback = callback
protected

◆ _callback_args

stepper.Stepper._callback_args = callback_args
protected

◆ _hz

float stepper.Stepper._hz = hz
protected

◆ _oneshot

bool stepper.Stepper._oneshot = oneshot
protected

◆ _period_ns

float stepper.Stepper._period_ns = 1e9 / float(hz)
protected

◆ _reset

bool stepper.Stepper._reset = reset
protected

◆ _shutdown

bool stepper.Stepper._shutdown = False
protected

◆ daemon

bool stepper.Stepper.daemon = True

The documentation for this class was generated from the following file: