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... | |
Functions | |
std::map< std::string, std::string > | mapMacAddressesToInterfaces () |
Maps MAC addresses to their corresponding network interface names. More... | |
int | setPdoMappingFromUiConfig (ecx_contextt *context, uint16 slave) |
Sets PDO mapping for a specified EtherCAT slave using UI configuration. More... | |
void | checkPdoMapping (ecx_contextt *context, uint16 slave) |
Diagnoses and prints the PDO mapping for a given slave. More... | |
uint16_t | getSlaveState (ecx_contextt *context, uint16_t slave, bool forceRefresh) |
Retrieves the current state of a specific EtherCAT slave. More... | |
std::string | convertSlaveStateToString (int state) |
Converts a numeric EtherCAT state value into a human-readable string. More... | |
bool | transitionToHigherSlaveState (ecx_contextt *context, uint16_t slave, int targetState) |
Transitions a slave to a higher EtherCAT state. More... | |
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). More... | |
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. More... | |
bool | setSlaveState (ecx_contextt *context, uint16_t slave, int targetState) |
Sets the state of a specified EtherCAT slave. More... | |
common::PdoMappings | readPdoMappings (ecx_contextt *context, uint16_t slave) |
Read and parse all mapped PDO entries for a given slave. More... | |
void | logPdoMappingEntries (const std::vector< common::PdoMappingEntry > &entries) |
Logs PDO mapping entries grouped by PDO index. More... | |
void | logIoMap (uint8_t *ioMap, size_t totalBytes) |
Logs the I/O map as a formatted hexadecimal string. More... | |
void | initFieldbus (std::unique_ptr< Fieldbus > &fieldbus, const std::string &iface) |
Initializes a Fieldbus instance for EtherCAT communication. More... | |
Variables | |
std::string | uiConfigWithDefaultPdoMapping |
Default UI configuration used for PDO mapping. More... | |
void soempp::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. |
ecx_SDOread
to fetch the assignment counts and entries for both RxPDO and TxPDO. It prints out the data to the console for inspection. It assumes the slave supports PDO mappings in the specified ranges. void soempp::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 soempp::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. |
uint16_t soempp::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 soempp::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 soempp::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 soempp::logPdoMappingEntries | ( | const std::vector< common::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. |
LOG_F(INFO, ...)
for logging the details. std::map< std::string, std::string > soempp::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.
common::PdoMappings soempp::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). |
PdoMappings
structure containing the parsed Rx and Tx PDO mappings. int soempp::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). |
common::UiConfigJson
struct to be properly defined and compatible with the JSON structure in ui.config.json
.bool soempp::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 soempp::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 soempp::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). |
|
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 common::UiConfigJson
, and includes:
"rx"
(e.g., 0x1600, 0x1601, ...)"tx"
(e.g., 0x1a00, 0x1a01, ...)common::UiConfigJson
parser implementation.