The RMP Motion Controller APIs
MultipleTasks.sq
1//@[MultipleTasksSnippet]
2global bool runEverySample = true; // global, so we can set it true or false int RapidSetup. set to false to stop the program.
3global int32 loopCounterDelta = 0; // allows us to view how many RMP samples have elapsed since the previous loop.
4global int32 currentSampleCounter; // allows us to see the counter counting when we view globals in RapidSetup
5
6void RunEverySample()
7{
8 int32 lastSampleCounter = ControllerSampleCounterGet();
9
10 while(runEverySample)
11 {
12 currentSampleCounter = ControllerSampleCounterGet();
13 loopCounterDelta = currentSampleCounter - lastSampleCounter;
14
15 YourFastCyclicCodeGoesHere();
16
17 RMPSampleWait(1, currentSampleCounter);
18
19 lastSampleCounter = currentSampleCounter;
20 }
21 print("Done.");
22}
23
24
25global bool runEvery50Samples = true; // global, so we can set it true or false int RapidSetup. set to false to stop the program.
26global int32 loopCounterDelta50; // allows us to view how many RMP samples have elapsed since the previous loop.
27global int32 currentSampleCounter50;
28
29void RunEvery50Samples()
30{
31 int32 lastSampleCounter = ControllerSampleCounterGet();
32
33 while(runEvery50Samples)
34 {
35 currentSampleCounter50 = ControllerSampleCounterGet();
36 loopCounterDelta50 = currentSampleCounter50 - lastSampleCounter;
37
38 YourSlowCyclicCodeGoesHere();
39
40 RMPSampleWait(50, currentSampleCounter50); // wait 50 samples
41
42 lastSampleCounter = currentSampleCounter50;
43 }
44 print("Done.");
45}
46
47
48void RMPSampleWait(int32 samplesToWait, int32 startingSampleCounter)
49{
50 while(ControllerSampleCounterGet() < (startingSampleCounter + samplesToWait))
51 {
52 wait(0); // yield to other tasks
53 }
54}
55
56void YourFastCyclicCodeGoesHere()
57{
58 return;
59}
60
61void YourSlowCyclicCodeGoesHere()
62{
63 ControllerSampleWait(25); // simulate doing something that takes 25ms to execute
64}
65//@[MultipleTasksSnippet]
66
67void main(){}