roboglia.base.BaseSync¶
-
class
BaseSync
(name='BASESYNC', patience=1.0, frequency=None, warning=0.9, throttle=0.1, review=1.0, group=None, registers=[], auto=True)[source]¶ Bases:
roboglia.base.thread.BaseLoop
Base processing for a sync loop.
This class is intended to be subclassed to provide specific functionality. It only parses the common elements that a sync loop would need: the devices (provided by a group) and registers (provided by a list). It will check that the provided devices are on the same bus and that the provided registers exist in all devices.
Note
Please note that this class does not actually perform any sync. Use the subclasses
BaseReadSync
orBaseWriteSync
that implement read or write syncs.BaseSync
inherits the parameters fromBaseLoop
. In addition it includes the following parameters.- Parameters
name (str) – The name of the sync
patience (float) – A duration in seconds that the main thread will wait for the background thread to finish setup activities and indicate that it is in
started
mode.frequency (float) – The sync 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.
group (set) – The set with the devices used by sync; normally the robot constructor replaces the name of the group from YAML file with the actual set built earlier in the initialization.
registers (list of str) – A list of register names (as strings) used by the sync
auto (bool) – If the sync loop should start automatically when the robot starts; defaults to
True
- Raises
KeyError – if mandatory parameters are not found:
-
__init__
(name='BASESYNC', patience=1.0, frequency=None, warning=0.9, throttle=0.1, review=1.0, group=None, registers=[], auto=True)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
auto_start
¶ Shows if the sync should be started automatically when the robot starts.
-
property
bus
¶ The bus this sync works with.
-
property
devices
¶ The devices used by the sync.
-
property
register_names
¶ The register names used by the sync.
-
process_devices
()[source]¶ Processes the provided devices.
The devices are exected as a set in the init_dict. This is normally performed by the robot class when reading the robot definition by replacing the name of the group with the actual content of the group. This method checks that all devices are assigned to the same bus otherwise raises an exception. It returns the single instance of the bus that manages all devices.
-
get_register_range
()[source]¶ Determines the start address of the range of registers and the whole length. Registers do not need to be order, but be careful that not all communication protocols can support gaps in the bulk read of registers.
- Returns
int – The start address of the range
int – The length covering all the registers (including gaps)
bool – True is the range of registers is contiguous
-
start
()[source]¶ Checks that the bus is open, then refreshes the register, sets the
sync
flag before calling the inherited :py:meth:BaseLoop.`start.
-
property
actual_frequency
¶ Returns the actual running frequency that is calculated by statistics.
-
atomic
()¶ 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
error_stat
¶ (error in %, total errors, total items).
- Type
Returns the error statistics as a tuple
-
property
errors
¶ Returns the number of errors logged by the statistics.
-
property
frequency
¶ Loop frequency.
-
inc_errors
()¶ Used by subclasses to increment the number of errors.
-
inc_processed
()¶ Used by subclasses to increment the number of processed items.
-
property
name
¶ Returns the name of the thread.
-
pause
()¶ Requests the thread to pause.
-
property
paused
¶ Indicates the thread was paused.
-
property
period
¶ Loop period = 1 / frequency.
-
property
processed
¶ Returns the number of items processed in the current statistics. The items processed depends on the loop and might be different from the number of loops executed. For example the one execution loop might include several communication packets.
-
resume
()¶ Requests the thread to resume.
-
property
review
¶ Indicates the amount of time in seconds before the thread will review the actual frequency against the target and take action.
-
run
()¶ Run method of the thread.
-
property
running
¶ Indicates if the thread is running.
-
setup
()¶ Thread preparation before running. Subclasses should override
-
property
started
¶ Indicates if the thread was started.
-
property
stopped
¶ Indicates if the thread was stopped.
-
teardown
()¶ Thread cleanup. Subclasses should override.
-
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.