APIs, concepts, guides, and more
🚀 Get started

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
    • Linux: 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

📜 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

  1. 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>
  2. Copy the examples

    cp -r /rsi/examples ~/rapidcode-examples
  3. 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:

  • Creation parameters: Set Config::RMP_PATH, NIC_PRIMARY, and NODE_NAME so the controller can start the EtherCAT network or run in phantom mode.
  • CPU affinity (Linux): Populate Config::CPU_AFFINITY with an isolated core. You can list isolated cores with:
cat /proc/cmdline | grep -o 'isolcpus=[^ ]*'
  • Hardware flag: Leave Config::USE_HARDWARE = false while testing with phantom axes. Switch to true only after the steps in “Run with hardware”.
  • User units & axis setup: Implement Config::ConfigureHardwareAxes (or use RapidSetup / rsiconfig) so every sample axis matches your mechanics.

Tip: Use rsiconfig to back up your axis settings before running samples that may overwrite firmware values.

🚀 Run the sample apps

  1. VS Code (recommended) – Use C/C++ Extension Pack + CMake Tools for configure/build/debug. Remote/headless targets can be driven via Remote - SSH.
  2. Visual Studio – Run one of the scripts in VisualStudioGeneratorScripts/ (e.g., generate_build_files_vs2022.bat) and build the generated solution in build/<VSVersion>/.
  3. Command line – Use the CMake CLI workflow:

    cmake -S . -B build
    cmake --build build --config Release
    ./build/bin/Release/<sample>

⚙️ Run with hardware

  1. Choose a sample in src/ and run it with phantom axes to understand its behavior.
  2. Adjust any motion constants (position, velocity, acceleration, jerk) to safe values.
  3. Update src/config.h (user units, limits, network settings) and implement Config::ConfigureHardwareAxes if you are not using rsiconfig.
  4. Enable hardware by setting Config::USE_HARDWARE = true.
  5. Double-check constants again (especially those expressed in user units).
  6. Build and run the sample while monitoring hardware and e-stop readiness.
  7. When finished, set Config::USE_HARDWARE = false so future runs revert to phantom axes.