APIs, concepts, guides, and more
Run a sample app in C++

Learn how to run a sample app in C++.


Precondition
Before getting started you may want to install an IDE (Integrated Development Environment).
The RapidCode API is designed to be compatible with any development environment.

We recommend the following IDEs based on programming language:

Our guides typically assume these IDEs, but the general steps provided should be applicable to any IDE you choose.

For Older Versions of RMP
Older versions of RMP may require different steps to run a sample app. If you are using one of the following versions, then refer to the appropriate guide.

- For versions in the range v9.x.x to v10.5.2, see Run a sample app in C++ (pre v10.5.3)
- For versions in the range 8.x.x, see Run a sample app in C++ (v8.x.x)

🔹 Prerequisites

Before you can build and run these sample applications, you must have the following installed:

  • An appropriate C++ compiler (e.g., GCC, Clang, MSVC) or Visual Studio build tools with the "Desktop development with C++" workload
  • CMake (version 3.15 or higher)

Ensure that your development environment is set up according to the specifications of the RMP motion controller as defined in the Setup page of our knowledge base.

🔹 Run without Hardware

For Linux Users

You will want to copy the examples to somewhere within your home directory and give ownership to the current user to avoid permission issues. This can be accomplished by running the following commands:
sudo cp -r /rsi/examples ~/<destination folder>
sudo chown -R $(whoami):$(whoami) ~/<destination folder>

If you are on version 10.5.3, then you must also modify RapidSoftware.cmake which is located in ~/<destination folder>/C++. On line 8, replace:
set(RMP_DIRECTORY ${CMAKE_SOURCE_DIR}/../..)
with:
set(RMP_DIRECTORY /rsi)

Then you must specify which CPU core the sample apps will run on in include/SampleAppsHelper.h. In the SampleAppsConfig struct, set the CPU affinity to an isolated core. If you are unsure if you have an isolated core, then run the following command to list your isolated cpu's (if you have any):
cat /proc/cmdline | grep -o 'isolcpus=[^ ]*

  • If you don't have an isolated core, then follow the instructions given here: CPU Isolation

For All Users

The first step is to set your motion controller creation parameters in include/SampleAppsHelper.h. For most situations, the default values will be acceptable to get started, but it is recommended to read through the comments and understand what each parameter does regardless.

Then choose one of the following methods:

1. VSCode (Recommended)

Install the C/C++ Extension Pack by Microsoft. Then use the CMake Tools extension to build, debug, and run the samples.

If your system is headless, then you can connect to it remotely using the Remote - SSH extension.

2. Visual Studio

Use one of our helper scripts located in the VisualStudioGeneratorScripts directory. Run generate_build_files_<Visual Studio Version>.bat to use CMake to generate a solution file for your version of Visual Studio. Then navigate to the build/<Visual Studio Version> and open the .sln file located there.

3. Command Line

Use the CMake CLI to generate build files and build the samples. Then navigate to /bin/<Configuration> and run the executables located there.

🔹 Run with Hardware

Warning
The samples are intended to assist in the integration of the RMP motion controller with your application. They 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.

By default the sample apps will run using "Phantom Axes" without the EtherCAT network running. If you wish to run the samples using hardware then complete the following:

  1. Pick the sample app you want to run with hardware. Navigate to the source file located in the src directory. Read through the code and run it with phantoms until you have a good understanding of how it works
  2. Change any constants in the sample app to fit your hardware setup. Pay special attention to any motion constants, such as position, velocity, or acceleration. Ensure that they are safe values for your setup. Keep in mind that these values will be affected by the User Units that you set in the next step.
  3. Open include/SampleAppsHelper.h and configure the SampleAppsConfig struct to have appropriate constants for your setup. - This will include setting the User Units for your motors, which is the number of motor encoder counts per RMP unit. For instance, if your motor has 1000 encoder counts per rotation, then setting the User Units to 1000 would mean that one RMP unit is one rotation (i.e. a position of 1 is 1 rotation from the origin, a velocity of 1 is 1 rotation per second etc.). Typically, the number of encoder counts per rotation will be a power of 2 based on the encoder resolution
  4. Implement SampleAppsConfig::ConfigureHardwareAxes according to your setup
  5. Set SampleAppsConfig::USE_HARDWARE to true. Now ALL sample apps will use your hardware until you set this back to false
  6. Revisit the sample app(s) you intend to run and double check that any constants (especially motion constants) are set to safe values based on your hardware setup and the value you set for the axes User Units
  7. Build and run the sample app
  8. When you are done testing, set SampleAppsConfig::USE_HARDWARE back to false, so that you don't accidentally run the samples with hardware in the future