Rapid Data
Data Types
There are many different data types in RAPID. For now, we will focus on the three general data types:
- num - Numerical data, can be both integer and decimal number. E.g. 10 or 3.14159.
- string - A text string. E.g. "This is a string". Maximum of 80 characters.
- bool - A boolean (logical) variable. Can only have the values TRUE or FALSE.
All other data types are based on these three. If you understand them, how to perform operations on them and how they can be combined to more complex data types, you can easily understand all data types.
Variables
Variable Characteristics
A variable contains a data value. If the program is stopped and started the variable keeps its value, but if the program pointer is moved to main the variable data value is lost.
Declaring a variable
Declaring a variable is the way of defining a variable name and which data type it should have. A variable is declared using the keyword VAR, according to the syntax:
VAR datatypeidentifier;
VAR num length;
VAR string name;
VAR bool finished;
Persistent
What is a Persistent Variable?
A persistent variable is basically the same as an ordinary variable, but with one important difference. A persistent variable remembers the last value it was assigned, even if the program is stopped and started from the beginning again.
Declaring a variable
A persistent variable is declared using the keyword PERS. At declaration an initial value must be assigned.
PERS num nbr := 1; PERS string string1 := "Hello";
MODULE MainModule
PERS num nbr := 1;
PROC main()
nbr := 2;
ENDPROC
ENDMODULE
Constants
What is a Constant?
A constant contains a value, just like a variable, but the value is always assigned at declaration and after that the value can never be changed. The constant can be used in the program in the same way as a variable, except that it is not allowed to assign a new value to it.
Constant Declaration
The constant is declared using the keyword CONST followed by data type, identifier and assignment of a value.
CONST num gravity := 9.81; CONST string greating := "Hello";
Why use Constants?
By using a constant instead of a variable, you can be sure that the value is not changed somewhere in the program. Using a constant instead of writing the value directly in the program is better if you need to update the program with another value on the constant.
Then you only have to change in one place and can be sure you have not forgotten any occurrence of the value.
Scope of Data
The scope of data denotes the area in which the data is visible. The optional local directive of a data declaration classifies data as local (within the module), otherwise it is global. Note that the local directive may only be used at the module level, not inside a routine.
The data declaration syntax is provided here:
< data declaration="" >
::= [LOCAL] ( <variable declaration="" >
| <persistent declaration="" >
| <constant declaration="" >
)
| TASK <persistent declaration="" >
| <comment >
| <DDN >
LOCAL PERS num localvariable;
PERS num globalvariable;
Support from RobotStudio SDK
To support LOCAL data declarations, the following changes are made in the RobotStudio SDK API. Earlier version contained methods on RsTask that takes global data name as parameter. Now, with LOCAL data, it is possible to use more than one variable with the same name under the same task, and thus such methods are obsolete, but still returns the first instance found.
Obsolete functions in the RobotStudio SDK API
Boolean RsDataDeclarationCollection.Contains(string name)
Boolean RsDataDeclarationCollection.TryGetPathProcedurestring name, out RsDataDeclaration dataDeclaration)
RsPathProcedure RsDataDeclarationCollection.Item[string]
RsTarget[] RsTask.FindTargetsByWorkObject(string workObjectName)
RsTarget[] RsTask.FindTargetsByRobTarget(string robTargetName)
RsTarget[] RsTask.FindTargets(string workObjectName, string robTargetName)
RsTarget RsTask.FindFirstTargetByWorkObject(string workObjectName)
Alternate functions for the obsoleted functions
Use the following functions instead of the obsolete functions.
FindFirstTargetByWorkObject(RsWorkObject workObject)
RsDataDeclaration RsTask.FindDataDeclarationFromModuleScopes(tring name, string moduleName)
Boolean IsValidRapidNameInTaskScope(String name, string moduleName)