11 KiB
PDO
Every EtherCAT device has a schema for its process data.
Structure
TxPdo / RxPdo
Tx stands for "Transmit" and Rx stands for "Receive". This is from the perspective of the EtherCAT device. So TxPdo is used by output devices and RxPdo is used by input devices. Some devices use both TxPdo and RxPdo.
PDO Assignment
Some devices (more complex ones) support the configuration of the schema, called PDO assignment. Devices without CoE support have a fixed PDO assignment.
The PDO Assignment is a list of PDO Objects.
There is a RxPdo Assignment and a TxPdo Assignment.
PDO Object
The PDO objects describe the encoding of the data. The content of the PDO Object are pointers to variables, but we can ignore this deeper logic since we only need the index (like 0x1A.. for inputs and 0x16.. for outputs) for the PDO assignment. Based on the selected PDO objects we cen implement bitwise encoding and decoding of the data.
There PDO object contents use variables with common variable types which are also available in Rust like u8, u16, u32, bool, f32, ect. Somtimes class-like data is represented by an u8 where it makes sense to write a wrapper enum. For example the common Limit type which encode four different states (0x00, 0x01, 0x10, 0x11) in an u8.
Sometimes its also possible to configure the integer signing type of an integer value. Here it makes sense to implement a wrapper and store the value as a raw u16 wether it unsigned or signed.
Predefined PDO Assignments
Not all PDO Objects are compatible with each other or redundant. A predefined PDO assignment is a selection of PDO objects that make sense together that can be used as a PDO assignment.
Examples
This is very abstract, so let's look at an example.
EL3001
EL3001 is a 1-channel analog input device.
Process data overview in TwinCAT
Analysis
It just uses the RxPdo assignment.
It has 2 PDO objects:
- AI Standard
- AI Compact
"AI Compact" takes up half the space (2 bytes) of "AI Standard" (4 bytes) since AI Standard contains additional information. AI Compact just provides us with the value we want.
Rust Implementation
We can define the TxPdo and RxPdo structs like this. The PDO objects always have to be inside an Option even if the device does not support custom assignments.
ethercat_hal::devices::el3001
#[derive(Debug, Clone, TxPdo)]
pub struct EL3001TxPdo {
