The RMP Motion Controller APIs
Global Data

Learn to interact with global data in a RapidScript program.

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 a RapidScript Program Asynchronously
The code snippet below demonstrates how to run a RapidScript program asynchronously. The sequencer.Run() waits for the RapidScript program to finish execution, but sequencer.RunAsync() will return regardless of the program's execution status. In this case, the program being run does not terminate, so RunAsync() is used in order to allow the rest of the code in the sample application to execute.

// Create a sequencer using the factory
// platform = the platform the RapidSequencerSequencer runs on (RSI.RapidSequencer.Platform.INtime or RSI.RapidSequencer.Platform.Windows)
// _nodeName = the INtime node the RapidSequencer will run on
// _rmpNodeName = the INtime node the RMP runs on
// workingDir = the directory where the RapidSequencer executable is located
// port = the port the RapidSequencer listens on
// timeoutMs = the timeout in milliseconds after which Create() fails if the sequencer hasn't been created yet.
RSI.RapidSequencer.RapidSequencer sequencer = RSI.RapidSequencer.RapidSequencerFactory.Create(_platform, _nodeName, _rmpNodeName, workingDir, port, "RapidSequencer", timeoutMs);
// Start the sequencer. The sequencer must call `EngineStart()` before calling any other functions.
// rmpPath = the path to RMP.rta
string rmpPath = TestContext.CurrentContext.TestDirectory;
sequencer.EngineStart(_rmpNodeName, rmpPath);
// Compile the RapidSequencer script, giving it the path to the file and the name of the function to run
sequencer.Compile(samplesDirectory + "BasicGlobalData.sq", "main");
// Run the RapidSequencer asynchronously so we can adjust values while it's running.
string taskId = sequencer.RunAsync();
// Wait a second for it to run for a bit. This sleep is just for demonstration purposes, and may not be necessary in an actual application
Thread.Sleep(1000);


📜 RapidScript Program with Global Data
The code below is an example RapidScript program with global values.

global int32 globalInt = 2;
global double globalDouble = 0.0;
void main()
{
while (globalDouble == 0.0)
{
ControllerSampleWait(10);
}
print("global double value: " + globalDouble);
}


📜 Getting a Global Value
The example code below demonstrates how to obtain an integer value from a RapidScript program.

string globalIntName = "globalInt"; // the name of the global integer as a string.
int expectedIntValue = 2; // The value that we expect the integer to have.
// Get the value of a global integer in the RapidScript program, referring to it by name.
RSI.RapidSequencer.SequencerGlobal globalInt = sequencer.GlobalVariableGet(globalIntName);
// Make sure that the type is a 32-bit integer.
if (globalInt.Type == RSI.RapidSequencer.SequencerGlobal.DataType.Int32)
{
int intValue = globalInt.Value;
// This line does not need to be in most applications, and is just for demonstration / testing purposes.
Assert.That(intValue, Is.EqualTo(expectedIntValue));
}

The example code below demonstrates how to obtain a double value from a RapidScript program.

// Get the value of a global double in the RapidScript program, referring to it by name.
RSI.RapidSequencer.SequencerGlobal globalDouble = sequencer.GlobalVariableGet(globalDoubleName);
// Make sure that the type is a double.
if (globalDouble.Type == RSI.RapidSequencer.SequencerGlobal.DataType.Double)
{
double doubleValue = globalDouble.Value;
// This line does not need to be in most applications, and is just for demonstration / testing purposes.
Assert.That(doubleValue, Is.EqualTo(expectedDoubleValue));
}


📜 Setting a Global Value
The example code below demonstrates how to set a global double value in a RapidScript program.

// Set the value of a global double in the RapidSequencer script
string globalDoubleName = "globalDouble"; // The name of the global double as a string.
double expectedDoubleValue = globalInt.Value * 3.14159; // The value we want to set the double value to.
// The data type of the global value we're setting. If we want to set a global double, this must be SequencerGlobal.DataType.Double
RSI.RapidSequencer.SequencerGlobal.DataType dataType = RSI.RapidSequencer.SequencerGlobal.DataType.Double;
// Set the value of the global double named "globalDouble" to the desired value.
sequencer.GlobalVariableSet(globalDoubleName, dataType, expectedDoubleValue);