#ifndef HELPERS
#define HELPERS
#ifndef RMP_INSTALL_PATH
#define RMP_INSTALL_PATH ""
#endif
#include "rsi.h"
#include <iostream>
#include <string>
#include <sstream>
#include <source_location>
{
{
switch (error)
{
return "RSINetworkStartErrorNETWORK_START_OK";
return "RSINetworkStartErrorNIC_PASSED";
return "RSINetworkStartErrorDEVICES_CONNECTED_POWERED";
return "RSINetworkStartErrorDISCOVERED_ZERO_NODES";
return "RSINetworkStartErrorGENERAL_DISCOVERY_FAILURE";
return "RSINetworkStartErrorNETWORK_INIT_FAILURE";
return "RSINetworkStartErrorINCORRECT_ENI_FORMAT";
return "RSINetworkStartErrorSLAVE_COMM_FAILED";
return "RSINetworkStartErrorMEMORY_CONFIG";
return "RSINetworkStartErrorETHERCAT_MASTER_STARTUP_ERROR";
return "RSINetworkStartErrorINTERNAL_RMP_ERROR";
return "RSINetworkStartErrorINTIME_OPEN_ERROR";
return "RSINetworkStartErrorFAILED_TO_READ_PRODUCT_CODE";
return "RSINetworkStartErrorFAILED_TO_READ_VENDOR_ID";
return "RSINetworkStartErrorFAILED_TO_READ_REVISION";
return "RSINetworkStartErrorFAILED_TO_READ_SERIAL_NO";
return "RSINetworkStartErrorFAILED_TO_READ_STATION_ALIAS";
return "RSINetworkStartErrorTHREAD_SCHEDULING_OR_PRIORITY";
return "RSINetworkStartErrorETHERCAT_SAFETY_NOT_LICENSED";
return "RSINetworkStartErrorETHERCAT_SAFETY_MAIN_DEVICE_NOT_DETECTED";
return "RSINetworkStartErrorUNSUPPORTED_NODE_DETECTED";
return "RSINetworkStartErrorENI_SAMPLE_RATE_MISMATCH";
return "RSINetworkStartErrorCPU_AFFINITY";
default:
return "RSINetworkStartErrorUNKNOWN";
}
}
{
bool hasErrors = false;
std::string errorStrings("");
{
errorStrings += err->
what();
errorStrings += "\n";
{
hasErrors = true;
}
}
if (hasErrors)
{
std::ostringstream message;
message << "Error! In "
<< location.file_name() << '('
<< location.line() << ':'
<< location.column() << ") `"
<< location.function_name() << "`:\n"
<< errorStrings;
throw std::runtime_error(message.str().c_str());
}
}
{
{
std::cout << "Starting Network.." << std::endl;
controller->NetworkStart();
}
{
std::cout << "Network start error: " << NetworkStartErrorName(startError)
<< " (" << static_cast<int>(startError) << ")" << std::endl;
int messagesToRead = controller->NetworkLogMessageCountGet();
for (int i = 0; i < messagesToRead; i++)
{
std::cout << controller->NetworkLogMessageGet(i) << std::endl;
}
throw std::runtime_error("Expected OPERATIONAL state but the network did not get there.");
}
else
{
std::cout << "Network Started" << std::endl << std::endl;
}
}
{
{
return;
}
std::cout << "Shutting down the network.." << std::endl;
controller->NetworkShutdown();
{
int messagesToRead = controller->NetworkLogMessageCountGet();
for (int i = 0; i < messagesToRead; i++)
{
std::cout << controller->NetworkLogMessageGet(i) << std::endl;
}
throw std::runtime_error("Expected SHUTDOWN state but the network did not get there.");
}
else
{
std::cout << "Network Shutdown" << std::endl << std::endl;
}
}
{
std::cout << "----------------------------------------------------------------------------------------------------\n";
std::cout << "Running " << sampleAppName << " Sample App\n";
std::cout << "----------------------------------------------------------------------------------------------------\n" << std::endl;
}
void PrintFooter(std::string sampleAppName,
int exitCode)
{
std::cout << "\n----------------------------------------------------------------------------------------------------\n";
if (exitCode == 0)
{
std::cout << sampleAppName << " Sample App Completed Successfully\n";
}
else
{
std::cout << sampleAppName << " Sample App Failed with Exit Code: " << exitCode << "\n";
}
std::cout << "----------------------------------------------------------------------------------------------------\n" << std::endl;
}
}
#endif
Represents the RMP soft motion controller. This class provides an interface to general controller con...
const RsiError *const ErrorLogGet()
Get the next RsiError in the log.
int32_t ErrorLogCountGet()
Get the number of software errors in the error log.
The RapidCode base class. All non-error objects are derived from this class.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
bool isWarning
Whether the error is or is not a warning.
const char * what() const noexcept
Returns a null terminated character sequence that may be used to identify the exception.
@ RSINetworkStateSHUTDOWN
EtherCAT was shutdown or stopped, must restart.
@ RSINetworkStateOPERATIONAL
EtherCAT operational, good state.
@ RSINetworkStateUNINITIALIZED
EtherCAT not yet started.
RSINetworkStartError
Network start errors.
@ RSINetworkStartErrorNIC_PASSED
Invalid or unusable NIC/interface selection. Verify NIC name, interface state, and permissions.
@ RSINetworkStartErrorINCORRECT_ENI_FORMAT
ENI data is invalid or unreadable. Regenerate or replace the ENI file.
@ RSINetworkStartErrorETHERCAT_SAFETY_MAIN_DEVICE_NOT_DETECTED
Safety configuration was detected but no supported Safety MainDevice was found.
@ RSINetworkStartErrorMEMORY_CONFIG
Memory/configuration allocation failed during network startup. Restart and review network logs.
@ RSINetworkStartErrorENI_SAMPLE_RATE_MISMATCH
The ENI cycle time does not match the configured SampleRate. Regenerate the ENI after changing the sa...
@ RSINetworkStartErrorSLAVE_COMM_FAILED
Startup communication with one or more EtherCAT slaves failed. Verify wiring and slave health.
@ RSINetworkStartErrorFAILED_TO_READ_STATION_ALIAS
Failed to read Station Alias from a slave device. Verify slave communication stability.
@ RSINetworkStartErrorFAILED_TO_READ_PRODUCT_CODE
Failed to read Product Code from a slave device. Verify slave communication stability.
@ RSINetworkStartErrorINTIME_OPEN_ERROR
INtime open/init operation failed. Verify INtime runtime status and platform setup.
@ RSINetworkStartErrorDISCOVERED_ZERO_NODES
Discovery completed with zero nodes found. Verify topology and that slaves are powered.
@ RSINetworkStartErrorDEVICES_CONNECTED_POWERED
EtherCAT devices could not be reached. Verify cabling, power, and link status.
@ RSINetworkStartErrorCPU_AFFINITY
Linux CPU affinity is not set to a single core.
@ RSINetworkStartErrorNETWORK_INIT_FAILURE
Network startup failed after initial setup. Review network logs and configuration.
@ RSINetworkStartErrorETHERCAT_MASTER_STARTUP_ERROR
EtherCAT master failed to reach the required startup state. Check logs and network configuration.
@ RSINetworkStartErrorFAILED_TO_READ_VENDOR_ID
Failed to read Vendor ID from a slave device. Verify slave communication stability.
@ RSINetworkStartErrorFAILED_TO_READ_SERIAL_NO
Failed to read Serial Number from a slave device. Verify slave communication stability.
@ RSINetworkStartErrorNETWORK_START_OK
No startup error. Network start completed successfully.
@ RSINetworkStartErrorFAILED_TO_READ_REVISION
Failed to read Revision from a slave device. Verify slave communication stability.
@ RSINetworkStartErrorUNSUPPORTED_NODE_DETECTED
An unsupported node on the network is blocking EtherCAT startup.
@ RSINetworkStartErrorTHREAD_SCHEDULING_OR_PRIORITY
Failed to set required thread scheduling/priority. Verify RT kernel support and privileges.
@ RSINetworkStartErrorETHERCAT_SAFETY_NOT_LICENSED
Safety configuration was detected but the required safety license is not present.
@ RSINetworkStartErrorGENERAL_DISCOVERY_FAILURE
Discovery failed for an unspecified reason. Check network logs and retry discovery/start.
@ RSINetworkStartErrorINTERNAL_RMP_ERROR
Internal controller/runtime error occurred while starting the network. Restart and collect logs.
void CheckErrors(RapidCodeObject *rsiObject, const std::source_location &location=std::source_location::current())
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
void NetworkStart(MotionController *controller)
[CheckErrors]
void PrintHeader(std::string sampleAppName)
[NetworkShutdown]
void NetworkShutdown(MotionController *controller)
[NetworkStart]
void PrintFooter(std::string sampleAppName, int exitCode)
[PrintHeader]
Helpers namespace provides utility functions for common tasks in RMP applications.