![]() |
APIs, concepts, guides, and more
|
Learn how to use Real-Time Tasks (RTTasks)
PREMIUM FEATURE BETA
HelloRTTasks
RTTaskFunctions
folder included with the C++ examples
To get up and running quickly, follow these steps:
RTTaskFunctionsTemplate
(found in the examples folder) into your projectsrc/rttaskglobals.h
src/rttaskfunctions.cpp
, using Increment
as a templateFor a more detailed walkthrough, continue below.
The examples
folder in your RMP installation includes a CMake project called RTTaskFunctionsTemplate
. This serves as a starting point for building a shared library containing RTTask functions. Copy this folder into your project directory and rename it appropriately.
Here is an overview of the key files:
The template project takes all the source files (.h, .cpp) in the src/
directory and compiles them into a shared library for platform (Windows/INtime or Linux). It automatically includes the RMP headers, links the RMP libraries, and applies necessary configuration for use with RTTasks.
By default, the resulting library is named RTTaskFunctions
and is output to the default RMP install directory (e.g., /rsi
or C:/RSI/X.X.X
). If these paths or names are modified, you must specify them explicitly when submitting a task. Otherwise, they will be discovered automatically.
If you want to change any of the default behavior or are interested in learning more about how it works, then look at the CMakeLists.txt
located in the root of the project folder.
In this guide, you’ll build a simple application that moves an axis based on the value of an analog input. It will use one global variable and two RTTasks. The first task, CalculateTarget
, reads the analog input and calculates a target position, storing it in the global variable targetPosition
. The second task, FollowTarget
, moves the axis to the specified target.
Open src/rttaskglobals.h
. This file is where the global variables are defined and registered.
To add a new global of type double
called targetPosition
:
RSI_GLOBAL(double, targetPosition)
to the GlobalData
structREGISTER_GLOBAL(targetPosition)
to the GlobalMetaDataMap
The result should be:
Open src/rttaskfunctions.cpp
. This is the file where the task functions are defined. A task function must follow this template:
We will add a new task function called CalculateTarget
that will read the analog input, scale it to a value between 0 and 1, and store it in the global created in the previous step.
Then we will add another task function called FollowTarget
that will move the axis towards the target position.
Once the task functions have been added, build the project to produce a new library.
In your application, after configuring your RapidCode objects, create an RTTaskManager instance and submit your tasks.
Next, run the Initialize
task one time, to get access to RapidCode objects and initialize your global variables.
Then submit the tasks created in the previous section.
While your tasks are running, you can use RTTask::StatusGet
and RTTaskManager::GlobalValueGet
to monitor your tasks.
At the end of your program, stop the tasks, manager, and axis.