APIs, concepts, guides, and more
rttaskfunctions.cpp
Note
See Real-Time Tasks 📜 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.
#include "rttaskglobals.h"
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iostream>
using namespace RSI::RapidCode;
// initialize the global data and random number generator
RSI_TASK(Initialize)
{
data->counter = 0;
data->sensorValue = 0;
data->startingSample = 0;
std::srand(std::time(nullptr));
}
// increment the counter in the global data
RSI_TASK(Increment)
{
data->counter += 1;
}
// Simulate getting sensor value with sine wave
double getSensorValue(MotionController *controller, int32_t startingSample) {
double FREQUENCY = 0.5; // Oscillations/second
double AMPLITUDE = 0.25; // Oscillation strength (user units)
double PI = 3.1415; // Approximation of pi
double secondsElapsed = ((double) controller->SampleCounterGet() - startingSample) / controller->SampleRateGet();
return AMPLITUDE * std::sin(2 * PI * FREQUENCY * secondsElapsed);
}
// move the axis to follow a simulated sensor value
RSI_TASK(FollowSensor)
{
MotionController *controller = RTMotionControllerGet();
if (data->startingSample == 0) {
data->startingSample = controller->SampleCounterGet();
}
data->sensorValue = getSensorValue(controller, data->startingSample);
RTAxisGet(0)->MoveTrapezoidal(data->sensorValue, 5, 10, 10);
}
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
The RealTimeTasks namespace.
Definition rttask.h:36