Learn to use multiple sequencers at the same time.
- 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.
📜 Running Multiple Sequencers
The code below demonstrates how to use two sequencers to run two tasks simultaneously and poll the global variable in each RapidScript program.
string rmpPath = TestContext.CurrentContext.TestDirectory;
sequencer1.
Compile(multipleTasksSampleFile,
"RunEverySample");
sequencer2.
Compile(multipleTasksSampleFile,
"RunEvery50Samples");
string runEverySampleTaskId = sequencer1.
RunAsync();
string runEvery50SamplesTaskId = sequencer2.
RunAsync();
Thread.Sleep(1000);
for (int i = 0; i < GLOBAL_TEST_LOOPS; i++)
{
Assert.That(loopCout.Value, Is.EqualTo(1), "This must be 1 if the program is running every sample. Failed on loop " + i);
Assert.That(loopCout50.Value, Is.EqualTo(50), "This must be 50 if the program is running every 50 samples. Failed on loop " + i);
Thread.Sleep(2);
}
sequencer1.
TaskStop(runEverySampleTaskId);
sequencer2.
TaskStop(runEvery50SamplesTaskId);
📜 Multiple Tasks in RapidScript
The code below is an example RapidScript program that continuously loops while keeping track of the number of motion controller samples that have elapsed during each iteration.
global bool runEverySample = true;
global int32 loopCounterDelta = 0;
global int32 currentSampleCounter;
void RunEverySample()
{
int32 lastSampleCounter = ControllerSampleCounterGet();
while(runEverySample)
{
currentSampleCounter = ControllerSampleCounterGet();
loopCounterDelta = currentSampleCounter - lastSampleCounter;
YourFastCyclicCodeGoesHere();
RMPSampleWait(1, currentSampleCounter);
lastSampleCounter = currentSampleCounter;
}
print("Done.");
}
global bool runEvery50Samples = true;
global int32 loopCounterDelta50;
global int32 currentSampleCounter50;
void RunEvery50Samples()
{
int32 lastSampleCounter = ControllerSampleCounterGet();
while(runEvery50Samples)
{
currentSampleCounter50 = ControllerSampleCounterGet();
loopCounterDelta50 = currentSampleCounter50 - lastSampleCounter;
YourSlowCyclicCodeGoesHere();
RMPSampleWait(50, currentSampleCounter50);
lastSampleCounter = currentSampleCounter50;
}
print("Done.");
}
void RMPSampleWait(int32 samplesToWait, int32 startingSampleCounter)
{
while(ControllerSampleCounterGet() < (startingSampleCounter + samplesToWait))
{
wait(0);
}
}
void YourFastCyclicCodeGoesHere()
{
return;
}
void YourSlowCyclicCodeGoesHere()
{
ControllerSampleWait(25);
}