Learn RapidCode C++ with these sample applications.
C++ Sample Apps
These C++ examples, located in the examples/ folder under your RMP install directory (e.g., C:/RSI/X.X.X/examples/ or /rsi/examples/), show how to control the RMP EtherCAT motion controller with the RapidCode API. Use these projects to explore API features, validate configurations, and jumpβstart your own apps.
β οΈ Important Note
These samples focus on demonstrating API usage. They may not include the complete safety logic required for your machine. When working with real hardware always wire an external emergency stop, verify limits, and start with conservative motion constants.
β
Prerequisites
- RapidCode / RMP SDK installed (includes firmware, drivers, and license tools)
- Build Tools
- Windows: Visual Studio (or the Build Tools edition) with the Desktop development with C++ workload installed
- Note: At this time, Visual Studio 2026 requires additional configuration. For this reason, we recommend Visual Studio 2022 or 2019
- Linux (Debian/Ubuntu): GCC or Clang toolchain with standard build essentials available on your distro
- CMake 3.15+
- Recommended: Visual Studio Code with C/C++ Extension Pack + CMake Tools
β¬οΈ Windows: Install Visual Studio
- Visit the Visual Studio - Older Downloads page
- Select either 2022 or 2019
- Download either a full Visual Studio installation or the Visual Studio Build Tools
β¬οΈ Linux (Debian/Ubuntu): Install GCC
Install the build-essential meta-package
sudo apt update
sudo apt install build-essential
Verify that GCC has been installed
gcc --version
g++ --version
β¬οΈ Linux (Debian/Ubuntu): Install Clang
Install Clang directly
sudo apt update
sudo apt install clang
Verify the installation
clang --version
clang++ --version
π About the RTTaskFunctions library
Samples such as HelloRTTasks and RandomWalk load the RTTaskFunctions library at runtime. The host sample (C++, C#, or Python) connects to the RTTaskManager, while deterministic motion/processing is executed inside the real-time tasks defined in examples/RTTaskFunctions/src/. See the rttasks documentation for the full architecture.
π Layout
| Path / File | Description |
| src/ | Modern CMake samples organized by topic (AxisConfiguration, Motion, etc.) |
| src/config.h | User-editable configuration (RMP path, NIC, CPU affinity, hardware flag, β¦) |
| src/helpers.h | Shared helper utilities (network start/stop, error handling, console output) |
| VisualStudioGeneratorScripts/ | Helper .bat scripts that call CMake to generate Visual Studio solutions |
βοΈ Linux setup
Allow YubiKey access (license check)
sudo usermod -aG plugdev <your_username>
sudo tee /etc/udev/rules.d/99-plugdev-yubikey.rules <<'EOF'
SUBSYSTEM=="usb", ATTR{idVendor}=="1050", GROUP="plugdev", MODE="0660"
EOF
sudo udevadm control --reload-rules
sudo udevadm trigger
Replug the key, verify with lsusb, then confirm ownership:
ls -l /dev/bus/usb/<bus>/<device>
Copy the examples
cp -r /rsi/examples ~/rapidcode-examples
Isolate a CPU core (recommended)
Add or update the GRUB entry (replace <cpu> with the chosen core):
sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX="isolcpus=<cpu> processor.max_cstate=0 intel_idle.max_cstate=0 idle=poll \
nohz_full=<cpu> rcu_nocbs=<cpu> rcu_nocb_poll nosmt"
Reboot, then set Config::CPU_AFFINITY to that core.
βοΈ Configuration
Edit src/config.h before running the samples:
| Constant | Windows | Linux | Value |
| RMP_PATH | βοΈ | βοΈ | RMP installation path. Usually /rsi (Linux) or C:\RSI\X.X.X (Windows) |
| NIC_PRIMARY | | βοΈ | The name of the primary network card (only required for physical axes) |
| NODE_NAME | βοΈ | | INtime node name (usually NodeA) |
| CPU_AFFINITY | | βοΈ | Isolated CPU core you want to use. Find it with cat /sys/devices/system/cpu/isolated |
| USE_HARDWARE | βοΈ | βοΈ | Start with false to test your sample app with phantom axes. When you're ready to use physical motors, see the "Run with Hardware" section below |
Tip: Use rsiconfig to back up your axis settings before running samples that may overwrite firmware values. Visit Software Tools > rsiconfig in our documentation to learn more.
π Build and Run the sample apps
There are 3 supported options for building and running the sample apps
- VSCode with CMake Tools (Recommended)
- Visual Studio
- CMake CLI
Each of these options is explained more in-depth in the sections below
Remember: Rebuild the sample app(s) after any changes to the source code
π οΈπ Building and Running with VS Code (Recommended)
Use C/C++ Extension Pack + CMake Tools for configure/build/debug. Remote/headless targets can be driven via Remote - SSH.
- Open VS Code to the C++ examples folder
- Click the CMake icon in the activity bar
- Open the Project Status dropdown
- Under the Folder dropdown, verify it says "C++"
- Under the Configure dropdown, choose your build kit
- Click the Select a Kit button
- Choose [Scan for kits] to detect your build kit
- Click Select a Kit again
- Choose the appropriate build kit for your system
- Windows: Select a Visual Studio kit (either 2022 or 2019) for amd64
- Linux: Select your GCC or Clang build kit
- Hover over the Configure tab and click the Configure button so CMake can generate the appropriate files
- Set your Build Target
- Under the Build dropdown, click the Set Build Target button
- Select the sample app you want to build (or the ALL_BUILD target to build all sample apps)
- Set your Launch Target
- Under the Debug or Launch dropdown, click the Set Launch/Debug Target
- Select the sample app you want to run
- Run your sample app
- To run with debugging: Click on the Debug button next to the Debug dropdown
- To run without debugging: Click on the Run in Terminal button next to the Launch dropdown
Note: You can also right-click in the Project Outline dropdown to set the build and debug/launch target
π οΈπ Building and Running with Visual Studio
- Run one of the scripts in VisualStudioGeneratorScripts/ (e.g., generate_build_files_vs2022.bat)
- Navigate to ./build/<VSVersion> (e.g., ./build/vs2022)
- Open the solution file SampleApps.sln
- Right click on your target in the Solution Explorer and click Set as Startup Project
- Click one of the green play buttons at the top of the window to build and run with or without debugging
π οΈπ Building and Running with CMake CLI
Use the CMake CLI workflow:
cmake -S . -B build
cmake --build build --config Release
./bin/Release/<sample>
β οΈ Warning
Unless you call MotionController::Shutdown(), the RMP firmware will continue your run after your sample app finishes. This can also happen if you started it through RapidSetup or RapidSetupX. If you believe this is causing issues with your execution, end the RMP firmware process before running your sample app again.
βοΈ Run with hardware
- Choose a sample in src/ and run it with phantom axes to understand its behavior.
- Adjust any motion constants (position, velocity, acceleration, jerk) to safe values.
- Update src/config.h (user units, limits, network settings) and implement Config::ConfigureHardwareAxes if you are not using rsiconfig.
Note: For more info on configuring hardware axes, see the axis-configuration.cpp sample app and our Concepts > Configuration documentation
- Enable hardware by setting Config::USE_HARDWARE = true.
- Double-check constants again (especially those expressed in user units).
- Build and run the sample while monitoring hardware and e-stop readiness.
- When finished, set Config::USE_HARDWARE = false so future runs revert to phantom axes.