C++
Sample Apps Config:
This struct provides static methods and constants for user configuration in RMP applications. Everything in this struct is expected to be modifed by the user.
{
{
std::ostringstream message;
message << "You must implement the " << __func__ << " function (found in " << __FILE__ << " line " << __LINE__ << ") to use hardware.";
throw std::runtime_error(message.str().c_str());
}
};
Get Creation Parameters:
Returns a MotionController::CreationParameters object with user-defined parameters.
#if _WIN32
{
return params;
}
#elif __linux__
{
return params;
}
#endif
Check Errors:
Check the RSIError log for any logged errors. Read and print all the errors. Ignore warnings.
{
bool hasErrors = false;
std::string errorStrings("");
{
errorStrings += err->
what();
errorStrings += "\n";
{
hasErrors = true;
}
}
if (hasErrors)
{
throw std::runtime_error(errorStrings.c_str());
}
}
Start-The-Network-cpp:
Start the network and print any errors encountered.
{
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;
}
}
Shutdown-The-Network-cpp:
Shutdown the network and print any errors encountered.
{
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;
}
}
Configure-Phantom-Axis-cpp:
Configures a specified axis as a phantom axis with custom settings.
{
const double positionToleranceMax =
std::numeric_limits<double>::max() /
10.0;
);
}
Setup-Controller-cpp:
Setup the controller with user defined axis counts and configuration.
{
{
}
else if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateUNINITIALIZED &&
{
std::ostringstream message;
message << "The Sample Apps are configured to use Phantom Axes, but the network is not in the UNINITIALIZED or SHUTDOWN state.\n"
<< "If you intended to run with hardware, then follow the steps in README.md and /include/SampleAppsHelper.h\n"
<< "Otherwise, shutdown the network before running the sample apps with phantom axes.";
throw std::runtime_error(message.str().c_str());
}
{
if (axisCount < numAxes)
{
std::ostringstream message;
message << "Error! Not enough axes configured. Expected " << numAxes << " axes but only found " << axisCount << " axes."
<< "Please configure the axes in the SampleAppsConfig::ConfigureHardwareAxes function.";
throw std::runtime_error(message.str().c_str());
}
}
else
{
{
}
for (int i = 0; i < numAxes; i++)
{
}
}
}
Setup-Controller-For-Hardware-cpp:
Sets up the controller for hardware use by resetting it and starting the network.
Clear-Controller-Counts-cpp:
Clears count settings for axes, motion, and user limits on the controller.
Setup-Controller-For-Phantoms-cpp:
Sets up the controller for phantom axes, including configuring specified axes as phantom.
{
for (auto axisNum : axisNums)
{
}
}
Print-Header-cpp:
Print a start message to indicate that the sample app has started.
{
std::cout << "----------------------------------------------------------------------------------------------------\n";
std::cout << "Running " << sampleAppName << " Sample App\n";
std::cout << "----------------------------------------------------------------------------------------------------\n" << std::endl;
}
Print-Footer-cpp:
Print a message to indicate the sample app has finished and if it was successful or not.
static 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;
}