APIs, concepts, guides, and more
🚀 Get started

Learn RapidCode C++ with these sample applications.

RapidCode C++ Sample Apps

🔹 Introduction

Welcome to the RapidCode Sample Applications project! This collection of sample applications is designed to demonstrate the capabilities of the RapidCode API and RMP motion controller. Each sample app provides an example of how to integrate and utilize the RapidCode API within your C++ projects to control and interact with the RMP motion controller effectively.

The purpose of these sample applications is to:

  • Help new users quickly get started with the RapidCode API.
  • Provide code examples that demonstrate best practices in API usage.
  • Showcase the features and capabilities of the RMP motion controller.

🔹 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.

🔹 Understand RTTask sample outputs

Some C++ sample apps (such as HelloRTTasks and InternalAnalogFollow) make use of the accompanying RTTaskFunctions project, which is also located in the examples folder. This project builds the deterministic C++ task library that is loaded at runtime by the RTTaskManager. The sample application itself remains a standard host program (C++ in this guide, but it could just as easily be C# or Python) that uses RapidCode to connect to the manager and submit tasks from the shared library.

Review Real-Time Tasks if you need a refresher on how these pieces interact.

🔹 Run without Hardware

For Linux Users

First, you need to ensure that RMP is able to read your YubiKey for license verification. Complete the following steps:

  1. Add your user to the plugdev group

    sudo usermod -aG plugdev <your_username>
  2. Create a Udev rule for the YubiKey

    sudo nano /etc/udev/rules.d/99-plugdev-yubikey.rules

    append the following:

    SUBSYSTEM=="usb", ATTR{idVendor}=="1050", GROUP="plugdev", MODE="0660"
  3. Reload Udev rules

    sudo udevadm control --reload-rules
    sudo udevadm trigger
  4. Verify that the new rule was applied

    • Unplug and plug back in your YubiKey
    • Run lsusb. The output will be in the following form:
    Bus [bus_number] Device [device_number]: ID 1050:<product_number> Yubico.com YubiKey ...
    • Run the following command filling in the [bus_number] and [device_number] from the lsusb output:
    ls -l /dev/bus/usb/[bus_number]/[device_number]
    • Check for plugdev in the output

Then you will want to copy the examples to somewhere in your home directory.

cp -r /rsi/examples ~/[destination folder]

Then you must specify which CPU core the sample apps will run on in src/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 use

    sudo nano /etc/default/grub

    and append the following:

    GRUB_CMDLINE_LINUX="isolcpus=<cpu number> processor.max_cstate=0 intel_idle.max_cstate=0 idle=poll nohz_full=<cpu number> rcu_nocbs=<cpu number> rcu_nocb_poll nosmt"

    replacing <cpu number> with the core you want to isolate. You may need to reboot for the change to apply.

For All Users

Warning! Running sample applications may overwrite your axes configuration. If you've set up your axes in RapidSetup or RapidSetupX and want to retain that setup, use rsiconfig to save it before running any sample applications. You can find instructions to use rsiconfig in our support site under software tools.

The first step is to set your motion controller creation parameters in src/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 src/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