APIs, concepts, guides, and more
starter-template.cpp
Note
See 🧩 Template 📜 for a detailed explanation of this sample code.
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.
/* This sample app demonstrates a basic template structure for building
RapidCode C++ applications.
*/
#include "helpers.h" // import our helper functions
#include "config.h" // import our configuration
#include "rsi.h" // import our RapidCode Library
using namespace RSI::RapidCode; // import the RapidCode namespace
int main()
{
// print a start message to indicate that the sample app has started
const std::string SAMPLE_APP_NAME = "📜 Template: Basic Structure";
Helpers::PrintHeader(SAMPLE_APP_NAME);
/* 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();
// print a message to indicate the sample app has finished and if it was successful or not
Helpers::PrintFooter(SAMPLE_APP_NAME, exitCode);
return exitCode;
}
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void SetupController(MotionController *controller, int numAxes=0)
Setup the controller and check if the network is in the correct state for the configuration.
Definition config.h:134
MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
Definition config.h:68
void Cleanup(MotionController *controller)
[SetupController]
Definition config.h:193
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 ...
Definition helpers.h:32
void PrintHeader(std::string sampleAppName)
[NetworkShutdown]
Definition helpers.h:146
void PrintFooter(std::string sampleAppName, int exitCode)
[PrintHeader]
Definition helpers.h:162
CreationParameters for MotionController::Create.
Definition rsi.h:866