|
Motion Master
|
Classes | |
| struct | Fieldbus |
| Structure representing the Fieldbus configuration and context for EtherCAT communication. More... | |
| class | Master |
| class | Slave |
| Represents a slave in the EtherCAT network. More... | |
| struct | SlaveInfoMailbox |
| Information about a slave's mailbox configuration. More... | |
Functions | |
| std::map< std::string, std::string > | mapMacAddressesToInterfaces () |
| Maps MAC addresses to their corresponding network interface names. | |
| SlaveInfo | getSlaveInfo (ecx_contextt *context, uint16 position) |
| void | logSlaveInfo (ecx_contextt *context, uint16 position) |
| Logs detailed information about a specific EtherCAT slave in JSON format. | |
| int | setPdoMappingFromUiConfig (ecx_contextt *context, uint16 slave) |
| Sets PDO mapping for a specified EtherCAT slave using UI configuration. | |
| void | checkPdoMapping (ecx_contextt *context, uint16 slave) |
| Diagnoses and prints the PDO mapping for a given slave. | |
| uint16_t | getSlaveState (ecx_contextt *context, uint16_t slave, bool forceRefresh) |
| Retrieves the current state of a specific EtherCAT slave. | |
| std::string | convertSlaveStateToString (int state) |
| Converts a numeric EtherCAT state value into a human-readable string. | |
| bool | transitionToHigherSlaveState (ecx_contextt *context, uint16_t slave, int targetState) |
| Transitions a slave to a higher EtherCAT state. | |
| void | updateMailboxSyncManagersOnNextState (ecx_contextt *context, uint16_t slave, int targetState) |
| Updates the mailbox and sync manager (SM) configurations for an EtherCAT slave when transitioning to specific states (e.g., BOOT or INIT). | |
| void | configureDetectedSmmModule (ecx_contextt *context, uint16_t slave) |
| Reads the detected SMM module ID from the slave device and configures the module identification object accordingly. | |
| bool | setSlaveState (ecx_contextt *context, uint16_t slave, int targetState) |
| Sets the state of a specified EtherCAT slave. | |
| mm::comm::base::PdoMappings | readPdoMappings (ecx_contextt *context, uint16_t slave) |
| Read and parse all mapped PDO entries for a given slave. | |
| void | logPdoMappingEntries (const std::vector< mm::comm::base::PdoMappingEntry > &entries) |
| Logs PDO mapping entries grouped by PDO index. | |
| void | logIoMap (uint8_t *ioMap, size_t totalBytes) |
| Logs the I/O map as a formatted hexadecimal string. | |
| void | initFieldbus (std::unique_ptr< Fieldbus > &fieldbus, const std::string &iface) |
| Initializes a Fieldbus instance for EtherCAT communication. | |
| NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (SlaveInfoMailbox, readLength, readOffset, supportedProtocols, writeLength, writeOffset) struct SlaveInfoSyncManager | |
| Information about a slave's Sync Manager (SM) configuration. | |
| NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (SlaveInfoSyncManager, flags, length, startAddress, type) struct SlaveInfoFmmu | |
| Information about a slave's Fieldbus Memory Management Unit (FMMU). | |
| NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (SlaveInfoFmmu, active, logicalEndBit, logicalStartBit, logicalStartAddress, logicalLength, physicalStartBit, physicalStartAddress, type) struct SlaveInfo | |
| General information about an EtherCAT slave device. | |
| NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (SlaveInfo, alStatusCode, aliasAddress, fmmus, mailbox, productCode, position, revisionNumber, syncManagers, name, vendorId) SlaveInfo getSlaveInfo(ecx_contextt *context | |
| Retrieves detailed information about a specific EtherCAT slave. | |
Variables | |
| std::string | uiConfigWithDefaultPdoMapping |
| Default UI configuration used for PDO mapping. | |
| uint16 | position |
| void mm::comm::soem::checkPdoMapping | ( | ecx_contextt * | context, |
| uint16 | slave ) |
Diagnoses and prints the PDO mapping for a given slave.
This function reads the number of RxPDO and TxPDO assignments from the slave, then iterates through them to read and print the mappings and their entries. It checks for RxPDOs in the range 0x1600-0x16FF and TxPDOs in the range 0x1A00-0x1AFF. For each PDO, it reads the index and subindex values and prints them along with the length (in bits) of the entry.
| context | The EtherCAT context for communication. |
| slave | The slave address to be diagnosed. |
| void mm::comm::soem::configureDetectedSmmModule | ( | ecx_contextt * | context, |
| uint16_t | slave ) |
Reads the detected SMM module ID from the slave device and configures the module identification object accordingly.
This function reads the detected module identification (object 0xF050:02) from the specified slave device using the given EtherCAT context. If a valid module ID is found (non-zero), it writes this ID back to the configured module identification object (0xF030:02) on the slave.
| [in,out] | context | Pointer to the EtherCAT master context. |
| [in] | slave | Slave device number to query. |
| std::string mm::comm::soem::convertSlaveStateToString | ( | int | state | ) |
Converts a numeric EtherCAT state value into a human-readable string.
This function maps a numeric EtherCAT state (e.g., EC_STATE_INIT, EC_STATE_OPERATIONAL) to its corresponding human-readable string representation. If the state includes the ERROR flag, the string will append " + ERROR" to the state name.
The function recognizes common EtherCAT states such as INIT, PRE-OPERATIONAL, SAFE-OPERATIONAL, and OPERATIONAL, as well as combinations with the ERROR flag. If the state is unrecognized, the function returns the string "UNRECOGNIZED".
| state | The numeric EtherCAT state value to convert. |
| SlaveInfo mm::comm::soem::getSlaveInfo | ( | ecx_contextt * | context, |
| uint16 | position ) |
| uint16_t mm::comm::soem::getSlaveState | ( | ecx_contextt * | context, |
| uint16_t | slave, | ||
| bool | forceRefresh ) |
Retrieves the current state of a specific EtherCAT slave.
This function returns the current state of a specified EtherCAT slave. If forceRefresh is true, the function explicitly reads the state from the slave device using ecx_FPRD, bypassing the cached value. The retrieved state is then stored in the master context.
The function accesses the AL status register and status code register of the slave to update the internal state tracking. This method avoids using ecx_readstate, which reads all slaves' states and may introduce delays, making this function more suitable for single-slave queries.
| context | Pointer to the EtherCAT master context. |
| slave | The slave index in the master's list, starting at 1 (0 is reserved for the master). |
| forceRefresh | If true, the state is re-read from the slave hardware. |
forceRefresh is false, the cached state is returned. | void mm::comm::soem::initFieldbus | ( | std::unique_ptr< Fieldbus > & | fieldbus, |
| const std::string & | iface ) |
Initializes a Fieldbus instance for EtherCAT communication.
This function allocates and initializes a new Fieldbus object using the specified network interface name. It sets default values and links internal pointers in the ecx_contextt structure to the corresponding members of the Fieldbus object.
| [out] | fieldbus | A reference to a unique pointer that will hold the newly created Fieldbus instance. |
| iface | The name of the network interface (e.g., "eth0") to use for EtherCAT communication. |
| void mm::comm::soem::logIoMap | ( | uint8_t * | ioMap, |
| size_t | totalBytes ) |
Logs the I/O map as a formatted hexadecimal string.
This function takes a pointer to an I/O map and its total size in bytes, then logs the contents in hexadecimal format using LOG_F. Each byte is formatted as 0xNN with uppercase hex digits and padded to two characters.
| ioMap | Pointer to the I/O map buffer. |
| totalBytes | Total number of bytes in the I/O map. |
| void mm::comm::soem::logPdoMappingEntries | ( | const std::vector< mm::comm::base::PdoMappingEntry > & | entries | ) |
Logs PDO mapping entries grouped by PDO index.
This function organizes PDO mapping entries by their PDO index and logs each group, displaying entries in the order of their appearance. Within each PDO group, the entries are displayed in the format:
| entries | A vector of PDO mapping entries to be logged, where each entry contains the PDO index, object index, subindex, and bit length. |
| void mm::comm::soem::logSlaveInfo | ( | ecx_contextt * | context, |
| uint16 | position ) |
Logs detailed information about a specific EtherCAT slave in JSON format.
This function retrieves all relevant information about a slave at the given position in the ECX context's slave list, converts it to JSON using nlohmann::json, and logs it.
| context | Pointer to an initialized ECX context (ecx_contextt*) containing the slave list. |
| position | Slave position in the context's slave list, starts from 1. |
| std::map< std::string, std::string > mm::comm::soem::mapMacAddressesToInterfaces | ( | ) |
Maps MAC addresses to their corresponding network interface names.
Scans available network adapters and constructs a map where each entry associates a MAC address (as a string) with its corresponding interface name.
This is useful for identifying interfaces by their hardware address, e.g., when selecting a specific NIC for EtherCAT communication.
| mm::comm::soem::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE | ( | SlaveInfo | , |
| alStatusCode | , | ||
| aliasAddress | , | ||
| fmmus | , | ||
| mailbox | , | ||
| productCode | , | ||
| position | , | ||
| revisionNumber | , | ||
| syncManagers | , | ||
| name | , | ||
| vendorId | ) |
Retrieves detailed information about a specific EtherCAT slave.
This function extracts all relevant data from the given EtherCAT context for the slave at the specified position in the slave list.
| context | Pointer to an initialized ECX context (ecx_contextt*) containing the slave list. |
| position | Slave position in the context's slave list, starts from 1. |
| mm::comm::soem::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE | ( | SlaveInfoFmmu | , |
| active | , | ||
| logicalEndBit | , | ||
| logicalStartBit | , | ||
| logicalStartAddress | , | ||
| logicalLength | , | ||
| physicalStartBit | , | ||
| physicalStartAddress | , | ||
| type | ) |
General information about an EtherCAT slave device.
This struct aggregates key properties and configuration of a slave, including identity, mailbox settings, FMMUs, and sync managers.
Application Layer (AL) status code.
Represents the current EtherCAT AL status of the slave (see EtherCAT standard AL Status Codes).
Alias address of the slave.
Used to differentiate between multiple slaves with the same position in the network. Default is 0x0000 if not configured.
List of Fieldbus Memory Management Units (FMMUs) for this slave.
Each FMMU maps logical process data to the slave's physical memory.
Mailbox configuration.
Defines offsets, lengths, and supported protocols for mailbox communication (e.g., CoE, FoE, EoE).
Product code of the slave.
Vendor-assigned identifier for the device type.
Retrieved from the slave's EEPROM.
Position of the slave in the EtherCAT network.
Also called the slave number; starts from 1 for the first slave.
Revision number of the slave device.
Vendor-assigned revision/version identifier.
Retrieved from the slave's EEPROM.
List of Sync Manager configurations.
Sync Managers handle cyclic process data transfer for inputs, outputs, and mailbox communication.
Name of the slave device.
Retrieved from the slave's EEPROM.
Vendor ID of the slave.
Unique identifier assigned by the EtherCAT Technology Group to the manufacturer.
Retrieved from the slave's EEPROM.
| mm::comm::soem::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE | ( | SlaveInfoMailbox | , |
| readLength | , | ||
| readOffset | , | ||
| supportedProtocols | , | ||
| writeLength | , | ||
| writeOffset | ) |
Information about a slave's Sync Manager (SM) configuration.
Sync Managers in EtherCAT control the flow of process data between the master and slave. Each SM defines a memory area for input, output, or mailbox communication.
SM flags.
Flags indicate the characteristics of the Sync Manager, such as:
Length of the Sync Manager area (in bytes).
Specifies the size of the memory block that the Sync Manager manages for process data.
Start address of the Sync Manager area in the slave memory.
Indicates where the data block starts in the slave's process data memory.
Type of the Sync Manager.
Common EtherCAT SM types:
| mm::comm::soem::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE | ( | SlaveInfoSyncManager | , |
| flags | , | ||
| length | , | ||
| startAddress | , | ||
| type | ) |
Information about a slave's Fieldbus Memory Management Unit (FMMU).
FMMUs in EtherCAT map logical process data addresses to physical memory in the slave. They allow flexible and efficient data access between master and slave.
Whether the FMMU is active.
0 = inactive, 1 = active.
Logical end bit of the FMMU mapping.
Indicates the last bit within the logical address space covered by this FMMU.
Logical start bit of the FMMU mapping.
Indicates the first bit within the logical address space covered by this FMMU.
Logical start address.
Start address in the slave's logical process data space.
Length of the logical memory area.
Specifies the number of bytes covered by this FMMU.
Physical start bit of the FMMU mapping.
Indicates the starting bit in the slave's physical memory that corresponds to logicalStartAddress.
Physical start address.
Start address in the slave's physical memory for this FMMU mapping.
FMMU type.
Usually indicates read/write direction or other attributes defined by the slave device.
| mm::comm::base::PdoMappings mm::comm::soem::readPdoMappings | ( | ecx_contextt * | context, |
| uint16_t | slave ) |
Read and parse all mapped PDO entries for a given slave.
This function reads the PDO assignments (0x1C12 and 0x1C13) and gathers all mapped objects into categorized RxPDO and TxPDO vectors.
| context | Pointer to the active EtherCAT context. |
| slave | Slave index (starting from 1). |
| int mm::comm::soem::setPdoMappingFromUiConfig | ( | ecx_contextt * | context, |
| uint16 | slave ) |
Sets PDO mapping for a specified EtherCAT slave using UI configuration.
This function attempts to read a ui.config.json file from the given EtherCAT slave using File-over-EtherCAT (FoE). If the read fails, it falls back to using a built-in default configuration.
The function then:
| context | Pointer to the EtherCAT master context (ecx_contextt). |
| slave | Index of the slave device (starting from 1). |
| bool mm::comm::soem::setSlaveState | ( | ecx_contextt * | context, |
| uint16_t | slave, | ||
| int | targetState ) |
Sets the state of a specified EtherCAT slave.
This function attempts to transition the state of a slave to the target state. If the slave is in an error state, it acknowledges and clears the error before transitioning to the target state. The function handles special cases for state transitions, including moving to the INIT or BOOT states.
| context | A pointer to the EtherCAT master context. |
| slave | The slave index in the master's list, starting at 1 (0 is reserved for the master). |
| targetState | The desired state to set for the slave. |
| bool mm::comm::soem::transitionToHigherSlaveState | ( | ecx_contextt * | context, |
| uint16_t | slave, | ||
| int | targetState ) |
Transitions a slave to a higher EtherCAT state.
This function attempts to transition an EtherCAT slave to a specified target state. If the slave is in an error state, it acknowledges the error and attempts to transition to the target state. The function performs state checks during the process and ensures that the slave transitions correctly.
| context | A pointer to the EtherCAT master context. |
| slave | The slave index in the master's list, starting at 1 (0 is reserved for the master). |
| targetState | The desired target state for the slave. |
| void mm::comm::soem::updateMailboxSyncManagersOnNextState | ( | ecx_contextt * | context, |
| uint16_t | slave, | ||
| int | targetState ) |
Updates the mailbox and sync manager (SM) configurations for an EtherCAT slave when transitioning to specific states (e.g., BOOT or INIT).
This function configures the sync managers (SM0 and SM1) for the target slave based on the target state. It handles the following scenarios:
| context | A pointer to the EtherCAT master context. |
| slave | The position of the target slave in the master's slave list. |
| target_state | The target EtherCAT state the slave is transitioning to (e.g., EC_STATE_BOOT, EC_STATE_INIT). |
| uint16 mm::comm::soem::position |
|
inline |
Default UI configuration used for PDO mapping.
This JSON string defines the default Process Data Object (PDO) mapping configuration, including Receive (Rx) and Transmit (Tx) PDOs. It is used as a fallback when reading the configuration file from an EtherCAT slave fails.
The structure follows a JSON schema compatible with mm::comm::UiConfigJson, and includes: