This namespace includes the source code of all our SampleAppsCPP helper functions.
Helper functions were created to reduce code. Please note that if you would like to use this classes on your personal project you will have to replicate this class.
- Precondition
- This sample code presumes that the user has set the tuning paramters(PID, PIV, etc.) prior to running this program so that the motor can rotate in a stable manner.
- 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.
📜 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
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
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
Configures a specified axis as a phantom axis with custom settings.
{
const double positionToleranceMax =
std::numeric_limits<double>::max() /
10.0;
);
}
📜 Setup Controller
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++)
{
}
}
}
📜 Cleanup
Cleanup the controller and restore the object counts to the original values.
📜 Setup Controller For Hardware
Sets up the controller for hardware use by resetting it and starting the network.
📜 Clear Controller Counts
Clears count settings for axes, motion, and user limits on the controller.
📜 Setup Controller For Phantoms
Sets up the controller for phantom axes, including configuring specified axes as phantom.
{
for (auto axisNum : axisNums)
{
}
}
📜 Print Header
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
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;
}