roboglia.base.BaseLoop

class BaseLoop(frequency=None, warning=0.9, throttle=0.1, review=1.0, **kwargs)[source]

Bases: roboglia.base.thread.BaseThread

This is a thread that executes in a separate thread, scheduling a certain atomic work (encapsulated in the atomic method) periodically as prescribed by the frequency parameter. The run method takes care of checking the flags for paused and stopped so there is no need to do this in the atomic method.

Parameters
  • name (str) – The name of the loop

  • frequency (float) – The loop frequency in [Hz]

  • warning (float) – Indicates a threshold in range [0..1] indicating when warnings should be logged to the logger in case the execution frequency is bellow the target. A 0.8 value indicates the real execution is less than 0.8 * target_frequency. The statistic is calculated over a period of time specified by the parameter review.

  • throttle (float) – Is a float (< 1.0) that is used by the monitoring of execution statistics to adjust the wait time in order to produce the desired processing frequency.

review: float

The time in [s] to calculate the statistics for the frequency.

Raises
  • KeyError and ValueError if provided data in the initialization

  • dictionary are incorrect or missing.

__init__(frequency=None, warning=0.9, throttle=0.1, review=1.0, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

property frequency

Loop frequency.

property period

Loop period = 1 / frequency.

property review

Indicates the amount of time in seconds before the thread will review the actual frequency against the target and take action.

property warning

Control the warning level for the warning message, the setter is smart: if the value is larger than 2 it will assume it is a percentage and divied it by 100 and ignore if the number is higher than 110. The over 100 is available for testing purposes.

run()[source]

Run method of the thread.

atomic()[source]

This method implements the periodic task that needs to be executed. It does not need to check paused or stopped as the run method does this already and the subclasses should make sure that the implementation completes quickly and does not raise any exceptions.

property name

Returns the name of the thread.

pause()

Requests the thread to pause.

property paused

Indicates the thread was paused.

resume()

Requests the thread to resume.

property running

Indicates if the thread is running.

setup()

Thread preparation before running. Subclasses should override

start(wait=True)

Starts the task in it’s own thread.

property started

Indicates if the thread was started.

stop(wait=True)

Sends the stopping signal to the thread. By default waits for the thread to finish.

property stopped

Indicates if the thread was stopped.

teardown()

Thread cleanup. Subclasses should override.