Motion Master
|
#include <soempp.h>
Public Member Functions | |
Master () | |
Default constructor for the Master class. More... | |
Master (const std::string &iface) | |
Constructs and initializes the Master with the given network interface. More... | |
void | init (const std::string &iface) |
Initializes the fieldbus using the specified network interface. More... | |
void | deinit () |
Deinitializes the fieldbus and releases associated resources. More... | |
~Master () | |
Destructor for the Master class. More... | |
Fieldbus & | getFieldbus () const |
Returns a reference to the Fieldbus instance. More... | |
std::string | getInterfaceName () const |
Retrieves the interface name used by the fieldbus. More... | |
size_t | getIoMapSize () const |
Returns the total size of the I/O map for the current group. More... | |
int | initSlaves () |
Initializes the slave devices on the EtherCAT network. More... | |
const std::vector< std::unique_ptr< soempp::Slave > > & | getSlaves () const |
Returns a reference to the list of slaves. More... | |
int | expectedWkc () const |
Calculates the expected working counter (WKC) for the current fieldbus group. More... | |
int | roundtrip () |
Performs a complete send/receive process data cycle on the fieldbus. More... | |
void | exchangeProcessDataAndUpdateParameters () |
Exchanges process data with slaves and updates parameters based on the response. More... | |
bool | start () |
Initializes and starts the fieldbus master. More... | |
|
explicit |
Default constructor for the Master class.
Does not perform any initialization. You must call initFieldbus()
before use.
|
explicit |
Constructs and initializes the Master with the given network interface.
Delegates to initFieldbus(iface)
. See initFieldbus()
for detailed initialization steps.
iface | The name of the network interface (e.g., "eth0"). |
std::runtime_error | if the fieldbus initialization fails. |
soempp::Master::~Master | ( | ) |
void soempp::Master::deinit | ( | ) |
Deinitializes the fieldbus and releases associated resources.
Calls ecx_close()
to properly close the EtherCAT context and free related system resources such as sockets and buffers.
Logs a confirmation message upon successful closure.
This method is also invoked by the destructor to ensure clean shutdown.
void soempp::Master::exchangeProcessDataAndUpdateParameters | ( | ) |
Exchanges process data with slaves and updates parameters based on the response.
This function initiates the process of exchanging data with all connected slaves. It first updates the output values for each slave using the updateOutputs
method. Then, it performs a round-trip communication and checks the Working Counter (WKC).
If the WKC is greater than or equal to the expected WKC, it updates the parameters for each slave by calling updateParametersFromInputs
. Otherwise, it logs an error indicating that the WKC is not as expected, and provides details about the slave responses and their states.
The function assumes that all slaves are properly initialized and that slavecount
is a valid value.
roundtrip()
function to perform the communication with slaves, and uses the expectedWkc()
to compare the result with the expected WKC.
|
inline |
Calculates the expected working counter (WKC) for the current fieldbus group.
Computes the expected WKC as twice the number of outputs plus the number of inputs for the selected group in the fieldbus context.
Fieldbus & soempp::Master::getFieldbus | ( | ) | const |
std::string soempp::Master::getInterfaceName | ( | ) | const |
Retrieves the interface name used by the fieldbus.
This function returns the network interface name associated with the fieldbus, which was set during initialization.
size_t soempp::Master::getIoMapSize | ( | ) | const |
Returns the total size of the I/O map for the current group.
The total size is calculated as the sum of output bytes (Obytes
) and input bytes (Ibytes
) defined in the current group of the fieldbus.
const std::vector< std::unique_ptr< soempp::Slave > > & soempp::Master::getSlaves | ( | ) | const |
Returns a reference to the list of slaves.
This function provides access to the internal vector of slave devices. The returned reference allows modification of the vector of std::unique_ptr<soempp::Slave>
elements. Ownership of the slave objects remains with the Master
object.
std::vector<std::unique_ptr<soempp::Slave>>
containing the slaves. void soempp::Master::init | ( | const std::string & | iface | ) |
Initializes the fieldbus using the specified network interface.
Sets up the EtherCAT context and underlying Ethernet interface required for communication. This includes configuring the context to prevent devices without firmware from entering the SAFE-OPERATIONAL state — a condition that would otherwise require a power cycle to recover from.
The following operations are performed:
ecx_init()
.Detailed steps performed by ecx_init()
:
ecx_context
, port
, redport
, etc.):ecx_config_init()
separately — this is handled by initSlaves()
.CAP_NET_RAW
or root).iface | The name of the Ethernet interface to initialize (e.g., "eth0"). |
std::runtime_error | if ecx_init() fails or setup cannot complete. |
int soempp::Master::initSlaves | ( | ) |
Initializes the slave devices on the EtherCAT network.
This function configures the slaves on the EtherCAT fieldbus by calling ecx_config_init()
with the provided context. It scans the network for all connected slaves, assigns logical addresses to them, and configures their parameters (such as PDO mapping, communication settings, etc.).
If ecx_config_init()
fails (e.g., no slaves detected, communication issues, or network misconfiguration), an error is logged, and a std::runtime_error
is thrown, providing the cause of the failure.
Once the slaves are successfully initialized, the method loops through each detected slave and adds it to the slaves_
vector using emplace_back
. This enables subsequent operations to be performed on each slave via the slaves_
collection, allowing communication and control after initialization.
Detailed initialization process:
ecx_config_init()
to scan and configure slaves based on the provided context:usetable
is TRUE
, using the configuration table to map I/O data.ec_slave[]
, ec_group[]
) to store slave and group information.slaves_
vector using emplace_back
, allowing for further operations.This method should typically be called after ecx_init()
to initialize the EtherCAT interface. It prepares the slaves for communication, allowing the system to begin exchanging data or transitioning to various states such as OPERATIONAL or SAFE-OPERATIONAL.
std::runtime_error | if ecx_config_init() fails (e.g., no slaves found, network issues, or timeout). |
int soempp::Master::roundtrip | ( | ) |
Performs a complete send/receive process data cycle on the fieldbus.
Sends process data and then waits to receive the corresponding process data response.
bool soempp::Master::start | ( | ) |
Initializes and starts the fieldbus master.
Maps process data I/O, configures distributed clocks, and transitions all slaves through SAFE-OPERATIONAL to OPERATIONAL state. Also sends an initial process data roundtrip to ensure proper output synchronization on the slaves.