#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>
{
{
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();
}
{
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.
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.