APIs, concepts, guides, and more
🧩 Template

Learn the basic structure for building RapidCode C++ applications.

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:


📜 Template: Basic Structure

Basic template structure for building RapidCode C++ applications with proper initialization, error handling, and cleanup patterns.

/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
const int NUM_AXES = 0; // the number of axes to configure, default is 0 for this template
/* RAPIDCODE INITIALIZATION */
// create the controller
// set the exit code to an error value
int exitCode = -1;
try // ensure that the controller is deleted if an error occurs
{
// prepare the controller as defined in config.h depending on the configuration
Helpers::CheckErrors(controller);
Config::SetupController(controller, NUM_AXES);
/* SET CONTROLLER OBJECT COUNTS HERE*/
// normally you would set the number of axes here, but for samples that is handled in the Config::SetupController function
// controller->AxisCountSet(NUM_AXES);
/* INSERT YOUR CONFIGURATION CODE HERE */
// axis *axis = controller->AxisGet(0);
/* INSERT YOUR APPLICATION CODE HERE */
std::cout << "Hello World!" << std::endl;
exitCode = 0; // set the exit code to success.
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
exitCode = -1;
}
// clean up the controller and any other objects as needed
Config::Cleanup(controller);
// delete the controller as the program exits to ensure memory is deallocated in the correct order
controller->Delete();

Source: starter-template.cpp