Learn how to implement and work with real-time tasks.
- 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.
In this page:
⚙️ Real-Time Tasks: Shared Global Data
This is the global data structure shared between Real-Time Tasks 📖 and the main application that is used in all the RTTasks samples.
Defined in the RTTaskFunctions library:
{
GlobalData() { std::memset(this, 0, sizeof(*this)); }
GlobalData(GlobalData&& other) { std::memcpy(this, &other, sizeof(*this)); }
RSI_GLOBAL(int64_t, counter);
RSI_GLOBAL(double, average);
};
inline constexpr GlobalMetadataMap<RSI::RapidCode::RealTimeTasks::GlobalMaxSize> GlobalMetadata(
{
REGISTER_GLOBAL(counter),
REGISTER_GLOBAL(average),
});
Source: rttaskglobals.h
📜 Real-Time Tasks: Hello RTTasks
Learn the basics of creating and running Real-Time Tasks 📖 with proper initialization and execution patterns.
std::cout << "Submitting task..." << std::endl;
RTTask task = manager->TaskSubmit(params);
std::cout << "Getting counter global tag..." << std::endl;
{
exitCode = -1;
std::cout << "Counter is not greater than 0. The task did not run correctly." << std::endl;
}
else
{
exitCode = 0;
std::cout <<
"Counter: " << counter.
Int64 << std::endl;
}
Source: hello-rttasks.cpp
Defined in the RTTaskFunctions library:
RSI_TASK(Increment)
{
data->counter += 1;
}
Source: rttaskfunctions.cpp
📜 Real-Time Tasks: Random Walk
Learn how to implement random walk motion patterns using Real-Time Tasks 📖 for continuous motion generation.
Axis *axis = controller->AxisGet(0);
std::cout << "Creating task manager..." << std::endl;
RTTaskHelper::SubmitInitializationTask(manager.value());
std::cout << "Submitting task..." << std::endl;
params.Period = 5;
RTTask task = manager->TaskSubmit(params);
std::cout << "Getting counter global tag..." << std::endl;
{
exitCode = -1;
std::cout << "Counter is not greater than 0. The task did not run correctly." << std::endl;
}
else
{
exitCode = 0;
std::cout <<
"Counter: " << counter.
Int64 << std::endl;
}
std::cout <<
"Average: " << average.
Double << std::endl;
Source: random-walk.cpp
Defined in the RTTaskFunctions library:
RSI_TASK(RandomWalk)
{
int random = std::rand() % 2;
double step = random ? 0.05 : -0.025;
data->average += step;
data->counter += 1;
RTAxisGet(0)->MoveSCurve(data->average);
}
Source: rttaskfunctions.cpp
⚙️ Real-Time Tasks: Task Manager Creation Parameters
Learn how to configure RTTaskManager's for different platforms and builds.
#if defined(WIN32) && defined(NDEBUG)
RTTaskManagerCreationParameters GetTaskManagerCreationParameters()
{
RTTaskManagerCreationParameters parameters;
std::snprintf(
RTTaskManagerCreationParameters::DirectoryLengthMaximum,
RMP_INSTALL_PATH
);
parameters.
Platform = PlatformType::INtime;
std::snprintf(
RTTaskManagerCreationParameters::NameLengthMaximum,
"NodeA"
);
return parameters;
}
#else
RTTaskManagerCreationParameters GetTaskManagerCreationParameters()
{
RTTaskManagerCreationParameters parameters;
std::snprintf(
RTTaskManagerCreationParameters::DirectoryLengthMaximum,
RMP_INSTALL_PATH
);
return parameters;
}
#endif
Source: rttasks-helpers.h
⚙️ Real-Time Tasks: Initialize RapidCode Objects
Learn how to submit an initialization task that primes RapidCode objects before real-time execution.
void SubmitInitializationTask(RTTaskManager &manager)
{
std::cout << "Running initialization task..." << std::endl;
RTTaskCreationParameters initParams("Initialize");
initParams.Repeats = RTTaskCreationParameters::RepeatNone;
constexpr int timeoutMs = 5000;
}
Source: rttasks-helpers.h
Defined in the RTTaskFunctions library:
RSI_TASK(Initialize)
{
data->counter = 0;
data->average = 0;
std::srand(std::time(nullptr));
}
Source: rttaskfunctions.cpp