PDO Automation
Introduction
In situations where setting PDOs over OPC UA is unsuitable (e.g. due to latency requirements), PDO automations can be used to automate concrete processes.
PDO automations are simple command sequences that are interpreted in the cyclic process of the master and are therefore very
deterministic.
Here is a simple example:
{
"type": "PDOAutomation",
"name": "example 2",
"trigger": {
"type": "ConditionTrigger",
"condition": {
"type": "PDOValue",
"pdo": {
"type": "PDOName",
"name": "Term1.digitalInput1"
}
}
},
"commands": [
{
"type": "WaitCycle",
"cycles": 10
},
{
"type": "SetPDO",
"pdo": {
"type": "PDOName",
"name": "Term1.digitalOutput1"
},
"value": {
"type": "Literal",
"value": 1
}
}
]
}
This automation is triggered by the digital input with the name Term1.digitalInput1.
It waits exactly 10 cycles and sets the PDO with the name Term1.digitalOutput1 to the value 1.
PDO automations can be loaded at startup from a file (see Configuration) or at runtime, using the OPC UA interface.
@note You don’t need to write the json structure manually.
The python client library simplifies the definition of PDO automations greatly.
Port configuration: PDO automations share PDO access with the OPC UA server, so they can only access PDOs
that are assigned to the port ecat-internal-opcua in the Port Configuration.
Execution Behavior
PDO automations are considered active, as soon as its trigger evaluates to true, or if they are triggered via OPC UA.
As soon as a PDO automation is active, its commands are processed (in the same cycle).
Commands can block (e.g. WaitCycle).
The execution of the commands continues, as long as no command blocks.
E.g. if there are two consecutive commands which
each set a PDO, the two PDOs are guaranteed to be set in the same cycle.
If a PDO automation is done processing, its trigger is checked again in the next cycle.
Automations are not reentrant. They must be executed to the end before they can be triggered again.
Basic Building Blocks of PDO Automations
In the following, the syntax and the basic building blocks of PDO automatons are described further. The json schema for PDO automations can also be retrieved from the master via OPC UA.
Trigger
Automations can be triggered using a trigger. Currently only the Condition Trigger is implemented.
Condition Trigger
The condition trigger evaluates its expression and triggers the automation accordingly.
Commands
Commands in an automation are executed sequentially. If a command does not block, the next command is executed directly. If a command blocks, it is executed in the next cycle, provided it is runnable then.
WaitCycles
This commands blocks for N cycles.
WaitTime
This commands blocks for at least N seconds.
E.g. if the cycle time is 2 ms, a WaitTime with 0.002 s will most likely block for 2 cycles and not one.
SetPDO
SetPDO writes an Expression to a PDO. The expression is statically cast to the PDO type (e.g. assigning the value 5 to a Bit2 will result in the value 1 because the 3rd bit will be truncated). However, the general type must match. E.g. The EtherCAT type Int16 must be set by an Expression of type Integer.
The PDO is identified by a PDOIdentifier.
Expressions
Expressions are statically typed. The type check is done during startup/loading of the automation.
An expression can be evaluated to one of the following data types:
Integer (signed, 128 bit)
Float (double precision)
ByteArray
There is no “real” bool datatype.
In a boolean context, an Int128 is expected.
Zero is used for false and any Integer other than zero is used for true.
Literal
This is a fixed literal, e.g. the Integer 1 or the Float 3.33.
BinaryOperator
This expression takes a left hand side (lhs) and a right hand side (rhs) expressions and applies an operator when it is evaluated. E.g. it is possible to add two PDOs, or shift a PDO by a fixed value (literal). It is also possible to nest binary operators and do complex calculations.
As described before, expressions are type safe.
Different operators have different type requirements.
E.g. The plus operator expects either two integers, or two floats, and yields the same datatype as its operand types.
Logical operators (||, && etc.) expect integer (boolean) operands and evaluate also to integer (boolean).
Supported operators:
Plus (
+)Minus (
-)Multiply (
*)Divide (
/)Bitwise And (
&)Bitwise Or (
|)Shift left (
<<)Shift right (
>>)Greater (
>)GreaterEqual (
>=)Less (
<)LessEqual (
<=)Equal (
==)NotEqual (
!=)LogicalAnd (
&&)LogicalOr (
||)
PDOValue
This expression reads the value of a PDO when it is evaluated. It uses a PDOIdentifier to identify the PDO.
PDO Identifier
PDOs can be identified in multiple ways.
E.g. by slave index, index and subindex, by name or by id.
However, currently only PDOName is implemented.