Logic cycles

Logic Manager allows to define logic cycles. Logic cycle is a loop which run specified macro as a worker with a chosen interval.

Logic Manager can create new cycles, start, stop them and reset their stats. Cycle information is replicated to SCADA Final Aggregator nodes, however SFA can access logic cycles read-only.

Cycle control from SFA nodes (and UI) is possible only by calling pre-made LM PLC macros, which can use macro control functions to manage cycles.

Note

For the heavy industry processes we strongly recommend to use dedicated hardware production cycle controllers and control/monitor them using EVA ICS as a supervisor only.

Cycle creation

Cycles can be created with either LM API create_cycle function or with EVA shell.

To configure cycle you may specify action and interval, or you may set cycle parameters one-by-one after the cycle is created.

To specify action and interval during cycle creation, use the following format:

eva -I
lm
cycle create <cycle_id> [action] [interval <seconds>]

Example, start unit unit:lamp/lamp1 (call start macro function) with interval 0.5 seconds.

cycle create cycle1 @start('unit:lamp/lamp1') interval 0.5

Another example, run macro macro1 every 100 milliseconds:

cycle create cycle2 macro1(1, 2, x=test) interval 0.1

Note

Cycle ID must be unique within a Logic Manager.

Cycle configuration

Each lcycle object has the following parameters:

  • autostart cycle will start automatically as soon as LM PLC server is started

  • ict interval notify counter. Every ict iterations notification is being performed.

  • iterations (read-only) cycle iterations since the last start/stats reset

  • interval cycle interval, in seconds

  • macro macro, which is called as a worker

  • on_error macro, which is called if cycle error has been occurred

  • status (read-only) cycle status, changed when start/stop commands are executed. Can be:

    • 0 cycle is stopped

    • 1 cycle is running

    • 2 cycle got “stop” command and will stop as soon as current iteration finish

Note

When cycle is running, attempts to change parameters ict, interval or macro will return an error.

on_error macro

Macro, defined in on_error cycle property is called when:

  • exception worker macro raised an exception, on_error macro args contain:

    • _1 “exception” word

    • _2 exception object

  • timeout/exec error macro execution took more time than cycle loop interval is set to, or worker macro exited with non-zero code. on_error macro args contain:

    • _1 “timeout” or “exec_error” word

    • _2 serialized worker macro execution result

the macro can e.g. stop cycle execution, send critical event to controller core or just log an error and let cycle continue.

Performance

Theoretically, cycle interval can be up to 1ms (1kHz worker frequency), but don’t expect stable cycle loops on a slow/busy hardware. In real life, software controllers handle well production loops up to 200/300ms (3-5Hz), with lower values (~100ms = 10Hz) users may expect 2-3% of iteration loss. Stable logic-rich cycles with the interval, lower than 20ms (50Hz), are nearly impossible.

If worker macro perform a calls between EVA ICS nodes, don’t forget about network timeouts.

To let cycle run with a maximum precision and avoid timeout errors, it is strongly recommended for the low-interval cycles:

Cycles vs jobs

Both cycles and Scheduled jobs do similar functions: start macros with the specified interval.

When you should use cycles

  • you need to have complete control and monitoring on the interval loop

  • you need to periodically stop / start interval loop manually

  • interval is in seconds or milliseconds

usage example: automation loops.

When jobs are better

  • you need a simple instrument to run the task periodically

  • you need to start a task with the specified time schedule, e.g. every day at 9:00

  • interval is in seconds, minutes or hours, precision is not important

usage examples: statistic tasks, cleaners, system checkers.