Use helper functions to learn about RapidCode good practices.
- Warning
- This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.
The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
In this page:
⚙️ Check Errors
Checks for errors in a RapidCodeObject and throws an exception if non-warning errors are found. This helper reads and prints all errors from the error log, ignoring warnings. Use after any RapidCode API call that might generate errors.
void CheckErrors(RapidCodeObject *rsiObject,
const std::source_location &location = std::source_location::current())
{
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());
}
}
⚙️ Network Start
Starts the network communication for a MotionController and verifies it reaches OPERATIONAL state. Prints network log messages if the network fails to start. Throws an exception if OPERATIONAL state is not reached.
{
if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateOPERATIONAL)
{
std::cout << "Starting Network.." << std::endl;
}
if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateOPERATIONAL)
{
for (int i = 0; i < messagesToRead; i++)
{
}
throw std::runtime_error("Expected OPERATIONAL state but the network did not get there.");
}
else
{
std::cout << "Network Started" << std::endl << std::endl;
}
}
⚙️ Network Shutdown
Shuts down the network communication for a MotionController. Verifies the network reaches SHUTDOWN or UNINITIALIZED state. Prints network log messages if shutdown fails.
{
if (controller->
NetworkStateGet() == RSINetworkState::RSINetworkStateUNINITIALIZED ||
{
return;
}
std::cout << "Shutting down the network.." << std::endl;
if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateUNINITIALIZED &&
{
for (int i = 0; i < messagesToRead; i++)
{
}
throw std::runtime_error("Expected SHUTDOWN state but the network did not get there.");
}
else
{
std::cout << "Network Shutdown" << std::endl << std::endl;
}
}