|
YARP CiA-402 EtherCAT Device 0.6.0
YARP device plugin for EtherCAT CiA-402 drives
|
Minimal EtherCAT master built on SOEM for CiA-402 devices. More...
#include <CiA402/EthercatManager.h>
Public Types | |
| enum class | Error : int { NoError = 0 , InitFailed = -1 , NoSlavesFound = -2 , ConfigFailed = -3 , SlavesNotOp = -4 , AlreadyInitialized = -5 , NotInitialized = -6 , InvalidSlaveIndex = -7 , PdoExchangeFailed = -8 } |
| Error codes returned by EthercatManager APIs. More... | |
Public Member Functions | |
| EthercatManager () | |
| Construct the manager (no I/O started). | |
| ~EthercatManager () | |
| Destructor, stops background monitoring and releases resources. | |
| EthercatManager (const EthercatManager &)=delete | |
| EthercatManager & | operator= (const EthercatManager &)=delete |
| Error | init (const std::string &ifname) noexcept |
| Initialize the EtherCAT stack and configure slaves. | |
| bool | isInitialized () const noexcept |
| Whether the manager has been successfully initialized. | |
| bool | isOperational () const noexcept |
| Whether the ring is in OPERATIONAL state. | |
| Error | sendReceive () noexcept |
| Perform one cyclic send/receive exchange over the bus. | |
| int | getWorkingCounter () const noexcept |
| Last Working Counter (WKC) observed from the previous cycle. | |
| int | getExpectedWorkingCounter () const noexcept |
| void | setPdoTimeoutUs (int usec) noexcept |
| Set receive timeout for PDO exchange (microseconds). Default is EC_TIMEOUTRET from SOEM. Larger values can help on busy systems. | |
| int | getPdoTimeoutUs () const noexcept |
| Get current receive timeout for PDO exchange (microseconds). | |
| const RxPDO * | getRxPDO (int slaveIndex) const noexcept |
| Access the RxPDO (master→slave) buffer for a given slave. | |
| RxPDO * | getRxPDO (int slaveIndex) noexcept |
| TxView | getTxView (int slaveIndex) const noexcept |
| Obtain a typed, bounds-checked view over the TxPDO (slave→master). | |
| template<typename T> | |
| Error | readSDO (int slaveIndex, uint16_t idx, uint8_t subIdx, T &out) noexcept |
| Read an SDO value from a slave (blocking call). | |
| template<typename T> | |
| Error | writeSDO (int slaveIndex, uint16_t idx, uint8_t subIdx, const T &value) noexcept |
| Write an SDO value to a slave (blocking call). | |
| std::string | getName (int slaveIndex) const noexcept |
| Get the name of a slave device. | |
| Error | enableDCSync0 (uint32_t cycleNs, int32_t shiftNs=0) noexcept |
| Enable DC Sync0 for a slave. | |
| Error | disableDCSync0 () noexcept |
| Disable DC Sync0 for a slave. | |
| void | dumpDiagnostics () noexcept |
| Print quick diagnostics about bus/slave state and WKC. Call this when a PDO exchange fails to get immediate hints. | |
| Error | goOperational () noexcept |
| Transition all slaves to OPERATIONAL and start monitoring. | |
| Error | goPreOp () noexcept |
| Transition all slaves back to PRE-OP and stop monitoring. | |
Minimal EtherCAT master built on SOEM for CiA-402 devices.
Responsibilities:
Notes:
Definition at line 163 of file EthercatManager.h.
|
strong |
Error codes returned by EthercatManager APIs.
| Enumerator | |
|---|---|
| NoError | Operation completed successfully. |
| InitFailed | Bus/stack initialization failed. |
| NoSlavesFound | No EtherCAT slaves were discovered. |
| ConfigFailed | PDO/SDO configuration failed. |
| SlavesNotOp | Slaves did not reach OP state. |
| AlreadyInitialized | init() called more than once. |
| NotInitialized | Operation requires a prior successful init(). |
| InvalidSlaveIndex | Provided slave index is out of range (1..ec_slavecount). |
| PdoExchangeFailed | Failed to exchange PDOs or read SDO. |
Definition at line 169 of file EthercatManager.h.
|
default |
Construct the manager (no I/O started).
| EthercatManager::~EthercatManager | ( | ) |
Destructor, stops background monitoring and releases resources.
Definition at line 37 of file EthercatManager.cpp.
|
delete |
|
noexcept |
Disable DC Sync0 for a slave.
Definition at line 759 of file EthercatManager.cpp.
|
noexcept |
Print quick diagnostics about bus/slave state and WKC. Call this when a PDO exchange fails to get immediate hints.
Definition at line 521 of file EthercatManager.cpp.
|
noexcept |
Enable DC Sync0 for a slave.
| cycleNs | Sync cycle time in nanoseconds. |
| shiftNs | Sync phase shift in nanoseconds. |
Definition at line 739 of file EthercatManager.cpp.
|
inlinenoexcept |
Definition at line 223 of file EthercatManager.h.
|
noexcept |
Get the name of a slave device.
| slaveIndex | 1-based slave index. |
Definition at line 725 of file EthercatManager.cpp.
|
inlinenoexcept |
Get current receive timeout for PDO exchange (microseconds).
Definition at line 240 of file EthercatManager.h.
|
noexcept |
Access the RxPDO (master→slave) buffer for a given slave.
Definition at line 549 of file EthercatManager.cpp.
|
noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 554 of file EthercatManager.cpp.
|
noexcept |
Obtain a typed, bounds-checked view over the TxPDO (slave→master).
Definition at line 559 of file EthercatManager.cpp.
|
inlinenoexcept |
Last Working Counter (WKC) observed from the previous cycle.
Definition at line 218 of file EthercatManager.h.
|
noexcept |
Transition all slaves to OPERATIONAL and start monitoring.
Call this after init() and any SDO configuration reads, right before starting the cyclic control loop. It computes WKC expectations, caches pointers if needed, and launches the background state monitor.
Definition at line 437 of file EthercatManager.cpp.
|
noexcept |
Transition all slaves back to PRE-OP and stop monitoring.
Use this to temporarily drop out of OP for tests or reconfiguration. Leaves the manager initialized (SAFE-OP/PRE-OP), but not operational.
Definition at line 479 of file EthercatManager.cpp.
|
noexcept |
Initialize the EtherCAT stack and configure slaves.
| ifname | Network interface name (e.g., "eth0"). |
Definition at line 239 of file EthercatManager.cpp.
|
inlinenoexcept |
Whether the manager has been successfully initialized.
Definition at line 198 of file EthercatManager.h.
|
inlinenoexcept |
Whether the ring is in OPERATIONAL state.
Definition at line 204 of file EthercatManager.h.
|
delete |
|
noexcept |
Read an SDO value from a slave (blocking call).
| T | Trivially copyable integral type matching the object size. |
| slaveIndex | 1-based slave index. |
| idx | Object index (e.g., 0x6041). |
| subIdx | Object subindex. |
| out | Destination variable populated on success. |
Definition at line 368 of file EthercatManager.h.
|
noexcept |
Perform one cyclic send/receive exchange over the bus.
Definition at line 379 of file EthercatManager.cpp.
|
inlinenoexcept |
Set receive timeout for PDO exchange (microseconds). Default is EC_TIMEOUTRET from SOEM. Larger values can help on busy systems.
Definition at line 232 of file EthercatManager.h.
|
noexcept |
Write an SDO value to a slave (blocking call).
| T | Trivially copyable integral type matching the object size. |
| slaveIndex | 1-based slave index. |
| idx | Object index (e.g., 0x6040). |
| subIdx | Object subindex. |
| value | Value to write. |
Definition at line 392 of file EthercatManager.h.