APIs, concepts, guides, and more
rttaskfunctions.cpp
1#include "rttaskglobals.h"
2
3#include <cstdlib>
4#include <ctime>
5#include <cmath>
6
7#include <iostream>
8
9using namespace RSI::RapidCode;
10using namespace RSI::RapidCode::RealTimeTasks;
11
13// initialize the global data and random number generator
14RSI_TASK(Initialize)
15{
16 data->counter = 0;
17
18 data->sensorValue = 0;
19 data->startingSample = 0;
20
21 std::srand(std::time(nullptr));
22}
24
26// increment the counter in the global data
27RSI_TASK(Increment)
28{
29 data->counter += 1;
30}
32
33// Simulate getting sensor value with sine wave
34double getSensorValue(MotionController *controller, int32_t startingSample) {
35 double FREQUENCY = 0.5; // Oscillations/second
36 double AMPLITUDE = 0.25; // Oscillation strength (user units)
37 double PI = 3.1415; // Approximation of pi
38
39 double secondsElapsed = ((double) controller->SampleCounterGet() - startingSample) / controller->SampleRateGet();
40 return AMPLITUDE * std::sin(2 * PI * FREQUENCY * secondsElapsed);
41}
42
44// move the axis to follow a simulated sensor value
45RSI_TASK(FollowSensor)
46{
47 MotionController *controller = RTMotionControllerGet();
48 if (data->startingSample == 0) {
49 data->startingSample = controller->SampleCounterGet();
50 }
51 data->sensorValue = getSensorValue(controller, data->startingSample);
52
53 RTAxisGet(0)->MoveTrapezoidal(data->sensorValue, 5, 10, 10);
54}
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