APIs, concepts, guides, and more
rttaskfunctions.cpp
1
10#include "rttaskglobals.h"
11
12#include <cstdlib>
13#include <ctime>
14
15#include <iostream>
16
17using namespace RSI::RapidCode;
18using namespace RSI::RapidCode::RealTimeTasks;
19
21// This task initializes the global data and the random number generator
22RSI_TASK(Initialize)
23{
24 data->counter = 0;
25 data->average = 0;
26
27 std::srand(std::time(nullptr));
28}
30
32// This task increments the counter in the global data
33RSI_TASK(Increment)
34{
35 data->counter += 1;
36}
38
40// This task randomly moves the axis back and forth
41RSI_TASK(RandomWalk)
42{
43 int random = std::rand() % 2;
44 double step = random ? 0.05 : -0.025; // Randomly increment or decrement the average
45 data->average += step;
46 data->counter += 1;
47
48 RTAxisGet(0)->MoveSCurve(data->average);
49}
The RealTimeTasks namespace.