Vous êtes sur la page 1sur 234

RAPID Developer’s Manual

CONTENTS
Page

1 Introduction ..................................................................................................................... 15
1.1 Design Objectives................................................................................................... 15
1.2 Language Summary................................................................................................ 15
1.3 Syntax Notation ...................................................................................................... 19
1.4 Error Classification................................................................................................. 20
2 Lexical Elements.............................................................................................................. 21
2.1 Character Set........................................................................................................... 21
2.2 Lexical Units........................................................................................................... 21
2.3 Identifiers................................................................................................................ 22
2.4 Reserved Words ...................................................................................................... 22
2.5 Num Literals ........................................................................................................... 23
2.6 Bool Literals ........................................................................................................... 23
2.7 String Literals ......................................................................................................... 23
2.8 Delimiters ............................................................................................................... 23
2.9 Placeholders............................................................................................................ 24
2.10 Comments............................................................................................................. 24
2.11 Data Types ............................................................................................................ 25
2.12 Scope Rules .......................................................................................................... 26
2.13 Atomic Types........................................................................................................ 26
2.14 Record Types ........................................................................................................ 27
2.15 Alias Types ........................................................................................................... 29
2.16 Data Type Value Classes....................................................................................... 30
2.17 Equal Types .......................................................................................................... 33
2.18 Data Declarations ................................................................................................. 33
2.19 Predefined Data Objects ....................................................................................... 34
2.20 Scope Rules .......................................................................................................... 34
2.21 Storage Class ........................................................................................................ 35
2.22 Variable Declarations............................................................................................ 35
2.23 Persistent Declarations ......................................................................................... 36
2.24 Constant Declarations........................................................................................... 37
3 Expressions ...................................................................................................................... 39
3.1 Constant Expressions.............................................................................................. 40
3.2 Literal Expressions ................................................................................................. 40
3.3 Conditional Expressions ......................................................................................... 40
3.4 Literals .................................................................................................................... 41

RAPID Developer’s Manual 1


RAPID Developer’s Manual

3.5 Variables ................................................................................................................. 41


3.6 Persistents ............................................................................................................... 42
3.7 Constants ................................................................................................................ 43
3.8 Parameters .............................................................................................................. 43
3.9 Aggregates.............................................................................................................. 43
3.10 Function calls ....................................................................................................... 44
3.11 Operators .............................................................................................................. 46
4 Statements........................................................................................................................ 49
4.1 Statement Termination............................................................................................ 49
4.2 Statement Lists ....................................................................................................... 50
4.3 Label Statement ...................................................................................................... 50
4.4 Assignment Statement ............................................................................................ 51
4.5 Procedure Call ........................................................................................................ 51
4.6 Goto Statement ....................................................................................................... 53
4.7 Return Statement .................................................................................................... 53
4.8 Raise Statement ...................................................................................................... 54
4.9 Exit Statement ........................................................................................................ 54
4.10 Retry Statement .................................................................................................... 55
4.11 Trynext Statement................................................................................................. 55
4.12 Connect Statement................................................................................................ 56
4.13 If Statement .......................................................................................................... 56
4.14 Compact If Statement ........................................................................................... 57
4.15 For Statement ....................................................................................................... 57
4.16 While Statement ................................................................................................... 58
4.17 Test Statement ...................................................................................................... 58
5 Routine Declarations ...................................................................................................... 59
5.1 Parameter Declarations........................................................................................... 59
5.2 Scope Rules ............................................................................................................ 62
5.3 Procedure Declarations........................................................................................... 62
5.4 Function Declarations............................................................................................. 63
5.5 Trap Declarations ................................................................................................... 64
6 Backward Execution ....................................................................................................... 65
6.1 Backward Handlers ................................................................................................ 65
7 Error Recovery................................................................................................................ 67
7.1 Error Handlers ........................................................................................................ 67
8 Interrupts......................................................................................................................... 69
8.1 Interrupt Recognition and Response ...................................................................... 69
8.2 Interrupt Manipulation ........................................................................................... 69

2 RAPID Developer’s Manual


RAPID Developer’s Manual

8.3 Trap Routines.......................................................................................................... 70


9 Task Modules ................................................................................................................... 73
9.1 Module Declarations............................................................................................... 74
9.2 System Modules ..................................................................................................... 76
10 Syntax Summary ........................................................................................................... 77
11 Built-in Routines............................................................................................................ 85
12 Built-in Data Objects .................................................................................................... 87
13 Built in objects ............................................................................................................... 89
13.1 Object scope ......................................................................................................... 89
13.2 The value of a built in data object durability........................................................ 90
13.3 The way to define user installed objects............................................................... 91
14 Intertask objects ............................................................................................................ 93
14.1 Symbol levels ....................................................................................................... 93
14.2 Data object handling............................................................................................. 94
14.3 The way to define Built in shared object.............................................................. 94
15 Text files ......................................................................................................................... 95
15.1 Syntax for a text file ............................................................................................. 95
15.2 RAPID identifier................................................................................................... 96
15.3 Retrieving text during program execution............................................................ 97
15.4 Loading text files .................................................................................................. 97
16 Storage allocation for RAPID objects ......................................................................... 99
16.1 Module, routine, program flow and other basic instructions................................ 99
16.2 Move instructions ................................................................................................. 100
16.3 I/O instructions ..................................................................................................... 100
byte - Decimal values 0 - 255 ............................................................................................ 101
Description................................................................................................................... 101
Examples ..................................................................................................................... 101
Error handling.............................................................................................................. 101
Characteristics ............................................................................................................. 101
Related information ..................................................................................................... 101
BitSet - Set a specified bit in a byte data......................................................................... 103
Examples ..................................................................................................................... 103
Arguments ..................................................................................................................... 103
Limitations..................................................................................................................... 104
Syntax ............................................................................................................................ 104
Related information ....................................................................................................... 104
BitClear - Clear a specified bit in a byte data ................................................................ 105
Examples ..................................................................................................................... 105

RAPID Developer’s Manual 3


RAPID Developer’s Manual

Arguments ..................................................................................................................... 105


Limitations..................................................................................................................... 106
Syntax ............................................................................................................................ 106
Related information....................................................................................................... 106
BitCheck - Check if a specified bit in a byte data is set................................................. 107
Example....................................................................................................................... 107
Return value Data type: bool......................................................................................... 107
Arguments ..................................................................................................................... 108
Limitations..................................................................................................................... 108
Syntax ............................................................................................................................ 108
Related information....................................................................................................... 108
BitAnd - Logical bitwise AND - operation on byte data................................................ 109
Example....................................................................................................................... 109
Return value Data type: byte ......................................................................................... 109
Arguments ..................................................................................................................... 110
Limitations..................................................................................................................... 110
Syntax ............................................................................................................................ 110
Related information....................................................................................................... 110
BitOr - Logical bitwise OR - operation on byte data..................................................... 111
Example....................................................................................................................... 111
Return value Data type: byte ......................................................................................... 111
Arguments ..................................................................................................................... 112
Limitations..................................................................................................................... 112
Syntax ............................................................................................................................ 112
Related information....................................................................................................... 112
BitXOr - Logical bitwise XOR - operation on byte data............................................... 113
Example....................................................................................................................... 113
Return value Data type: byte ......................................................................................... 113
Arguments ..................................................................................................................... 114
Limitations..................................................................................................................... 114
Syntax ............................................................................................................................ 114
Related information....................................................................................................... 114
BitNeg - Logical bitwise NEGATION - operation on byte data ................................... 115
Example....................................................................................................................... 115
Return value Data type: byte ......................................................................................... 115
Arguments ..................................................................................................................... 115
Limitations..................................................................................................................... 115

4 RAPID Developer’s Manual


RAPID Developer’s Manual

Syntax ............................................................................................................................ 116


Related information ....................................................................................................... 116
BitLSh - Logical bitwise LEFT SHIFT- operation on byte data ................................... 117
Example ....................................................................................................................... 117
Return value Data type: byte ......................................................................................... 117
Arguments ..................................................................................................................... 118
Limitations..................................................................................................................... 118
Syntax ............................................................................................................................ 118
Related information ....................................................................................................... 118
BitRSh - Logical bitwise RIGHT SHIFT- operation on byte data................................ 119
Example ....................................................................................................................... 119
Return value Data type: byte ........................................................................................ 119
Arguments .................................................................................................................... 120
Limitations..................................................................................................................... 120
Syntax ............................................................................................................................ 120
Related information ....................................................................................................... 120
datapos - Enclosing block for a data object .................................................................... 121
Description................................................................................................................... 121
Example ....................................................................................................................... 121
Characteristics ............................................................................................................. 121
Related information ..................................................................................................... 121
SetDataSearch - Define the symbol set in a search sequence ....................................... 123
Example ....................................................................................................................... 123
Arguments ................................................................................................................... 123
Program Running......................................................................................................... 125
Limitations................................................................................................................... 125
Syntax .......................................................................................................................... 126
Related information ..................................................................................................... 126
GetNextSym - Get next matching symbol....................................................................... 127
Example ....................................................................................................................... 127
Return value Data type: bool ....................................................................................... 127
Arguments ................................................................................................................... 127
Syntax .......................................................................................................................... 128
Related information ..................................................................................................... 128
GetDataVal - Get the value of a data object .................................................................. 129
Example ....................................................................................................................... 129
Arguments ................................................................................................................... 129
Error handling.............................................................................................................. 130
Limitations................................................................................................................... 130

RAPID Developer’s Manual 5


RAPID Developer’s Manual

Syntax ......................................................................................................................... 4-130


Related information ................................................................................................... 4-130
SetDataVal - Set the value of a data object .................................................................... 4-131
Example....................................................................................................................... 4-131
Arguments ................................................................................................................... 4-131
Error handling.............................................................................................................. 4-132
Limitations................................................................................................................... 4-132
Syntax .......................................................................................................................... 4-132
Related information ..................................................................................................... 4-132
SetAllDataVal - Set a value to all data objects in a defined set................................... 4-133
Example....................................................................................................................... 4-133
Arguments ................................................................................................................... 4-133
Program Running ........................................................................................................ 4-134
Limitations................................................................................................................... 4-134
Syntax .......................................................................................................................... 4-134
Related information ..................................................................................................... 4-134
AliasIO - Define I/O signal with alias name ................................................................... 5-135
Example 1.................................................................................................................... 5-135
Arguments ................................................................................................................... 5-135
Program execution....................................................................................................... 5-136
Example 2.................................................................................................................... 5-136
Limitation .................................................................................................................... 5-136
Syntax .......................................................................................................................... 136
Related information ..................................................................................................... 137
ArgName - Gets argument name..................................................................................... 139
Example....................................................................................................................... 139
Return value Data type: string..................................................................................... 139
Arguments ................................................................................................................... 539
Program execution....................................................................................................... 139
Example....................................................................................................................... 140
Error handling.............................................................................................................. 141
Syntax .......................................................................................................................... 141
Related information ..................................................................................................... 141
BookErrNo - Book a RAPID system error number....................................................... 143
Examples ..................................................................................................................... 143
Arguments ................................................................................................................... 143
Limitations................................................................................................................... 144

6 RAPID Developer’s Manual


RAPID Developer’s Manual

Syntax .......................................................................................................................... 144


Related information ..................................................................................................... 144
TextTabGet - Get text table number................................................................................ 145
Example ....................................................................................................................... 145
Return value Data type: num ....................................................................................... 146
Arguments ................................................................................................................... 146
Syntax .......................................................................................................................... 146
Related information ..................................................................................................... 146
TextGet - Get text from system text tables...................................................................... 147
Example ....................................................................................................................... 147
Return value Data type: string..................................................................................... 147
Arguments ................................................................................................................... 147
Syntax .......................................................................................................................... 147
Related information ..................................................................................................... 148
IsSysId - Test system identity ........................................................................................... 149
Example ....................................................................................................................... 149
Return value Data type: bool ...................................................................................... 149
Arguments ................................................................................................................... 149
Syntax .......................................................................................................................... 149
Related information ..................................................................................................... 149
SetSysData - Set system data............................................................................................ 151
Example ....................................................................................................................... 151
Arguments ................................................................................................................... 151
Program execution....................................................................................................... 151
Syntax .......................................................................................................................... 152
Related information ..................................................................................................... 152
IsStopStateEvent - Test whether moved PP.................................................................... 153
Example ....................................................................................................................... 153
Return value Data type: bool ....................................................................................... 153
Arguments ................................................................................................................... 154
Limitations................................................................................................................... 154
Syntax .......................................................................................................................... 154
Related information ..................................................................................................... 154
ReadCfgData - Reads attribute of a system parameter................................................. 155
Examples ..................................................................................................................... 155

RAPID Developer’s Manual 7


RAPID Developer’s Manual

Arguments ................................................................................................................... 155


Program execution....................................................................................................... 155
Limitations................................................................................................................... 156
Error handling.............................................................................................................. 156
Syntax .......................................................................................................................... 156
Related information ..................................................................................................... 156
WriteCfgData - Writes attribute of a system parameter .............................................. 157
Examples ..................................................................................................................... 157
Arguments ................................................................................................................... 157
Program execution....................................................................................................... 157
Limitations................................................................................................................... 158
Error handling.............................................................................................................. 158
Syntax .......................................................................................................................... 158
Related information ..................................................................................................... 158
PFIOResto - Restore Digital Output Signals after Power Failure ............................... 159
Example....................................................................................................................... 159
Program execution....................................................................................................... 159
Syntax .......................................................................................................................... 159
Related information ..................................................................................................... 159
PFDOVal - Digital Output Value before Power Failure .............................................. 161
Example....................................................................................................................... 161
Return value Data type: dionum ................................................................................. 161
Arguments ................................................................................................................... 161
Syntax .......................................................................................................................... 161
Related information ..................................................................................................... 162
PFGOVal - Group Output Value before Power Failure .............................................. 163
Example....................................................................................................................... 163
Return value Data type: num....................................................................................... 163
Arguments ................................................................................................................... 163
Syntax .......................................................................................................................... 163
Related information ..................................................................................................... 164
PFRestart - Check interrupted path after power failure ............................................ 165
Example....................................................................................................................... 165
Return value Data type: bool ....................................................................................... 165
Arguments ................................................................................................................... 165
Syntax .......................................................................................................................... 165
Related information ..................................................................................................... 166

8 RAPID Developer’s Manual


RAPID Developer’s Manual

TriggSpeed - Defines TCP speed proportional analog output with fixed


position-time scale event ............................................................................................. 167
Examples ..................................................................................................................... 167
Arguments ................................................................................................................... 168
Program execution....................................................................................................... 170
Examples ..................................................................................................................... 171
Limitations................................................................................................................... 171
Error handling.............................................................................................................. 172
Related system parameters .......................................................................................... 173
Syntax .......................................................................................................................... 173
Related information ..................................................................................................... 173
StepBwdPath - Move backwards one step on path ........................................................ 175
Example ....................................................................................................................... 175
Arguments ................................................................................................................... 175
Program execution....................................................................................................... 175
Limitations................................................................................................................... 176
Syntax .......................................................................................................................... 176
Related information ..................................................................................................... 176
restartdata - Restart data for trigg signals ..................................................................... 177
Definition..................................................................................................................... 177
Description................................................................................................................... 177
Components ................................................................................................................. 177
Structure....................................................................................................................... 179
Related information ..................................................................................................... 179
TriggStopProc - Generate restart data for trigg signals at stop ................................... 181
Arguments ................................................................................................................... 181
Program execution....................................................................................................... 182
Performing a restart ..................................................................................................... 185
Limitation .................................................................................................................... 185
Syntax .......................................................................................................................... 185
Related information ..................................................................................................... 186
dir - File Directory structure............................................................................................ 187
Description................................................................................................................... 187
Example ....................................................................................................................... 187
Characteristics ............................................................................................................. 187
Related information ..................................................................................................... 187
MakeDir - Create a new directory................................................................................... 189
Examples ..................................................................................................................... 189

RAPID Developer’s Manual 9


RAPID Developer’s Manual

Arguments ................................................................................................................... 189


Error handling.............................................................................................................. 189
Syntax .......................................................................................................................... 189
Related information ..................................................................................................... 189
OpenDir - Open a directory ............................................................................................. 191
Example....................................................................................................................... 191
Arguments ................................................................................................................... 191
Limitations................................................................................................................... 191
Error handling.............................................................................................................. 191
Syntax .......................................................................................................................... 192
Related information ..................................................................................................... 192
CloseDir - Close a directory ............................................................................................. 193
Example....................................................................................................................... 193
Arguments ................................................................................................................... 193
Syntax .......................................................................................................................... 193
Related information ..................................................................................................... 193
RemoveDir - Delete a directory ....................................................................................... 195
Examples ..................................................................................................................... 195
Arguments ................................................................................................................... 195
Error handling.............................................................................................................. 195
Syntax .......................................................................................................................... 195
Related information ..................................................................................................... 195
ReadDir - Read next entry in a directory ....................................................................... 197
Example....................................................................................................................... 197
Return value Data type: bool....................................................................................... 197
Arguments ................................................................................................................... 197
Program execution....................................................................................................... 197
Example....................................................................................................................... 198
Error handling.............................................................................................................. 198
Syntax .......................................................................................................................... 199
Related information ..................................................................................................... 199
IsFile - Check the type of a file ........................................................................................ 201
Example....................................................................................................................... 201
Return value Data type: bool....................................................................................... 201
Arguments ................................................................................................................... 202
Program execution....................................................................................................... 202
Example....................................................................................................................... 203
Error handling.............................................................................................................. 203

10 RAPID Developer’s Manual


RAPID Developer’s Manual

Syntax .......................................................................................................................... 204


Related information ..................................................................................................... 204
FileSize - Retrieve the size of a file .................................................................................. 205
Example ....................................................................................................................... 205
Return value Data type: num ....................................................................................... 205
Arguments ................................................................................................................... 205
Program execution....................................................................................................... 205
Example ....................................................................................................................... 206
Error handling.............................................................................................................. 207
Syntax .......................................................................................................................... 207
Related information ..................................................................................................... 207
Internt........................................................................................................................... 207
FSSize - Retrieve the size of a file system........................................................................ 211
Example ....................................................................................................................... 211
Return value Data type: num ....................................................................................... 211
Arguments ................................................................................................................... 211
Program execution....................................................................................................... 211
Example ....................................................................................................................... 212
Error handling.............................................................................................................. 212
Syntax .......................................................................................................................... 212
Related information ..................................................................................................... 213
RemoveFile - Delete a file ................................................................................................. 215
Examples ..................................................................................................................... 215
Arguments ................................................................................................................... 215
Error handling.............................................................................................................. 215
Syntax .......................................................................................................................... 215
Related information ..................................................................................................... 215
Elementary IO Configuration File .................................................................................. 217
Defining a IO module type section (EIO_UNIT_TYPE)............................................ 218
Defining Parameters to a unit type. (EIO_PARAM) ................................................... 220
Defining a IO unit (EIO_UNIT).................................................................................. 221
Defining values for configurable unit parameters. (EIO_PARAM_VALUE)............. 224
Defining input and output signals. (EIO_SIGNAL).................................................... 224
Defining signal groups. (EIO_GROUP_SIGNAL = EIO_SIGNAL) ......................... 229
Defining cross connections. (EIO_CROSS)................................................................ 230
Predefined Buses and Unit types in the Elementary I/O System ................................ 230
• Topic: Communication .................................................................................................... 232
Defining physical channels.......................................................................................... 232

RAPID Developer’s Manual 11


RAPID Developer’s Manual

Defining Transmission Protocol.................................................................................. 232


Defining Application Protocol .................................................................................... 233
17 Index............................................................................................................................... 235

12 RAPID Developer’s Manual


RAPID Kernel Reference Manual Introduction

1 Introduction
This manual contains a formal description of the ABB Robotics robot programming
language RAPID.

1.1 Design Objectives


The RAPID language is aimed to support a levelled programming concept where new
routines, data objects and data types may be installed at a specific IRB site. This con-
cept makes it possible to customize (extend the functionality of) the programming en-
vironment and must be fully supported by the programming language.

In addition, with RAPID a number of powerful features are introduced:

- Modular Programming - Tasks/Modules


- Procedures and Functions
- Type definitions
- Variables, Persistents and Constants
- Arithmetic
- Control Structures
- Backward Execution Support
- Error Recovery
- Interrupt Handling
- Placeholders

1.2 Language Summary

Task - Modules

An RAPID application is called a task. A task is composed of a set of modules. A mod-


ule contains a set of data and routine declarations. The task buffer is used to host mod-
ules currently in use (execution, development) on a system.

RAPID distinguishes between task modules and system modules. A task module is con-
sidered to be a part of the task/application while a system module is considered to be
a part of the “system”. System modules are automatically loaded to the task buffer dur-
ing system start-up and are aimed to (pre)define common, system specific data objects
(tools, weld data, move data ..), interfaces (printer, logfile ..) etc.

While small applications usually are contained in a single task module (besides the sys-
tem module/s), larger applications may have a "main" task module that in turn refer-
ences routines and/or data contained in one or more other, "library" task modules.

One task module contains the entry procedure of the task. Running the task really
means that the entry routine is executed. Entry routines must be parameterless.

RAPID Developer’s Manual 15


Introduction RAPID Kernel Reference Manual

Routines

There are three types of routines - functions, procedures and traps. A function returns
a value of a specific type and is used in expression context. A procedure does not return
any value and is used in statement context. Trap routines provide a means to respond
to interrupts. A trap routine can be associated with a particular interrupt and is then later
automatically executed if that interrupt occurs.

User (defined) routines are defined using RAPID declarations while predefined rou-
tines are supplied by the system and always available.

User Routines

An RAPID routine declaration specifies the routine name, routine parameters, data dec-
larations, statements and possibly a backward handler or/and error handler.

Predefined Routines

There are two types of predefined routines - built-in routines and installed routines.
Built-in routines (like arithmetic functions) are a part of the RAPID language while in-
stalled routines are application/equipment dependent routines used for the control of
the robot arm, grippers, sensors etc. Note that from the users point of view there is no
difference between built-in routines and installed routines.

Data Objects

There are four types of data objects - constants, variables, persistents and parameters.
A persistent (data object) can be described as a "persistent" variable. While a variable
value is lost (re-initialized) at the beginning of each new session - at module load (mod-
ule variable) or routine call (routine variable) - a persistent keeps its value between ses-
sions. Data objects can be structured (record) and dimensioned (array, matrix etc.).

Statements

A statement may be simple or compound. A compound statement may in turn contain


other statements. A label is a "no operation" statement that can be used to define named
(goto-) positions in a program. Statements are executed in succession unless a goto, re-
turn, raise, exit, retry or trynext statement, or the occurrence of an interrupt or error
causes the execution to continue at another point.

The assignment statement changes the value of a variable, persistent or parameter.

A procedure call invokes the execution of a procedure after associating any arguments
with corresponding parameters of the procedure. RAPID supports late binding of pro-
cedure names.

The goto statement causes the execution to continue at a position specified by a label.

The return statement terminates the evaluation of a routine.

16 RAPID Developer’s Manual


RAPID Kernel Reference Manual Introduction

The raise statement is used to raise and propagate errors.

The exit statement terminates the evaluation of a task.

The connect statement is used to allocate an interrupt number and associate it with a
trap (interrupt service) routine.

The retry and trynext statements are used to resume evaluation after an error.

The if and test statements are used for selection. The if statement allows the selection
of a statement list based on the value of a condition. The test statement selects one (or
none) of a set of statement lists, depending on the value of an expression.

The for and while statements are used for iteration. The for statement repeats the eval-
uation of a statement list as long as the value of a loop variable is within a specified
value range. The loop variable is updated (with selectable increment) at the end of each
iteration. The while statement repeats the evaluation of a statement list as long as a con-
dition is met. The condition is evaluated and checked at the beginning of each iteration.

Backward Execution

RAPID supports stepwise, backward execution of statements. Backward execution is


very useful for debugging, test and adjustment purposes during RAPID program de-
velopment. RAPID procedures may contain a backward handler (statement list) that
defines the backward execution "behaviour" of the procedure.

Error Recovery

The occurrence of a runtime detected error causes suspension of normal program exe-
cution. The control may instead be passed to a user provided error handler. An error
handler may be included in any routine declaration. The handler can obtain informa-
tion about the error and possibly take some actions in response to it. If desirable, the
error handler can return the control to the statement that caused the error (retry) or to
the statement after the statement that caused the error (trynext) or to the point of the
call of the routine. If further execution is not possible, at least the error handler can as-
sure that the task is given a graceful abortion.

Interrupts

Interrupts occur as a consequence of a user defined (interrupt) condition turning true.


Unlike errors, interrupts are not directly related to (synchronous with) the execution of
a specific piece of the code. The occurrence of an interrupt causes suspension of nor-
mal program execution and the control may be passed to a trap routine. After neces-
sary actions have been taken in response to the interrupt the trap routine can resume
execution at the point of the interrupt.

RAPID Developer’s Manual 17


Introduction RAPID Kernel Reference Manual

Data Types

Any RAPID object (value, expression, variable, function etc.) has a data type. A data
type can either be a built-in type or an installed type (compare installed routines) or a
user-defined (defined in RAPID) type. Built-in types are a part of the RAPID language
while the set of installed or user-defined types may differ from site to site. From the
users point of view there is no difference between built-in, installed and user-defined
types. There are three different kinds of types - atomic types, record types and alias
types. The definition of an atomic type must be built-in or installed, but a record or alias
type could also be user-defined.

Atomic types are "atomic" in the sense that they are not defined upon any other type
and they cannot be divided into parts or components. Record types are built up by a set
of named, ordered components. An alias type is by definition equal to another type. Ali-
as types make it possible to classify data objects.

In addition to the atomic, record or alias classification of types, each type has a value
class. There are three value classes of types - value types, nonvalue types and semivalue
types. An object of value type is simply considered to represent some form of "value"
(e.g, 3.55 or "John Smith"). A nonvalue (type) object instead represents a hidden/en-
capsulated description of some physical or logical object, e.g. a file. Semivalue objects
are somewhat special. They really have two types, one "basic" nonvalue type and one
associated value type that may be used to represent some property of the nonvalue type.

Built-in Data Types

The built-in atomic types are bool, num and string. Bool is an enumerated type with the
value domain {TRUE, FALSE} and provides a means of performing logical and rela-
tional computations. The num type supports exact and approximate arithmetic compu-
tations. The string type represents character sequences.

The built-in record types are pos, orient and pose. The pos type represents a position in
space (vector). The orient type represents an orientation in space. The pose type repre-
sents a coordinate system (position/orientation combination).

The built-in alias types are errnum and intnum. Errnum and intnum are both aliases for
num and are used to represent error and interrupt numbers.

Operations on objects of built-in types are defined by means of arithmetic, relational


and logical operators and predefined routines.

Installed Data Types

The concept of installed types supports the use of installed routines by making it pos-
sible to use appropriate parameter types. An installed type can be either an Atomic,
Record or Alias type.

18 RAPID Developer’s Manual


RAPID Kernel Reference Manual Introduction

User-defined Data Types

The user-defined types make it easier to customise an application program. They also
make it possible to write a RAPID program which is more readable.

Placeholders

The concept of placeholders supports structured creation and modification of


RAPID programs. Placeholders may be used by Offline and Online programming tools
to temporarily represent "not yet defined" parts of an RAPID program. A program that
contains placeholders is syntactically correct and may be loaded to (and saved from)
the task buffer. If the placeholders in an RAPID program do not cause any semantic
errors (see 1.4), such a program can even be executed, but any placeholder encountered
causes an execution error (see 1.4).

1.3 Syntax Notation


The context-free syntax of the RAPID language is described using a modified variant
of the Backus-Naur Form - EBNF:

- Boldface, upper case words denote reserved words and placeholders


e.g. WHILE
- Quoted strings denote other terminal symbols.
e.g. ’+’
- Strings enclosed in angle brackets denote syntactic categories - nonterminals.
e.g. <constant expression>
- The symbol "::=" means is defined as.
e.g. <dim> ::= <constant expression>
- A list of terminals and/or nonterminals denotes a sequence.
e.g. GOTO <identifier> ’;’
- Square brackets enclose optional items. The items may occur zero or one time.
e.g. <return statement> ::= RETURN [ <expression> ] ’;’
- The vertical bar separates alternative items.
e.g. OR | XOR
- Braces enclose repeated items. The items may appear zero or more times.
e.g <statement list> ::= { <statement> }
- Parentheses are used to hierarchically group concepts together
e.g. ( OR | XOR ) <logical term>

RAPID Developer’s Manual 19


Introduction RAPID Kernel Reference Manual

1.4 Error Classification


Based on the time of detection errors may be divided into:

- Static errors
- Execution errors

Static errors are detected either when a module is loaded into the task buffer (see 9) or
prior to program execution after program modification.

- Lexical errors - illegal lexical elements.


e.g. b := 2E52786; - Exponent out of range
- Syntax errors - violation of the syntax rules.
e.g. FOR i 5 TO 10 DO - Missing FROM keyword
- Semantic errors - violation of semantic rules - typically type errors.
e.g. VAR num a;
a := "John"; - Data type mismatch
- Fatal (system resource) errors.
e.g. Program to complex (nested)
- Execution errors occur (are detected) during the execution of a task:
- Arithmetic errors.
e.g. Division by zero
- IO-errors.
e.g. No such file or device
- Fatal (system resource) errors.
e.g. Execution Stack overflow

The error handler concept of RAPID makes it possible to recover from nonfatal execu-
tion errors. Refer to 7.

20 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

2 Lexical Elements
This chapter defines the lexical elements of RAPID.

2.1 Character Set


Sentences of the RAPID language are constructed using the standard ISO 8859-1 char-
acter set. In addition newline, tab and formfeed control characters are recognized.

<character> ::= -- ISO 8859-1 --


<newline> ::= -- newline control character --
<tab> ::= -- tab control character --
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<hex digit> ::= <digit> | A | B | C | D | E | F | a | b | c | d | e | f
<letter> ::=
<upper case letter>
| <lower case letter>
<upper case letter> ::=
A|B|C|D|E|F|G|H|I|J
|K|L|M|N|O|P|Q|R|S|T
|U|V|W|X|Y|Z|À|Á|Â|Ã
|Ä|Å|Æ|Ç|È|É|Ê|Ë|Ì|Í
| Î | Ï | 1) | Ñ | Ò | Ó | Ô | Õ | Ö | Ø
| Ù | Ú | Û | Ü | 2) | 3) | ß
<lower case letter> ::=
a|b|c|d|e|f|g|h|i|j
|k|l|m|n|o|p|q|r|s|t
|u|v|w|x|y|z|ß|à|á|â|ã
|ä|å|æ|ç|è|é|ê|ë|ì|í
| î | ï | 1) | ñ | ò | ó | ô | õ | ö | ø
| ù | ú | û | ü | 2) | 3) | ÿ
1) Icelandic letter eth.
2) Letter Y with acute accent.
3) Icelandic letter thorn.

2.2 Lexical Units


An RAPID sentence is a sequence of lexical units - tokens. The RAPID tokens are:

- identifiers
- reserved words
- literals
- delimiters
- placeholders
- comments

RAPID Developer’s Manual 21


Lexical Elements RAPID Kernel Reference Manual

Tokens are indivisible. Except for string literals and comments, space must not occur
within tokens.

An identifier, reserved word or numeric literal must be separated from a trailing, adja-
cent identifier, reserved word or numeric literal by one or more space, tab, formfeed or
newline characters. Other combinations of tokens may by separated by one or more
space, tab, formfeed or newline characters.

2.3 Identifiers
Identifiers are used for naming objects.

<identifier> ::=
<ident>
| <ID>
<ident> ::= <letter> {<letter> | <digit> | ’_’}

The maximum length of an identifier is 16 characters. All characters of an identifier are


significant. Identifiers differing only in the use of corresponding upper and lower case
letters are considered the same. The placeholder <ID> (see and 2.9) can be used to rep-
resent an identifier.

2.4 Reserved Words


The 56 identifiers listed below are reserved words. They have a special meaning in the
language. They may not be used in any context not specially stated by the syntax.

ALIAS AND BACKWARD


CASE CONNECT CONST
DEFAULT DIV DO
ELSE ELSEIF ENDFOR
ENDFUNC ENDIF ENDMODULE
ENDPROC ENDRECORD ENDTEST
ENDTRAP ENDWHILE ERROR
EXIT FALSE FOR
FROM FUNC GOTO
IF INOUT LOCAL
MOD MODULE NOSTEPIN
NOT NOVIEW OR
PERS PROC RAISE
READONLY RECORD RETRY
RETURN STEP SYSMODULE
TEST THEN TO
TRAP TRUE TRYNEXT
VAR VIEWONLY WHILE
WITH XOR

22 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

2.5 Num Literals


A num literal represents a numeric value.

<num literal> ::=


<integer> [ <exponent> ]
| <integer> ’.’ [ <integer> ] [ <exponent> ]
| [ <integer> ] ’.’ <integer> [ <exponent> ]

<integer> ::= <digit> {<digit>}

<exponent> ::= (’E’ | ’e’) [’+’ | ’-’] <integer>

A num literal must be in the range specified by the ANSI IEEE 754-1985 standard (sin-
gle precision) float format.

e.g. 7990 23.67 2E6 .27 2.5E-3 38.

2.6 Bool Literals


A bool literal represents a logical value.

<bool literal> ::= TRUE | FALSE

2.7 String Literals


A string literal is a sequence of zero or more characters enclosed by the double quote
(") character.

<string literal> ::= ’"’ { <character> | <character code> } ’"’


<character code> ::= ’\’ <hex digit> <hex digit>

The possibility to use character codes provides a means to include non printable char-
acters (binary data) in string literals. If a back slash or double quote character should
be included in a string literal it must be written twice.

e.g. "A string literal"


"Contains a "" character"
"Ends with BEL control character\07"
"Contains a \\ character"

2.8 Delimiters
A delimiter is one of the following characters:

{ } ( ) [ ] , . = < > + - * / : ; ! \ ?

or one of the following compound symbols:

:= <> >= <=

RAPID Developer’s Manual 23


Lexical Elements RAPID Kernel Reference Manual

2.9 Placeholders
Placeholders can be used by Offline and Online programming tools to temporarily rep-
resent "not yet defined" parts of an RAPID program. A program that contains place-
holders is syntactically correct and may be loaded to (and saved) from the task buffer.
If the placeholders in an RAPID program do not cause any semantic errors (see 1.4),
such a program can even be executed, but any placeholder encountered causes an exe-
cution error (see 1.4). RAPID recognizes the following 13 placeholders:

<TDN> - (represents a) data type definition


<DDN> - (represents a) data declaration
<RDN> - routine declaration
<PAR> - parameter declaration
<ALT> - alternative parameter declaration
<DIM> - array dimension
<SMT> - statement
<VAR> - data object (variable, persistent or parameter)
reference
<EIT> - else if clause of if statement
<CSE> - case clause of test statement
<EXP> - expression
<ARG> - procedure call argument
<ID> - identifier

2.10 Comments
A comment starts with an exclamation point and is terminated by a newline character.
A comment can never include a newline character.

<comment> ::= ’!’ { <character> | <tab> } <newline>

Comments have no effect on the meaning of an RAPID code sequence, their sole pur-
pose is the enlightenment of the reader.

Each RAPID comment occupies an entire source line and may occur either as:

- an element of a type definition list (see 3)


- an element of a data declaration list (see 5.3),
- an element of a routine declaration list (see 9.1) or
- an element of a statement list (see 4.2).
e.g.
! Increase length
length := length + 5;
IF length < 1000 OR length > 14000 THEN
! Out of bounds
EXIT;
ENDIF
...

24 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

Comments located between the last data declaration (see 2.18) and the first routine dec-
laration (see 5) of a module are regarded to be a part of the routine declaration list.
Comments located between the last data declaration and the first statement of a routine
are regarded to be a part of the statement list (see 4.2).

2.11 Data Types


An RAPID data type is identified by its name and can be either built-in, installed or a
user-defined (defined in RAPID).

<data type> ::= <identifier>

Built-in types are part of the RAPID language while the set of installed or user-defined
types may differ from site to site. Please refer to site specific documentation. The con-
cept of installed types supports the use of installed routines by making it possible to
use appropriate parameter types. The user-defined types make it possible to prepare
understandable and easy programmable application packets for the application engi-
neer. From the users point of view there is no difference between built-in, installed and
user-defined types.

There are three different kinds of types - atomic types, record types and alias types.

A type definition introduces an alias or a record by associating an identifier with a de-


scription of a data type. A type definition can be represented by the placeholder
<TDN>.

<type definition> ::=


[LOCAL] ( <record definition>
| <alias definition> )
| <comment>
| <TDN>

Type definitions can occur in the heading section of modules (see 9).

The optional local directive classifies the data object being local, otherwise global (see
2.20).

e.g. LOCAL RECORD object - record definition


num usecount;
string name;
ENDRECORD

ALIAS num another_num; - alias definition

<TDN> - definition placeholder

RAPID Developer’s Manual 25


Lexical Elements RAPID Kernel Reference Manual

2.12 Scope Rules


The scope of a type definition denotes the area in which the type is visible and is deter-
mined by the context and position of its declaration.

The scope of a predefined type comprises any RAPID module.

A user-defined type is always defined inside a module. The following scope rules are
valid for module type definitions:

- The scope of a local module type definition comprises the module in which it is
contained.
- The scope of a global module type definition in addition comprises any other
module in the task buffer.
- Within its scope a module type definition hides any predefined type with the
same name.
- Within its scope a local module type definition hides any global module type
with the same name.
- Two module objects declared in the same module may not have the same name.
- Two global objects declared in two different modules in the task buffer may not
have the same name.

2.13 Atomic Types


Atomic types are "atomic" in the sense that they are not defined upon any other type
and cannot be divided into parts or components. The internal structure (implementa-
tion) of an atomic type is hidden. The built-in atomic types are the numeric type num,
the logical type bool and the text type string.

Num Type

A num object represents a numeric value. The num type denotes the domain specified
by the ANSI IEEE 754-1985 standard (single precision) float format.

Within the subdomain -8388607 to (+)8388608, num objects may be used to represent
integer (exact) values. The arithmetic operators +, -, and * (see 3.11) preserves integer
representation as long as operands and result are kept within the integer subdomain of
num.

Examples of num usage;

VAR num counter; - variable declaration


counter := 250; - num literal usage

26 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

Bool Type

A bool object represents a logical value.

The bool type denotes the domain of twovalued logic - { TRUE, FALSE }.

Examples of bool usage;

VAR bool active; - variable declaration


active := TRUE; - bool literal usage

String Type

A string object represents a character string.

The string type denotes the domain of all sequences of graphical characters (ISO 8859-
1) and control characters (non ISO 8859-1 characters in the numeric code range 0 ..
255). A string may consist of 0 to 80 characters (fixed 80 characters storage format).

Examples of string usage;

VAR string name; - variable declaration


name := "John Smith"; - string literal usage

2.14 Record Types


A record data type is a composite type with named, ordered components. The value of
a record type is a composite value consisting of the values of its components. A com-
ponent can have atomic type or record type. Semivalue types cannot be included in a
record type. The built-in record types are pos, orient and pose. The available set of in-
stalled and user-defined record types is by definition not bound by the RAPID specifi-
cation. Please refer to site specific documentation.

A record type is introduced by a record definition.

<record definition> ::=


RECORD <identifier>
<record component list>
ENDRECORD
<record component list> ::=
<record component definition> |
<record component definition> <record component list>
<record component definition> ::=
<data type> <record component name> ’;’

e.g. RECORD newtype


num x;
ENDRECORD

RAPID Developer’s Manual 27


Lexical Elements RAPID Kernel Reference Manual

A record value can be expressed using an aggregate representation.

e.g. [ 300, 500, depth ] - pos record aggregate value

A specific component of a record data object can be accessed by using the name of the
component.

e.g. p1.x := 300; - assignment of the x-component of the


pos variable p1

Unless otherwise stated the domain of a record type is the cartesian product of the do-
mains of its components.

Pos Type

A pos object represents a vector (position) in 3D space. The pos type has three compo-
nents:

[ x, y, z ]

name data type comment

x num X-axis component of position


y num Y-axis component of position
z num Z -axis component of position

Examples of pos usage:

VAR pos p1; - variable declaration


p1 := [ 10, 10, 55.7 ]; - aggregate usage
p1.z := p1.z + 250; - component usage
p1 := p1 + p2; - operator usage

Orient Type

An orient object represents an orientation (rotation) in 3D space. The orient type has
four components:

[ q1, q2, q3, q4 ]

name data type comment

q1 num first quarternion component

q2 num second quarternion component

q3 num third quarternion component

q4 num fourth quarternion component

28 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

The quarternion representation is the most compact way to express an orientation in


space. Alternate orientation formats (e.g. euler angles) can be specified using prede-
fined functions available for this purpose.

Examples of orient usage:

VAR orient o1; - variable declaration


o1 := [ 1, 0, 0, 0 ]; - aggregate usage
o1.q1 := -1; - component usage
o1 := euler( a1, b1, g1); - function usage

Pose Type

A pose object represents a 3D frame (coordinate system) in 3D-space. The pose type
has two components:

[ trans, rot ]

name data type comment

trans pos origin translation


rot orient rotation

Examples of pose usage:

VAR pose p1; - variable declaration


p1 := [[ 100, 100, 0 ], o1 ]; - aggregate usage
p1.trans := homepos; - component usage

2.15 Alias Types


An alias data type is defined as being equal to another type. Alias types provide a
means to classify objects. The system may use the alias classification to look up and
present type related objects.

An alias type is introduced by an alias definition.

<alias definition> ::=


ALIAS <type name> <identifier> ’;’

e.g. ALIAS num newtype;

e.g. Usage of alias type ’level’ (alias for num):

CONST level low := 2.5;


CONST level high := 4.0;

Note that one alias type cannot be defined upon another alias type.

The built-in alias types are errnum and intnum - both aliases for num.

RAPID Developer’s Manual 29


Lexical Elements RAPID Kernel Reference Manual

Errnum Type

The errnum type is an alias for num and is used for the representation of error numbers.

Intnum Type

The intnum type is an alias for num and is used for the representation of interrupt num-
bers.

2.16 Data Type Value Classes


With respect to the relation between object data type and object value, different data
types can be classified as being either a:

- value data type, a


- nonvalue (private) data type or a
- semivalue data type.

An object of value type is simply considered to represent some form of "value" (e.g. 5,
[10, 7, 3.25], "John Smith", TRUE). A nonvalue (type) object instead represents a hid-
den/encapsulated description (descriptor) of some physical or logical object, e.g. the
iodev (file) type.

The content ("value") of nonvalue objects can only be manipulated using installed rou-
tines ("methods"). Nonvalue objects may in RAPID programs only be used as argu-
ments to var or ref parameters.

e.g. Use of nonvalue object ’logfile’

VAR iodev logfile;


...
! Open logfile
Open "flp1:LOGDIR" \File := "LOGFILE1.DOC ", logfile;
...
! Write timestamp to logfile
Write logfile, "timestamp = " + GetTime();

Semivalue objects are somewhat special. They really have two types, one "basic" non-
value type and one associated (value) type that may be used to represent some property
of the nonvalue type. RAPID views a semivalue object as a value object when used in
value context (se table below) and a nonvalue object otherwise. The semantics (mean-
ing/result) of a read or update (value) operation performed upon a semivalue type is
defined by the type itself.

30 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

e.g. Use of semivalue object ’sig1’ in value context (the associaed


type of
signaldi is num).

VAR signaldi sig1;


...
! use digital input sig1 as value object
IF sig1 = 1 THEN ...
...
! use digital input sig1 as nonvalue object
IF DInput(sig1) = 1 THEN ...

Note that a semivalue object (type) can reject either reading or updating "by value".

.e.g. The following assignment will be rejected by sig1 since sig1


represents
an input device.

VAR signaldi sig1;


...
sig1 := 1;

The table below shows which combinations of object usage and type value class that
are possibly legal and which are impossible/illegal:

RAPID Developer’s Manual 31


Lexical Elements RAPID Kernel Reference Manual

X Legal/Possible
--- Illegal/Impossible Data type Value class
Object Declarations value nonvalue semivalue

Constant X ---

Persistent X ---

Variable with initialization X ---


Data Object Usage

Variable without initialization X X X

Routine Parameter
in X --- ---
var X X X
pers X --- ---
ref (only installed routines) X X X
inout:
var X --- ---
pers X --- ---

Function return value X --- ---

Object Reference value nonvalue semivalue

Assignment2) X --- X1)

Assignment X X3 X3)

Assignment4) X --- X1)

1) The associated type (value) is used.


2) Assignment target (see 6.4), Connect target (see 6.12).
3) Argument to var or ref parameter.
4) Object used in expression.

The basic value types are the built-in atomic types num, bool and string. A record type
with all components being value types is itself a value type, e.g the built-in types pos,
orient and pose. An alias type defined upon a value type is itself a value type, e.g. the
built-in types errnum and intnum.

A record type having at least one semivalue component and all other components have
value type is itself a semivalue type. An alias type defined upon a semivalue type is it-
self a semivalue type.

All other types are nonvalue types, e.g record types with at least one nonvalue compo-
nent and alias types defined upon nonvalue types.

Arrays have the same value class as the element value class.

32 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

2.17 Equal Types


The types of two objects are equal if the objects have the same structure (degree, di-
mension and number of components) and either:

- Both objects have the same type name (any alias type name included is first
replaced by its definition type).
- One of the objects is an aggregate (array or record) and the types of (all) corre-
sponding elements/components are equal.
- One of the objects has a value type, the other object has a semivalue type and
the type of the first object and the associated type of the semivalue object are
equal. Note that this is only valid in value context.

2.18 Data Declarations


There are four kinds of data objects - constants, variables, persistents and parameters.
Except for predefined data objects (see 2.19 and appendix C) and for loop variables
(see 4.15) all data objects must be declared. A data declaration introduces a constant,
a variable or a persistent by associating an identifier with a data type. Refer to 5.1 for
information on parameter declarations. A data declaration can be represented by the
placeholder <DDN>.

<data declaration> ::=


[LOCAL] ( <variable declaration>
| <persistent declaration>
| <constant declaration> )
| <comment>
| <DDN>

A persistent (data object) can be described as a "persistent" variable. While a variable


value is lost (re-initialised) at the beginning of each new session - at module load (mod-
ule variable) or routine call (routine variable) - a persistent keeps its value between ses-
sions. This is accomplished by letting an update of the value of a persistent automati-
cally lead to an update of the initialization value of the persistent declaration. When a
module (or task) is saved, the initialization value of any persistent declaration reflects
the current value of the persistent. In addition, persistents are stored in a system public
"database" and can be accessed (updated, referenced) by other components of the con-
trol system.

Data declarations can occur in the heading section of modules (see 9) and routines (see
5).

The optional local directive classifies the data object being local, otherwise global (see
2.20). Note that the local directive only may be used at module level (not inside a rou-
tine).

RAPID Developer’s Manual 33


Lexical Elements RAPID Kernel Reference Manual

e.g. LOCAL VAR num counter; - variable declaration

CONST num maxtemp := 39.5; - constant declaration

PERS pos refpnt := [100.23, 778.55, 1183.98]; -persistent declaration

<DDN -declaration placeholder

2.19 Predefined Data Objects


A predefined data object is supplied by the system and is always available. Predefined
data objects are automatically declared and can be referenced from any module. Refer
to appendix C for the description of built-in data objects.

2.20 Scope Rules


The scope of a data object denotes the area in which the object is visible and is deter-
mined by the context and position of its declaration.

The scope of a predefined data object comprises any RAPID module.

A data object declared outside any routine is called a module data object (module var-
iable, module constant or persistent). The following scope rules are valid for module
data objects:

- The scope of a local module data object comprises the module in which it is con-
tained.
- The scope of a global module data object in addition comprises any other mod-
ule in the task buffer.
- Within its scope a module data object hides any predefined object with the same
name.
- Within its scope a local module data object hides any global module object with
the same name.
- Two module objects declared in the same module may not have the same name.
- Two global objects declared in two different modules in the task buffer may not
have the same name.
- A global data object and a module may not share the same name.

A data object declared inside a routine is called a routine data object (routine variable
or routine constant). Note that the concept of routine data objects in this context also
comprises routine parameters (see 5.1).

34 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

The following scope rules are valid for routine data objects:

- The scope of a routine data object comprises the routine in which it is con-
tained.
- Within its scope a routine data object hides any predefined or user defined
object with the same name.
- Two routine data objects declared in the same routine may not have the same
name.
- A routine data object may not have the same name as a label declared in the
same routine.
- Refer to 5 and 9 for information on routines and task modules.

2.21 Storage Class


The storage class of a data object determines when the system allocates and deallo-
cates memory for the data object. The storage class of a data object is determined by
the kind of data object and the context of its declaration and can be either static or vol-
atile.

Constants, persistents and module variables are static. The memory needed to store the
value of a static data object is allocated when the module that declares the object is
loaded (see 9). This means that any value assigned to a persistent or a module variable
always remains unchanged until the next assignment.

Routine variables (and in parameters, see 5.1) are volatile. The memory needed to store
the value of a volatile object is allocated first upon the call of the routine in which the
declaration of the variable is contained. The memory is later deallocated at the point of
the return to the caller of the routine. This means that the value of a routine variable is
always undefined before the call of the routine and is always lost (becomes undefined)
at the end of the execution of the routine.

In a chain of recursive routine calls (a routine calling itself directly or indirectly) each
instance of the routine receives its own memory location for the "same" routine varia-
ble - a number of instances of the same variable are created.

2.22 Variable Declarations


A variable is introduced by a variable declaration.
<variable declaration> ::=
VAR <data type> <variable definition> ’;’
<variable definition> ::=
<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]
[ ’:=’ <constant expression> ]
<dim> ::= <constant expression>
e.g. VAR num x;
VAR pos curpos := [b+1, cy, 0];

RAPID Developer’s Manual 35


Lexical Elements RAPID Kernel Reference Manual

Variables of any type (including installed types) can be given an array (of degree 1, 2
or 3) format by adding dimension information to the declaration. The dimension ex-
pression must represent an integer value (see ) greater than 0.

e.g. ! pos (14 x 18) matrix


VAR pos pallet{14, 18};

Variables with value types (see 2.16) may be initialized (given an initial value). The
data type of the constant expression used to initialize a variable must be equal to the
variable type.

e.g. VAR string author_name := "John Smith";


VAR pos start := [100, 100, 50];
VAR num maxno{10} := [1, 2, 3, 9, 8, 7, 6, 5, 4, 3];

An uninitialised variable (or variable component/element) receives the following initial


value.

Data Type Initial Value


num (or alias for num) 0
bool (or alias for bool) FALSE
string (or alias for string) ""
Installed atomic types all bits 0’ed

2.23 Persistent Declarations


A persistent is introduced by a persistent declaration. Note that persistents can only be
declared at module level (not inside a routine). A persistent can be given any value data
type.

<persistent declaration> ::=


PERS <data type> <persistent definition> ’;’
<persistent definition> ::=
<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]
’:=’ <literal expression>

e.g. PERS num pcounter := 0;

Persistents of any type (including installed types) can be given an array (of degree 1, 2
or 3) format by adding dimension information to the declaration. The dimension ex-
pression must represent an integer value (see ) greater than 0.

e.g. ! 2 x 2 matrix
PERS num grid{2, 2} := [[0, 0], [0, 0]];

Persistents must be initialized (given an initial value). The data type of the literal ex-
pression used to initialize a persistent must be equal to the persistent type. Note that an
update of the value of a persistent automatically leads to an update of the initialization
expression of the persistent declaration.

36 RAPID Developer’s Manual


RAPID Kernel Reference Manual Lexical Elements

e.g. MODULE ...


PERS pos refpnt := [0, 0, 0];
...
refpnt := [x, y, z];
...
ENDMODULE

after execution the module looks like

MODULE ...
PERS pos refpnt := [100.23, 778.55, 1183.98];
...
refpnt := [x, y, z];
...
ENDMODULE

if the value of the variables x, y and z at the time of execution


was 100.23,
778.55 and 1183.98 respectively.

2.24 Constant Declarations


A constant represents a static value and is introduced by a constant declaration. The
value of a constant cannot be modified. A constant can be given any value data type.

<constant declaration> ::=


CONST <data type> <constant definition> ’;’
<constant definition> ::=
<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]
’:=’ <constant expression>
<dim> ::= <constant expression>

e.g. CONST num pi := 3.141592654;


CONST num siteno := 9;

A constant of any type (including installed types) can be given an array (of degree 1,
2 or 3) format by adding dimensioning information to the declaration. The dimension
expression must represent an integer value (see ) greater than 0. The data type of the
constant value must be equal to the constant type.

e.g. CONST pos seq{3} := [[614, 778, 1020],


[914, 998, 1021],
[814, 998, 1022]];

RAPID Developer’s Manual 37


Lexical Elements RAPID Kernel Reference Manual

38 RAPID Developer’s Manual


RAPID Kernel Reference Manual Expressions

3 Expressions
An expression specifies the evaluation of a value. An expression can be represented by
the placeholder <EXP>.

<expression> ::=
<expr>
| <EXP>
<expr> ::= [ NOT ] <logical term> { ( OR | XOR ) <logical term> }
<logical term> ::= <relation> { AND <relation> }
<relation> ::= <simple expr> [ <relop> <simple expr> ]
<simple expr> ::= [ <addop> ] <term> { <addop> <term> }
<term> ::= <primary> { <mulop> <primary> }
<primary> ::=
<literal>
| <variable>
| <persistent>
| <constant>
| <parameter>
| <function call>
| <aggregate>
| ’(’ <expr> ’)’
<relop> ::= ’<’ | ’<=’ | ’=’ | ’>’ | ’>=’ | ’<>’
<addop> ::= ’+’ | ’-’
<mulop> ::= ’*’ | ’/’ | DIV | MOD

The relative priority of the operators determines the order in which they are evaluated.
Parentheses provide a means to override operator priority. The rules above imply the
following operator priority:

* / DIV MOD - highest


+-
< > <> <= >= =
AND
XOR OR NOT - lowest

An operator with high priority is evaluated prior to an operator with low priority. Op-
erators of the same priority are evaluated from left to right.

Examples of evaluation order:

e.g. a+b+c --> (a + b) + c -- left to right rule


a+b*c --> a + (b * c) -- * higher than +
a OR b OR c --> (a OR b) OR c-- Left to right rule
a AND b OR c AND d --> (a AND b) OR (c AND d)
a < b AND c < d --> (a < b) AND (c < d)

RAPID Developer’s Manual 39


Expressions RAPID Kernel Reference Manual

The left operand of a binary operator 1) is evaluated prior to the right operand. Note that
the evaluation of expressions involving AND and OR operators is optimised so that the
right operand of the expression will not be evaluated if the result of the operation can
be determined after the evaluation of the left operand.

3.1 Constant Expressions


Constant expressions are used to represent values in data declarations.

<constant expression> ::= <expression>

A constant expression is a specialization of an ordinary expression. It may not at any


level contain:

- Variables, Persistents
- Function calls

e.g. CONST num radius := 25;


CONST num pi := 3.141592654;
! constant expression
CONST num area := pi * radius * radius;

3.2 Literal Expressions


Literal expressions are used to represent initialization values in persistent declarations.

<literal expression> ::= <expression>

A literal expression is a specialization of an ordinary expression. It may only contain


either a single literal value (+ or - may precede a num literal) or a single aggregate with
members that in turn are literal expressions.

e.g. PERS pos refpnt := [100, 778, 1183];


PERS num diameter := 24.43;

3.3 Conditional Expressions


Conditional expressions are used to represent logical values.

<conditional expression> ::= <expression>

A conditional expression is a specialization of an ordinary expression. The resulting


type must be bool (TRUE/FALSE).

e.g. counter > 5 OR level < 0 - conditional expression

1. An operator that takes two operands, i.e. +, -, * etc.

40 RAPID Developer’s Manual


RAPID Kernel Reference Manual Expressions

3.4 Literals
A literal is a lexical element (indivisible) that represents a constant value of a specific
data type.

<literal> ::= <num literal>


| <string literal>
| <bool literal>

e.g. 0.5, 1E2 - num literals


"limit" - string literal
TRUE - bool literal

3.5 Variables
Depending on the type and dimension of a variable it may be referenced in up to three
different ways. A variable reference may mean the entire variable, an element of a var-
iable (array) or a component of a variable (record).

<variable> ::=
<entire variable>
| <variable element>
| <variable component>

A variable reference denotes, depending on the context, either the value or the location
of the variable.

Entire Variable

An entire variable is referenced by the variable identifier.

<entire variable> ::= <ident>

If the variable is an array the reference denotes all elements. If the variable is a record
the reference denotes all components. Note that the placeholder <ID> (see 2.3) cannot
be used to represent an entire variable.

e.g. VAR num row{3};


VAR num column{3};
..
! array assignment
row := column;

RAPID Developer’s Manual 41


Expressions RAPID Kernel Reference Manual

Variable Element

An array variable element is referenced using the index number of the element.

<variable element> ::= <entire variable> ’{’ <index list> ’}’

<index list> ::= <expr> { ’,’ <expr> }

An index expression must represent an integer value (see ) greater than 0. Index value
1 selects the first element of an array. An index value may not violate the declared di-
mension. The number of elements in the index list must fit the declared degree (1, 2 or
3) of the array.

e.g. column{10} - reference of the tenth element of column

mat{i * 10, j} - reference of matrix element

Variable Component

A record variable component is referenced using the component name (names).

<variable component> ::= <variable> ’.’ <component name>

<component name> ::= <ident>

Note that the placeholder <ID> (see 2.3) cannot be used to represent a component
name.

e.g. home.y - referencing the Y component of


a pos variable

parr{i+2}.x - referencing the X component of an


element of a pos array

p1.trans.x - referencing a component (x) of another


component (trans)

3.6 Persistents
A persistent reference may mean the entire persistent, an element of a persistent (array)
or a component of a persistent (record).

<persistent> ::=
<entire persistent>
| <persistent element>
| <persistent component>

The rules concerning persistent references comply with the rules concerning variable
references (see , and respectively).

42 RAPID Developer’s Manual


RAPID Kernel Reference Manual Expressions

3.7 Constants
A constant reference may mean the entire constant, an element of a constant (array) or
a component of a constant (record).

<constant> ::=
<entire constant>
| <constant element>
| <constant component>

The rules concerning constant references comply with the rules concerning variable
references (see , and respectively).

3.8 Parameters
A parameter reference may mean the entire parameter, an element of a parameter (ar-
ray) or a component of a parameter (record).

<parameter> ::=
<entire parameter>
| <parameter element>
| <parameter component>

The rules concerning parameter references comply with the rules concerning variable
references (see , and respectively).

3.9 Aggregates
An aggregate denotes a composite value, i.e. an array or record value. Each aggregate
member is specified by an expression.

<aggregate> ::= ’[’ <expr> { ’,’ <expr> } ’]’

e.g. [x, y, 2*x] -- pos aggregate


["john", "eric", "lisa"] -- string array aggregate
[[ 100, 100, 0 ], [ 0, 0, z ]] -- pos array aggregate
[[1, 2, 3], [a, b, c]] -- num matrix (2*3) aggregate

The data type of an aggregate is (must be able to be) determined by the context. The
data type of each aggregate member must be equal to the type of the corresponding
member of the determined type.

e.g. VAR pos p1;


p1 := [1, -100, 12]; -- Aggregate type pos - determined by p1

IF [1,-100,12] = [a,b,b] THEN -- Illegal since the data type of neither of


the aggregates can be determined by
the context

RAPID Developer’s Manual 43


Expressions RAPID Kernel Reference Manual

3.10 Function calls


A function call initiates the evaluation of a specific function and receives the value re-
turned by the function. Functions can be either predefined or user defined.

<function call> ::= <function> ’(’ [ <function argument list> ] ’)’


<function> ::= <ident>

The arguments of a function call is used to transfer data to (and possibly from) the
called function. Arguments are evaluated from left to right. The data type of an argu-
ment must be equal to the type of the corresponding parameter (see 5.1) of the function.
An argument may be either required, optional or conditional. Optional arguments may
be omitted but the order of the (present) arguments must be the same as the order of the
parameters. Two or more parameters may be declared to mutually exclude each other,
in which case at most one of them may be present in the argument list. Conditional ar-
guments are used to support smooth propagation of optional arguments through chains
of routine calls.

<function argument list> ::=


<first function argument> { <function argument> }
<first function argument> ::=
<required function argument>
| <optional function argument>
| <conditional function argument>

<function argument> ::=


’,’ <required function argument>
| <optional function argument>
| ’,’ <optional function argument>
| <conditional function argument>
| ’,’ <conditional function argument>
<required function argument> ::=
[ <ident> ’:=’ ] <expr>
<optional function argument> ::=
’\’ <ident> [ ’:=’ <expr>]
<conditional function argument> ::=
’\’ <ident> ’?’ <parameter>

A required argument is separated from a preceding (if any) argument by ",". The param-
eter name may be included, or left out.

e.g. polar(3.937, 0.785398) - two required arguments

polar(dist := 3.937, angle := 0.785398) - .. using names

An optional or conditional argument is preceded by ’\’ and the parameter name. The
specification of the parameter name is mandatory. Switch (See 5.1) type arguments are
somewhat special; they are used only to signal presence (of an argument). Switch ar-
guments do therefore not include any argument expression. Switch arguments may be
propagated using the conditional syntax.

44 RAPID Developer’s Manual


RAPID Kernel Reference Manual Expressions

e.g. cosine(45) - one required argument


cosine(0.785398\rad) - .. and one switch (optional)
dist(pnt:=p2) - one required argument
dist(\base:=p1, pnt:=p2) - .. and one optional

A conditional argument is considered to be "present" if the specified optional parame-


ter (of the calling function) is present (see 5.1), otherwise it is simply considered to be
"omitted". Note that the specified parameter must be optional.

e.g. distance := dist(\base ? b, p);

.. is interpreted as

distance := dist(\base := b, p);

.. if the optional parameter b is present otherwise as

distance := dist( p);

The concept of conditional arguments thus eliminates the need for multiple "versions"
of routine calls when dealing with propagation of optional parameters.

e.g. IF Present(b) THEN


distance := dist(\base:=b, p);
ELSE
distance := dist(p);
ENDIF

More than one conditional argument may be used to match more than one alternative
of mutually excluding parameters (see 5.1). In that case at most one of them may be
"present" (may refer a present optional parameter).

e.g. The function

FUNC bool check (\switch on | switch off, ...

.. thus may be called as

check(\on ? high \ off ? low, ...

.. if at most one of the optional parameters ’high’ and ’low’ are


present.

The parameter list (see 5.1) of a function assigns each parameter an access mode. The
access mode of a parameter puts restrictions on a corresponding argument and speci-
fies how RAPID transfers the argument. Please refer to 5 for the full description on
routine parameters, access modes and argument restrictions.

RAPID Developer’s Manual 45


Expressions RAPID Kernel Reference Manual

3.11 Operators
The tables below view the available operators divided into 4 classes:

- Multiplying operators
- Adding operators
- Relational operators
- Logical operators

The tables specify the legal operand types and the result type of each operator. Note
that the relational operators = and <> are the only operators valid for arrays. The use of
operators in combination with operands of types not equal to (see 2.17) the types spec-
ified below will cause a type error (see 1.4).

Multiplication Operators

Operator Operation Operand types Result type


* multiplication num * num num 1)
* scalar vector multiplication num * pos or pos * num pos
* vector product pos * pos pos
* linking of rotations orient * orient orient
/ division num / num num
div integer division num 2) div num 2) num
mod (integer) modulo num 2) mod num 3) num

1) Preserves integer (exact) representation (see ) as long as operands and result are kept within the integer subdomain of the num type.
2) Must represent an integer (see ) value.
3) Must represent a positive (≥ 0) integer value.

Addition Operators

Operator Operation Operand types Result type


+ addition num + num num 2)
+ unary plus ; keep sign +num or +pos same 1) 2)
+ vector addition pos + pos pos
+ string concatenation string + string string
- subtraction num - num num 2)
- unary minus ; change sign -num or -pos same 1) 2)
- vector subtraction pos - pos pos

1) The result receives the same data type as the operand. If the operand has an alias data type (see 2.15) the result receives the alias "base"
type (num or pos).
2) Preserves integer (exact) representation (see ) as long as operands and result are kept within the integer subdomain of the num type.

46 RAPID Developer’s Manual


RAPID Kernel Reference Manual Expressions

Relational Operators

Operator Operation Operand types Result type


< less than num < num bool
<= less than or equal to num <= num bool
= equal to anytype 1) = anytype 1) bool
>= greater than or equal to num >= num bool
> greater than num > num bool
<> not equal to anytype 1) <> anytype 1) bool

1) Only value and semivalue data types (see 2.16). Operands must have equal types.

Logical Operators

Operator Operation Operand types Result type


and and bool and bool bool
xor exclusive or bool xor bool bool
or or bool or bool bool
not unary not - negation not bool bool

RAPID Developer’s Manual 47


Expressions RAPID Kernel Reference Manual

48 RAPID Developer’s Manual


RAPID Kernel Reference Manual Statements

4 Statements
The concept of using installed routines (and types) to support the specific needs of the
IRB application programmer has made it possible to limit the number of RAPID state-
ments to a minimum. The RAPID statements support general programming needs and
there are really no IRB specific RAPID statements. Statements may only occur inside
a routine definition.

<statement> ::=
<simple statement>
| <compound statement>
| <label>
| <comment>
| <SMT>

A statement is either simple or compound. A compound statement may in turn contain


other statements. A label is a "no operation" statement that can be used to define named
(goto-) positions in a program. The placeholder <SMT> can be used to represent a
statement.

<simple statement> ::=


<assignment statement>
| <procedure call>
| <goto statement>
| <return statement>
| <raise statement>
| <exit statement>
| <retry statement>
| <trynext statement>
| <connect statement>
<compound statement> ::=
<if statement>
| <compact if statement>
| <for statement>
| <while statement>
| <test statement>

4.1 Statement Termination


Compound statements (except for the compact if statement) are terminated by state-
ment specific keywords. Simple statements are terminated by a semicolon (;). Labels
are terminated by a colon (:). Comments are terminated by a newline character (see
2.10). Statement terminators are considered to be a part of the statement.

e.g. WHILE index < 100 DO


.
! Loop start - newline terminates a comment
next: - ":" terminates a label
index := index + 1; - ";" terminates assignment statement
ENDWHILE - "endwhile" terminates the while
statement

RAPID Developer’s Manual 49


Statements RAPID Kernel Reference Manual

4.2 Statement Lists


A sequence of zero or more statements is called a statement list. The statements of a
statement list are executed in succession unless a goto, return, raise, exit, retry or tryn-
ext statement, or the occurrence of an interrupt or error causes the execution to continue
at another point.

<statement list> ::= { <statement> }

Both routines and compound statements contain statement lists. There are no specific
statement list separators. The beginning and end of a statement list is determined by the
context.

e.g. IF a > b THEN


pos1 := a * pos2; - start of statement list
...
! this is a comment
pos2 := home; - end of statement list
ENDIF

4.3 Label Statement


Labels are "no operation" statements used to define named program positions. The goto
statement (see 4.6) causes the execution to continue at the position of a label.

<label> ::= <identifier> ’:’

e.g. next:
..
GOTO next;

The following scope rules are valid for labels:

- The scope of a label comprises the routine in which it is contained.


- Within its scope a label hides any predefined or user defined object with the
same name.
- Two labels declared in the same routine may not have the same name.
- A label may not have the same name as a routine data object declared in the
same routine.

50 RAPID Developer’s Manual


RAPID Kernel Reference Manual Statements

4.4 Assignment Statement


The assignment statement is used to replace the current value of a variable, persistent
or parameter (assignment target) with the value defined by an expression. The assign-
ment target and the expression must have equal types. Note that the assignment target
must have value or semivalue data type (see 2.16). The assignment target can be rep-
resented by the placeholder <VAR>.

<assignment statement> ::= <assignment target> ’:=’ <expression> ’;’


<assignment target> ::=
<variable>
| <persistent>
| <parameter>
| <VAR>

e.g. count := count +1; - entire variable assignment


home.x := x * sin(30); - component assignment
matrix{i, j} := temp; - array element assignment
posarr{i}.y := x; - array element/component assign-
ment
<VAR> := temp + 5; - placeholder use

4.5 Procedure Call


A procedure call initiates the evaluation of a procedure. After the termination of the
procedure the evaluation continues with the subsequent statement. Procedures can be
either predefined or user defined. The placeholder <ARG> may be used to represent
an undefined argument.

<procedure call> ::= <procedure> [ <procedure argument list> ] ’;’


<procedure> ::=
<identifier>
| ’%’ <expression> ’%’
<procedure argument list> ::=
<first procedure argument> { <procedure argument> }
<first procedure argument> ::=
<required procedure argument>
| <optional procedure argument>
| <conditional procedure argument>
| <ARG>
<procedure argument> ::=
’,’ <required procedure argument>
| <optional procedure argument>
| ’,’ <optional procedure argument>
| <conditional procedure argument>
| ’,’ <conditional procedure argument>
| ’,’ <ARG>
<required procedure argument> ::=
[ <identifier> ’:=’ ] <expression>

RAPID Developer’s Manual 51


Statements RAPID Kernel Reference Manual

<optional procedure argument> ::=


’\’ <identifier> [ ’:=’ <expression> ]
<conditional procedure argument> ::=
’\’ <identifier> ’?’ ( <parameter> | <VAR> )

The procedure (name) may either be statically specified by using an identifier (early
binding) or evaluated during runtime from a (string type) expression (late binding).
Even though early binding should be considered to be the "normal" procedure call
form, late binding sometimes provides very efficient and compact code.

e.g. ! early binding


test product_id
case 1:
proc1 x, y, z;
case 2:
proc2 x, y, z;
case 3:
...

! same example using late binding


% "proc" + NumToStr(product_id, 0) % x, y, z;
...

! same example again using another variant of late binding


VAR string procname {3} := ["proc1", "proc2", "proc3"];
...
% procname{product_id} % x, y, z;
...

Note that late binding is available for procedure calls only, not for function calls.

The general rules concerning the argument list of the procedure call are exactly the
same as those of the function call. Please refer to 3.10 and 5 for more details.

e.g. move t1, pos2, mv; .. procedure call

move tool := t1, dest := pos2, movedata := mv;.. with names

move \reltool, t1, dest, mv; .. with switch ’reltool’

move \reltool, t1, dest, mv \speed := 100; .. with optional speed’

move \reltool, t1, dest, mv \time := 20; .. with optional ’time’

Normally the procedure reference is solved (bind) according to the normal scope
rules, but late binding provide a way to do a deviation from that rule.

The string expression in the statement %<expression>% is in the normal case a string
with the name of a procedure found according to the scope rules, but the string could
also have an enclosing description prefix that specify the location of the routine.

52 RAPID Developer’s Manual


RAPID Kernel Reference Manual Statements

"name1:name2" specify the procedure "name2" inside the module "name1" (note that
the procedure "name2" could be declared local in that module). ":name2" specify the
global procedure "name2" in one of the task modules, this is very useful when a down-
wards call must be done from the system level (installed built in object).

4.6 Goto Statement


The goto statement causes the execution to continue at the position of a label.

<goto statement> ::= GOTO <identifier> ’;’

A goto statement may not transfer control into a statement list.

e.g. next:
i := i + 1;
..
GOTO next;

4.7 Return Statement


The return statement terminates the execution of a routine and, if applicable, specifies
a return value. A routine may contain an arbitrary number of return statements. A re-
turn statement can occur anywhere in the statement list or the error or backward han-
dler of the routine and at any level of a compound statement. The execution of a return
statement in the entry (see 9) routine of a task terminates the evaluation of the task. The
execution of a return statement in a trap (see 8.3) routine resumes execution at the point
of the interrupt.

<return statement> ::= RETURN [ <expression> ] ’;’

The expression type must be equal to the type of the function. Return statements in pro-
cedures and traps must not include the return expression.

e.g. FUNC num abs_value (num value)


IF value < 0 THEN
RETURN -value;
ELSE
RETURN value;
ENDIF
ENDFUNC

PROC message ( string mess )


write printer, mess;
RETURN; - might have been left out
ENDPROC

RAPID Developer’s Manual 53


Statements RAPID Kernel Reference Manual

4.8 Raise Statement


The raise statement is used to explicitly raise or propagate an error.

<raise statement> ::= RAISE [ <error number> ] ’;’


<error number> ::= <expression>

A raise statement that includes an explicit error number raises an error with that
number. The error number (see 7) expression must represent an integer value (see ) in
the range from 1 to 90. A raise statement including an error number must not appear in
the error handler of a routine.

A raise statement with no error number may only occur in the error handler of a routine
and raises again (reraises) the same (current) error at the point of the call of the routine,
i.e. propagates the error. Since a trap routine can only be called by the system (as a re-
sponse to an interrupt), any propagation of an error from a trap routine is made to the
system error handler (see 7).

e.g. CONST errnum escape := 10;


...
RAISE escape; - recover from this position
...
ERROR
IF ERRNO = escape THEN
RETURN val2;
ENDIF
ENDFUNC

4.9 Exit Statement


The exit statement is used to immediately terminate the execution of a task.

<exit statement> ::= EXIT ’;’

Task termination using the exit statement, unlike returning from the entry routine of the
task, in addition prohibits any attempt from the system to automatically restart the task.

e.g. TEST state


CASE ready:
...
DEFAULT :
! illegal/unknown state - abort
write console, "Fatal error: illegal state";
EXIT;
ENDTEST

54 RAPID Developer’s Manual


RAPID Kernel Reference Manual Statements

4.10 Retry Statement


The retry statement is used to resume execution after an error, starting with (reexecut-
ing) the statement that caused the error.

<retry statement> ::= RETRY ’;’

The retry statement can only appear in the error handler of a routine.

e.g. ...
! open logfile
open \append, logfile, "temp.log";
...
ERROR
IF ERRNO = ERR_FILEACC THEN
! create missing file
create "temp.log";
! resume execution
RETRY;
ENDIF
! propagate "unexpected" error
RAISE;
ENDFUNC

4.11 Trynext Statement


The trynext statement is used to resume execution after an error, starting with the state-
ment following the statement that caused the error.

<trynext statement> ::= TRYNEXT ’;’

The trynext statement can only appear in the error handler of a routine.

e.g. ...
! Remove the logfile
delete logfile;
...
ERROR
IF ERRNO = ERR_FILEACC THEN
! Logfile already removed - Ignore
TRYNEXT;
ENDIF
! propagate "unexpected" error
RAISE;
ENDFUNC

RAPID Developer’s Manual 55


Statements RAPID Kernel Reference Manual

4.12 Connect Statement


The connect statement allocates an interrupt number, assigns it to a variable or param-
eter (connect target) and connects it to a trap routine. When (if) an interrupt with that
particular interrupt number later occurs the system responds to it by calling the con-
nected trap routine. The connect target can be represented by the placeholder <VAR>.

<connect statement> ::= CONNECT <connect target> WITH <trap> ’;’


<connect target> ::=
<variable>
| <parameter>
| <VAR>
<trap> ::= <identifier>

The connect target must have num (or alias for num) type and must be (or represent) a
module variable (not a routine variable). If a parameter is used as connect target it must
be a VAR or INOUT/VAR parameter - see 5.1). An allocated interrupt number cannot
be "disconnected" or connected with another trap routine. The same connect target may
not be associated with the same trap routine more than once. This means that the same
connect statement may not be executed more than once and that only one of two iden-
tical connect statements (same connect target and same trap routine) may be executed
during a session. Note though, that more than one interrupt number may be connected
with the same trap routine.

e.g. PROC main()


VAR intnum hp;
...
CONNECT hp WITH high_pressure;
...
ENDPROC

TRAP high_pressure
close_valve\fast;
RETURN;
ENDTRAP

4.13 If Statement
The if statement evaluates one or none of a number of statement lists, depending on the
value of one or more conditional expressions.

<if statement> ::=


IF <conditional expression> THEN <statement list>
{ELSEIF <conditional expression>
THEN <statement list> | <EIT> }
[ ELSE <statement list> ]
ENDIF

56 RAPID Developer’s Manual


RAPID Kernel Reference Manual Statements

The conditional expressions are evaluated in succession until one of them evaluates to
true. The corresponding statement list is then executed. If none of them evaluates to
true the (optional) else clause is executed. The placeholder <EIT> can be used to rep-
resent an undefined elseif clause.

e.g. IF counter > 100 THEN


counter := 100;
ELSEIF counter < 0 THEN
counter := 0;
ELSE
counter := counter + 1;
ENDIF

4.14 Compact If Statement


In addition to the general, structured if-statement presented above (4.13), RAPID pro-
vides an alternative, compact if statement. The compact if statement evaluates a single,
simple statement if a conditional expression evaluates to true.

<compact if statement> ::=


IF <conditional expression> ( <simple statement> | <SMT> )
The placeholder <SMT> can be used to represent an undefined simple statement.
e.g. IF ERRNO = escape1 GOTO next;

4.15 For Statement


The for statement repeats the evaluation of a statement list while a loop variable is in-
cremented (or decremented) within a specified range. An optional step clause makes it
possible to select the increment (or decrement) value.

The loop variable:

- is declared (with type num) by its appearance.


- has the scope of the statement list (do .. endfor).
- hides any other object with the same name.
- is readonly, i.e. cannot be updated by the statements of the for loop.
<for statement> ::=
FOR <loop variable> FROM <expression>
TO <expression> [ STEP <expression> ]
DO <statement list> ENDFOR
<loop variable> ::= <identifier>

Initially the from, to and step expressions are evaluated and their values are kept. They
are evaluated only once. The loop variable is initiated with the from value. If no step
value is specified it defaults to 1 (or -1 if the range is descending).

Before each new (not the first) loop, the loop variable is updated and the new value is
checked against the range. As soon as the value of the loop variable violates (is outside)
the range the execution continues with the subsequent statement.

RAPID Developer’s Manual 57


Statements RAPID Kernel Reference Manual

The from, to and step expressions must all have num (numeric) type.

e.g. FOR i FROM 10 TO 1 STEP -1 DO


a{i} := b{i};
ENDFOR

4.16 While Statement


The while statement repeats the evaluation of a statement list as long as the specified
conditional expression evaluates to true.

<while statement> ::=


WHILE <conditional expression> DO
<statement list> ENDWHILE

The conditional expression is evaluated and checked before each new loop. As soon as
it evaluates to false the execution continues with the subsequent statement.

e.g. WHILE a < b DO


...
a := a + 1;
ENDWHILE

4.17 Test Statement


The test statement evaluates one or none of a number of statement lists, depending on
the value of an expression.

<test statement> ::=


TEST <expression>
{ CASE <test value> { ’,’ <test value> } ’:’
<statement list> ) | <CSE> }
[ DEFAULT ’:’<statement list> ]
ENDTEST
<test value> ::= <expression>

Each statement list is preceded by a list of test values, specifying the values for which
that particular alternative is to be selected. The test expression can have any value or
semivalue data type (see 2.16). The type of a test value must be equal to the type of the
test expression. The execution of a test statement will choose one or no alternative. In
case more than one test value fits the test expression only the first is recognized. The
placeholder <CSE> can be used to represent an undefined case clause.

The optional default clause is evaluated if no case clause fits the expression.

e.g. TEST choice


CASE 1, 2, 3 :
pick number := choice;
CASE 4 :
stand_by;
DEFAULT:
write console, "Illegal choice";
ENDTEST

58 RAPID Developer’s Manual


RAPID Kernel Reference Manual Routine Declarations

5 Routine Declarations
A routine is a named carrier of executable code. A user routine is defined by an RAPID
routine declaration. A predefined routine is supplied by the system and is always avail-
able. There are three types of routines - procedures, functions and traps. A function re-
turns a value of a specific type and is used in expression context (see 3.10). A procedure
does not return any value and is used in statement context (see 4.5). Trap routines pro-
vide a means to respond to interrupts (see 8). A trap routine can be associated with a
specific interrupt (using the connect statement - see 4.12) and is then later automatically
executed if that particular interrupt occurs. A trap routine can never be explicitly called
from RAPID code. A routine declaration can be represented by the placeholder
<RDN>.

<routine declaration> ::=


[LOCAL] ( <procedure declaration>
| <function declaration>
| <trap declaration> )
| <comment>
| <RDN>

The declaration of a routine specifies its:

- Name
- Data Type (only valid for functions)
- Parameters (not for traps)
- Data Declarations and Statements (body)
- Backward Handler (only valid for procedures)
- Error Handler

Routine declarations may only occur in the last section of a module (see 9). Routine
declarations cannot be nested, i.e. it is not possible to declare a routine inside a routine
declaration.

The optional local directive of a routine declaration classifies a routine to be local, oth-
erwise it is global (see 5.2).

5.1 Parameter Declarations


The parameter list of a routine declaration specifies the arguments (actual parameters)
that must/can be supplied when the routine is called. Parameters are either required or
optional. An optional parameter may be omitted from the argument list of a routine call
(see 2.20). Two or more optional parameters may be declared to mutually exclude each
other, in which case at most one of them may be present in a routine call. An optional
parameter is said to be present if the routine call supplies a corresponding argument,
not present otherwise. The value of a not present, optional parameter may not be set or
used. The predefined function Present can be used to test the presence of an optional
parameter. The placeholders <PAR>, <ALT>, <DIM> can be used to represent unde-
fined parts of a parameter list.

RAPID Developer’s Manual 59


Routine Declarations RAPID Kernel Reference Manual

<parameter list> ::=


<first parameter declaration> { <next parameter declaration> }
<first parameter declaration> ::=
<parameter declaration>
| <optional parameter declaration>
| <PAR>
<next parameter declaration> ::=
’,’ <parameter declaration>
| <optional parameter declaration>
| ’,’<optional parameter declaration>
| ’,’ <PAR>
<optional parameter declaration> ::=
’\’ ( <parameter declaration> | <ALT> )
{ ’|’ ( <parameter declaration> | <ALT> ) }
<parameter declaration> ::=
[ VAR | PERS | INOUT ] <data type>
<identifier> [ ’{’ ( ’*’ { ’,’ ’*’ } ) | <DIM> ’}’ ]
| ’switch’ <identifier>

The data type of an argument must be equal to the data type of the corresponding pa-
rameter.

Each parameter has an access mode. Available access modes are in (default), var, pers,
inout and ref 1).The access mode specifies how RAPID transfers a corresponding argu-
ment to a parameter:

- An in parameter is initialized with the value of the argument (expression). The


parameter may be used (e.g. assigned a new value) as an ordinary routine vari-
able.
- A var, pers, inout or ref parameter is used as an alias for the argument (data
object). This means that any update of the parameter is also an update of the
argument.

1. RAPID routines cannot have ref parameters, only predefined routines can.

60 RAPID Developer’s Manual


RAPID Kernel Reference Manual Routine Declarations

The specified access mode of a parameter restricts a corresponding argument as:


Table 1

X Legal argument
--- Illegal argument Access mode
in var pers inout ref

constant X X

readonly variable 1 X X

variable X X X X
Argument

persistent X X X X

parameter:
in X X --- X X
var X X --- X X
pers X --- X X X
inout:
var X X --- 2 X X
pers X ---2 X X X

any other expression X --- --- --- ---

1. e.g. FOR loop variables (see 6.15), errno, intno (see C Appendix:).
2. Execution error (see 1.4).

e.g. ..., INOUT num temp, ... - inout parameter

The built-in routines ’IsPers’ and ’IsVar’ can be used to test if an inout parameter is an
alias for a variable or persistent argument.

The special type ’switch’ may (only) be assigned to optional parameters and provides
a means to use "switch arguments", i.e. arguments given only by their names (no val-
ues). The domain of the switch type is empty and no value can be transferred to a
switch parameter. The only way to use a switch parameter is to check its presence using
the predefined function Present, or to pass it as an argument in a routine call.

e.g. PROC glue ( \switch on | switch off, ... - switch parameters


...
IF Present(off ) THEN - check presence off
... optional parameter ’off’
ENDPROC

glue\off, pos2; - argument use

Arrays may be passed as arguments. The degree of an array argument must comply
with the degree of the corresponding parameter. The dimension of an array parameter
is "conformant" (marked by ’*’). The actual dimension is later bound by the dimension
of the corresponding argument of a routine call. A routine can determine the actual di-
mension of a parameter using the predefined function ’Dim’.

e.g. ... , VAR num pallet{*,*}, ... - num-matrix parameter

RAPID Developer’s Manual 61


Routine Declarations RAPID Kernel Reference Manual

5.2 Scope Rules


The scope of an object denotes the area in which the name is visible.

The scope of a predefined routine comprises any RAPID module.

The following scope rules are valid for user routines:

- The scope of a local user routine comprises the module in which it is contained.
- The scope of a global user routine in addition comprises any other module in
the task buffer.
- Within its scope a user routine hides any predefined object with the same name.
- Within its scope a local user routine hides any global module object with the
same name.
- Two module objects declared in the same module may not have the same name.
- Two global objects declared in two different modules in the task buffer may not
have the same name.
- A global user routine and a module may not share the same name.

The scope rules concerning parameters comply with the scope rules concerning routine
variables. Refer to 2.20 for information on routine variable scope.

Refer to 9 for information on task modules.

5.3 Procedure Declarations


A procedure declaration binds an identifier to a procedure definition.

<procedure declaration> ::=


PROC <procedure name>
’(’ [ <parameter list> ] ’)’
<data declaration list>
<statement list>
[ BACKWARD <statement list> ]
[ ERROR <statement list> ]
ENDPROC
<procedure name> ::= <identifier>
<data declaration list> ::= { <data declaration> }

Note that a data declaration list can include comments (see 2.10).

The evaluation of a procedure is either explicitly terminated by a return statement (see


4.7) or implicitly terminated by reaching the end (ENDPROC, BACKWARD or ER-
ROR) of the procedure.

62 RAPID Developer’s Manual


RAPID Kernel Reference Manual Routine Declarations

e.g. Multiply all elements of a num array by a factor:

PROC arrmul( VAR num array{*}, num factor)


FOR index FROM 1 TO Dim( array, 1 ) DO
array{index} := array{index} * factor;
ENDFOR
ENDPROC <-- implicit return

(the predefined ’Dim’ function returns the dimension of an array)

Procedures which are going to be used in late binding calls are treated as a special case.
I.e. the parameters for the procedures, which are called from the same late binding
statement, should be matching as regards optional/required parameters and mode, and
should also be of the same basic type. E.g. if the second parameter of one procedure is
required and declared as VAR num then the second parameter of other procedures,
which are called by the same late binding statement, should have a second parameter
which is a required VAR with basic type num. The procedures should also have the
same number of parameters. If there are mutually exclusive optional parameters, they
also have to be matching in the same sense.

5.4 Function Declarations


A function declaration binds an identifier to a function definition.

<function declaration> ::=


FUNC <data type>
<function name>
’(’ [ <parameter list> ] ’)’
<data declaration list>
<statement list>
[ ERROR <statement list> ]
ENDFUNC
<function name> ::= <identifier>

Functions can have (return) any value data type (including any available installed
type). A function cannot be dimensioned, i.e. a function cannot return an array value.

The evaluation of a function must be terminated by a return statement (see 4.7).

e.g. Return the length of a vector:

FUNC num veclen(pos vector)


RETURN sqrt(quad(vector.x) + quad(vector.y) + quad(vector.z));
ERROR
IF ERRNO = ERR_OVERFLOW THEN
RETURN maxnum;
ENDIF
! propagate "unexpected" error
RAISE;
ENDFUNC

RAPID Developer’s Manual 63


Routine Declarations RAPID Kernel Reference Manual

5.5 Trap Declarations


A trap declaration binds an identifier to a trap definition. A trap routine can be associ-
ated with an interrupt (number) by using the connect statement (see 4.12). Note that one
trap routine may be associated with many (or no) interrupts.

<trap declaration> ::=


TRAP <trap name>
<data declaration list>
<statement list>
[ ERROR <statement list> ]
ENDTRAP
<trap name> ::= <identifier>

The evaluation of the trap routine is explicitly terminated using the return statement
(see 4.7) or implicitly terminated by reaching the end (endtrap or error) of the trap rou-
tine. The execution continues at the point of the interrupt.

e.g. Respond to low pressure interrupt:

TRAP low_pressure
open_valve\slow;
! return to point of interrupt
RETURN;
ENDTRAP

e.g. Respond to high pressure interrupt:

TRAP high_pressure
close_valve\fast;
! return to point of interrupt
RETURN;
ENDTRAP

64 RAPID Developer’s Manual


RAPID Kernel Reference Manual Backward Execution

6 Backward Execution
RAPID supports stepwise, backward execution of statements. Backward execution is
very useful for debugging, test and adjustment purposes during RAPID program de-
velopment. RAPID procedures may contain a backward handler (statement list) that
defines the backward execution "behaviour" of the procedure (call).

The following general restrictions are valid for Backward execution:

- Only simple (not compound) statements can be executed backwards.


- It is not possible to step backwards out of a routine at the top of it’s statement
list (and reach the routine call).
- Simple statements have the following backward behaviour:
- Procedure calls (predefined or user defined) can have any backward behaviour
- take some action, do nothing or reject 1) the backward call. The behaviour is
defined by the procedure definition.
- The arguments of a procedure call being executed backwards are always (even
in case of reject) executed and transferred to the parameters of the procedure
exactly in the same way as is the case with forward execution. Argument
expressions (possibly including function calls) are always executed "forwards".
- Comments, labels, assignment statements and connect statements are executed
as "no operation" while all other simple statements rejects1) backward execu-
tion.
- 1) No support for backward step execution - no step is taken.

6.1 Backward Handlers


The backward behaviour of a user defined (RAPID) procedure is defined by the state-
ments of the optional backward handler (see 5.3). The backward handler is really a part
of the procedure and the scope of any routine data object (variable, constant, parameter
or label) also comprises the (if any) backward handler of the procedure.

e.g. PROC MoveTo ( robtarget p )


! store target in global "Rail Buffer"
rail{index} := p;
index := index+1;
MoveL .. p .. ;
BACKWARD
index := index-1;
MoveL .. rail{index-1} ..;
ENDPROC

The statements of the backward handler are executed (forwards) when the procedure
call is executed backwards:

RAPID Developer’s Manual 65


Backward Execution RAPID Kernel Reference Manual

Forward execution of procedure (call):


... PROC MoveTo( ..
... ...
MoveTo.. ...
... BACKWARD
... ...
...
ENDPROC
Backward execution of procedure (call):
... PROC MoveTo( ..
... . ...
MoveTo .. ...
... BACKWARD
... ...
...
ENDPROC

Statements in the backward or error handler of a routine may not be executed back-
wards. Function calls (and indeed trap "calls") are never executed backwards (and can-
not have a backward handler). Backward execution cannot be "nested", i.e. two state-
ments in a call chain may not simultaneously be executed backwards.

The following rules are valid for the backward execution of RAPID procedures:

- An RAPID procedure with no backward handler does not support backward


step execution and will reject any backward call.
- An RAPID procedure with an empty backward handler is executed as "no oper-
ation"
- Error recovery is not available for statements in the backward handler. Such
errors are always propagated to the system error handler. See 7.

66 RAPID Developer’s Manual


RAPID Kernel Reference Manual Error Recovery

7 Error Recovery
An execution error (see 1.4) is an abnormal situation, related to the execution of a spe-
cific piece of RAPID program code. An error makes further execution impossible (or
at least hazardous). "Overflow" and "division by zero" are examples of errors. Errors
are identified by their unique error number and are always recognized by the system.
The occurrence of an error causes suspension of the normal program execution and the
control is passed to an error handler. The concept of error handlers makes it possible
to respond to, and possibly recover from errors that arise during program execution. If
further execution is not possible, at least the error handler can assure that the task is giv-
en a graceful abortion.

7.1 Error Handlers


Any routine declaration may include an error handler. The error handler is really a part
of the routine and the scope of any routine data object (variable, constant, parameter or
label) also comprises the (if any) error handler of the routine. If an error occurs during
the evaluation of the routine the control is transferred to the statement list of its error
handler.

e.g. FUNC num safediv(num x, num y)


RETURN x / y;
ERROR
IF ERRNO = ERR_DIVZERO THEN
! return max numeric value
RETURN max_num;
ENDIF
ENDFUNC

The predefined (readonly) variable ERRNO contains the error number of the (most re-
cent) error and can be used by the error handler to identify the error. After necessary
actions have been taken the error handler can:

- Resume execution starting with the statement in which the error occurred. This
is made using the retry statement (see 4.10).
- Resume execution starting with the statement after the statement in which the
error occurred. This is made using the trynext statement (see 4.11).
- Return control to the caller of the routine by using the return statement (see 4.7).
If the routine is a function the return statement must specify an appropriate
return value.
- Propagate the error to the caller of the routine by using the raise statement (see
4.8) - "Since I‘m not familiar with this error it’s up to my caller to deal with it".

If an error occurs in a routine that does not contain an error handler or reaching the end
of the error handler (ENDFUNC, ENDPROC or ENDTRAP), the system error han-
dler is called. The system error handler just reports the error and stops the execution.

RAPID Developer’s Manual 67


Error Recovery RAPID Kernel Reference Manual

In a chain of routine calls, each routine may have its own error handler. If an error oc-
curs in a routine with an error handler, and the error is explicitly propagated using the
raise statement, the same error is raised again at the point of the call of the routine - the
error is propagated. If the top of the call chain (the entry routine of the task) is reached
without any error handler found or if reaching the end of any error handler within the
call chain, the system error handler is called. The system error handler just reports the
error and stops the execution. Since a trap routine can only be called by the system (as
a response to an interrupt), any propagation of an error from a trap routine is made to
the system error handler.

In addition to errors detected and raised by the system, a program can explicitly raise
errors using the raise statement (see 4.8). The facility can be used to recover from com-
plex situations. For example it can be used to escape from deeply nested code positions.
Error numbers in the range from 1 to 90 may be used.

e.g. CONST errnum escape1 := 10;


...
RAISE escape1;
...
ERROR
IF ERRNO = escape1 THEN
RETURN val2;
ENDIF
ENDFUNC

Note that it is not possible to recover from or respond to errors that occur within an error
handler or backward handler. Such errors are always propagated to the system error
handler.

68 RAPID Developer’s Manual


RAPID Kernel Reference Manual Interrupts

8 Interrupts
Interrupts are program defined events identified by interrupt numbers. An interrupt oc-
curs as a consequence of an interrupt condition turning true. Unlike errors, the occur-
rence of an interrupt is not directly related to (synchronous with) a specific code posi-
tion. The occurrence of an interrupt causes suspension of the normal program execu-
tion and the control is passed to a trap routine. Interrupt numbers are allocated and
connected (associated) with a trap routine using the connect statement (see 4.12). In-
terrupt conditions are defined and manipulated using predefined routines. A task may
define an arbitrary number of interrupts.

8.1 Interrupt Recognition and Response


Even though the system recognizes the occurrence of an interrupt immediately, the re-
sponse in the form of calling the corresponding trap routine can only take place at spe-
cific program positions, namely:

- at the entry of next (after interrupt recognition) statement (of any type).
- after the last statement of a statement list.
- any time during the execution of a waiting routine (e.g. WaitTime).

This means that, after the recognition of an interrupt, the normal program execution
always continues until one of these positions are reached. This normally results in a
delay of 5-120 ms between interrupt recognition and response, depending on what type
of movement is being performed at the time of the interrupt.

8.2 Interrupt Manipulation


Interrupt numbers are used to identify interrupts/interrupt conditions. Interrupt num-
bers are not just "any" numbers. They are "owned" by the system and must be allocated
and connected with a trap routine using the connect statement (see 4.12) before they
may be used to identify interrupts.

e.g. VAR intnum full;


...

CONNECT full WITH ftrap;

Interrupts are defined and manipulated using predefined routines. The definition of an
interrupt specifies an interrupt condition and associates it with an interrupt number.

e.g. ! define feeder interrupts


ISignalDI sig3, high, full;

An interrupt condition must be active to be watched by the system. Normally the def-
inition routine (e.g. ISignalDI) activates the interrupt but that is not always the case.
An active interrupt may in turn be deactivated again (and vice versa).

RAPID Developer’s Manual 69


Interrupts RAPID Kernel Reference Manual

e.g. ! deactivate empty


ISleep empty;

! activate empty again


IWatch empty;

The deletion of an interrupt deallocates the interrupt number and removes the interrupt
condition. It is not necessary to explicitly delete interrupts. Interrupts are automatically
deleted when the evaluation of a task is terminated.

e.g. ! delete empty


IDelete empty;

The raising of interrupts may be disabled and enabled. If interrupts are disabled any
interrupt that occurs is queued and raised first when interrupts are enabled again. Note
that the interrupt queue may contain more than one waiting interrupt. Queued interrupts
are raised in fifo order. Interrupts are always disabled during the evaluation of a trap
routine (see 8.3 below).

e.g. ! enable interrupts


IEnable;

! disable interrupts
IDisable;

8.3 Trap Routines


Trap routines provide a means to respond to interrupts. A trap routine is connected with
a particular interrupt number using the connect statement (see 4.12). If an interrupt oc-
curs, the control is immediately (see 8.1) transferred to it’s connected trap routine.

e.g. LOCAL VAR intnum empty;


LOCAL VAR intnum full;

PROC main()
...
! Connect feeder interrupts
CONNECT empty WITH ftrap;
CONNECT full WITH ftrap;
! define feeder interrupts
ISignalDI sig1, high, empty;
ISignalDI sig3, high, full;
...
ENDPROC

TRAP ftrap
TEST INTNO
CASE empty:
open_valve
CASE full:
close_valve;
ENDTEST
RETURN;
ENDTRAP
70 RAPID Developer’s Manual
RAPID Kernel Reference Manual Interrupts

More than one interrupt may be connected with the same trap routine. The predefined
(readonly) variable INTNO contains the interrupt number and can be used by a trap
routine to identify the interrupt. After necessary actions have been taken a trap routine
can be terminated using the return statement (see 4.7) or by reaching the end (endtrap
or error) of the trap routine. The execution continues at the point of the interrupt. Note
that interrupts are always disabled (see 8.2) during the evaluation of a trap routine.

Since a trap routine can only be called by the system (as a response to an interrupt),
any propagation of an error from a trap routine is made to the system error handler (see
7).

RAPID Developer’s Manual 71


Interrupts RAPID Kernel Reference Manual

72 RAPID Developer’s Manual


RAPID Kernel Reference Manual Task Modules

9 Task Modules
An RAPID application is called a task. A task is composed of a set of modules. A mod-
ule contains a set of type definitions, data and routine declarations. The task buffer is
used to host modules currently in use (execution, development) on a system. RAPID
program code in the task buffer may be loaded/stored from/to file oriented external de-
vices (normally disk files) either as separate modules or as a group of modules - a Task.

RAPID distinguishes between task modules and system modules. A task module is con-
sidered to be a part of the task/application while a system module is considered to be
a part of the “system”. System modules are automatically loaded to the task buffer dur-
ing system start-up and are aimed to (pre)define common, system specific data objects
(tools, weld data, move data ..), interfaces (printer, logfile ..) etc. System modules are
not included when a task is saved on a file. This means that any update made to a sys-
tem module will have impact on all existing (old) tasks currently in, or later loaded to
the task buffer. In any other sense there is no difference between task and system mod-
ules; they can have any content.

While small applications usually are contained in a single task module (besides the sys-
tem module/s), larger applications may have a "main" task module that in turn refer-
ences routines and/or data contained in one or more other, "library" task modules.
Task Buffer
Disk (ram, hard, floppy)
System Modules
system module
system module
system module
system module

Task Modules (Task)


module load/store
"main" module

task load/store
"Library" module
"Library" module
"Library" module
"Library" module

A "library" module may for example define the interface of a physical or logical object
(gripper, feeder, counter etc.) or contain geometry data generated from a CAD-system
or created on-line by digitizing (teach in).

One task module contains the entry procedure of the task. Running the task really
means that the entry routine is executed. Entry routines must be parameterless.

RAPID Developer’s Manual 73


Task Modules RAPID Kernel Reference Manual

9.1 Module Declarations


A module declaration specifies the name, attributes and body of a module. A module name
hides any predefined object with the same name. Two different modules may not share the
same name. A module and a global module object (type, data object or routine) may not
share the same name. Module attributes provide a means to modify some aspects of the
systems treatment of a module when it is loaded to the task buffer. The body of a module
declaration contains a sequence of data declarations followed by a sequence of routine
declarations.

<module declaration> ::=


MODULE <module name> [ <module attribute list> ]
<type definition list>
<data declaration list>
<routine declaration list>
ENDMODULE
<module name> ::= <identifier>
<module attribute list> ::= ’(’ <module attribute> { ’,’ <module attribute> } ’)’
<module attribute> ::=
SYSMODULE
| NOVIEW
| NOSTEPIN
| VIEWONLY
| READONLY
<routine declaration list> ::= { <routine declaration> }

<type definition list> ::= { <type definition> }

<data declaration list> ::= { <data declaration> }

The module attributes have the following meaning:

attribute if specified, the module ..

SYSMODULE .. is a system module, otherwise a task module


NOVIEW .. (it’s source code) cannot be viewed (only executed)
NOSTEPIN .. cannot be entered during stepwise execution
VIEWONLY .. cannot be modified.
READONLY .. cannot be modified, but the attribute can be removed.

An attribute may not be specified more than once. If present, attributes must be specified
in table order (see above). The specification of noview excludes nostepin, viewonly and
readonly (and vice versa). The specification of viewonly excludes readonly (and vice
versa).

74 RAPID Developer’s Manual


RAPID Kernel Reference Manual Task Modules

e.g. The following three modules could represent a (very simple)


task:

MODULE prog1(SYSMODULE, VIEWONLY)


PROC main()
! init weldlib
initweld;
FOR i FROM 1 TO Dim(posearr,1) DO
slow posearr{i};
ENDFOR
ENDPROC
PROC slow(pose p)
arcweld p \speed := 25;
ENDPROC
ENDMODULE

MODULE weldlib
LOCAL VAR welddata w1 := sysw1;
! weldlib init procedure
PROC initweld()
! override speed
w1.speed := 100;
ENDPROC
PROC arcweld(pose position \ num speed | num time)
...
ENDPROC
ENDMODULE

MODULE weldpath - (CAD) generated module


CONST pose posearr{768} := [
[[234.7, 1136.7, 10.2], [1, 0, 0, 0]],
...
[[77.2, 68.1, 554.7], [1, 0, 0, 0]]
];
ENDMODULE

RAPID Developer’s Manual 75


Task Modules RAPID Kernel Reference Manual

9.2 System Modules


System modules are used to (pre)define system specific data objects (tools, weld data,
move data ..), interfaces (printer, logfile ..) etc. Normally, system modules are automat-
ically loaded to the task buffer during system start-up.

e.g. MODULE sysun1(SYSMODULE)


! Provide predefined variables
VAR num n1 := 0;
VAR num n2 := 0;
VAR num n3 := 0;
VAR pos p1 := [0, 0, 0];
VAR pos p2 := [0, 0, 0]; ...
! Define channels - open in init function
VAR channel printer;
VAR channel logfile; ...
! Define standard tools
PERS pose bmtool := [...
! Define basic weld data records
PERS wdrec wd1 := [ ...
! Define basic move data records
PERS mvrec mv1 := [ ...
! Define home position - Sync. Pos. 3
PERS robtarget home := [ ...
! Init procedure
LOCAL PROC init()
Open\write, printer, "/dev/lpr";
Open\write, logfile, "/usr/pm2/log1"... ;
ENDPROC
ENDMODULE

The selection of system module/s is a part of system configuration.

76 RAPID Developer’s Manual


RAPID Kernel Reference Manual Syntax Summary

10 Syntax Summary
Each rule or group of rules are prefixed by a reference to the section where the rule is
introduced.

2.1: <character> ::= -- ISO 8859-1 --

<newline> ::= -- newline control character --

<tab> ::= -- tab control character --

<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

<hex digit> ::= <digit> | A | B | C | D | E | F | a | b | c | d | e | f

<letter> ::=
<upper case letter>
| <lower case letters>

<upper case letter> ::=


A|B|C|D|E|F|G|H|I|J
|K|L|M|N|O|P|Q|R|S|T
|U|V|W|X|Y|Z|À|Á|Â|Ã
|Ä|Å|Æ|Ç|È|É|Ê|Ë|Ì|Í
| Î | Ï | 1) | Ñ | Ò | Ó | Ô | Õ | Ö | Ø
| Ù | Ú | Û | Ü | 2) | 3) | ß

<lower case letter> ::=


a|b|c|d|e|f|g|h|i|j
|k|l|m|n|o|p|q|r|s|t
|u|v|w|x|y|z|ß|à|á|â|ã
|ä|å|æ|ç|è|é|ê|ë|ì|í
| î | ï | 1) | ñ | ò | ó | ô | õ | ö | ø
| ù | ú | û | ü | 2) | 3) | ÿ

1) Icelandic letter eth.


2) Letter Y with acute accent.
3) Icelandic letter thorn

2.3: <identifier> ::=


<ident>
| <ID>

<ident> ::= <letter> {<letter> | <digit> | ’_’}

2.5: <num literal> ::=


<integer> [ <exponent> ]
| <integer> ’.’ [ <integer> ] [ <exponent> ]
| [ <integer> ] ’.’ <integer> [ <exponent> ]

<integer> ::= <digit> {<digit>}

RAPID Developer’s Manual 77


Syntax Summary RAPID Kernel Reference Manual

<exponent> ::= (’E’ | ’e’) [’+’ | ’-’] <integer>

2.6: <bool literal> ::= TRUE | FALSE

2.7 <string literal> ::= ’"’ { <character> | <character code> } ’"’

<character code> ::= ’\’ <hex digit> <hex digit>

2.10: <comment> ::= ’!’ { <character> | <tab> } <newline>

2.11: <type definition> ::=


[LOCAL] ( <record definition>
| <alias defnition> )
| <comment>
| <DN>

<record definition> ::=


RECORD <identifier>
<record component list>
ENDRECORD

<record component list> ::=


<record component definition> |
<record component definition> <record component list>

<record component definition> ::=


<data type> <record component name> ’;’

<alias definition> ::=


ALIAS <data type> <identifier> ’;’

<data type> ::= <identifier>

2.18: <data declaration> ::=


[LOCAL] ( <variable declaration>
| <persistent declaration>
| <constant declaration> )
| <comment>
| <DDN>

2.22: <variable declaration> ::=


VAR <data type> <variable definition> ’;’

<variable definition> ::=


<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]
[ ’:=’ <constant expression> ]

<dim> ::= <constant expression>

2.22: <persistent declaration> ::=


PERS <data type> <persistent definition> ’;’

<persistent definition> ::=

78 RAPID Developer’s Manual


RAPID Kernel Reference Manual Syntax Summary

<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]


’:=’ <literal expression>

2.24: <constant declaration> ::=


CONST <data type> <constant definition> ’;’

<constant definition> ::=


<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]
’:=’ <constant expres-
sion>

<dim> ::= <constant expression>

3: <expression> ::=
<expr>
| <EXP>

<expr> ::= [ NOT ] <logical term> { ( OR | XOR ) <logical term> }

<logical term> ::= <relation> { AND <relation> }

<relation> ::= <simple expr> [ <relop> <simple expr> ]

<simple expr> ::= [ <addop> ] <term> { <addop> <term> }

<term> ::= <primary> { <mulop> <primary> }

<primary> ::=
<literal>
| <variable>
| <persistent>
| <constant>
| <parameter>
| <function call>
| <aggregate>
| ’(’ <expr> ’)’

<relop> ::= ’<’ | ’<=’ | ’=’ | ’>’ | ’>=’ | ’<>’

<addop> ::= ’+’ | ’-’

<mulop> ::= ’*’ | ’/’ | DIV | MOD

3.1: <constant expression> ::= <expression>

3.1 <literal expression> ::= <expression>

3.1: <conditional expression> ::= <expression>

3.4: <literal> ::= <num literal>


| <string literal>
| <bool literal>

3.5: <variable> ::=


| <entire variable>

RAPID Developer’s Manual 79


Syntax Summary RAPID Kernel Reference Manual

| <variable element>
| <variable component>

<entire variable> ::= <ident>

<variable element> ::= <entire variable> ’{’ <index list> ’}’

<index list> ::= <expr> { ’,’ <expr> }

<variable component> ::= <variable> ’.’ <component name>

<component name> ::= <ident>

3.6 <persistent> ::=


<entire persistent>
| <persistent element>
| <persistent component>

3.6 <constant> ::=


<entire constant>
| <constant element>
| <constant component>

3.8 <parameter> ::=


<entire parameter>
| <parameter element>
| <parameter component>

3.9: <aggregate> ::= ’[’ <expr> { ’,’ <expr> } ’]’

3.10: <function call> ::= <function> ’(’ [ <function argument list> ] ’)’

<function> ::= <identifier>

<function argument list> ::=


<first function argument> { <function argument>

<first function argument> ::=


<required function argument>
| <optional function argument>
| <conditional function argument>

<function argument> ::=


’,’ <required function argument>
| <optional function argument>
| ’,’ <optional function argument>
| <conditional function argument>
| ’,’ <conditional function argument>

<required function argument> ::= [ <ident> ’:=’ ] <expr>

<optional function argument> ::= ’\’ <ident> [ ’:=’ <expr> ]

<conditional function argument> ::=’\’ <ident> ’?’ <parameter>

80 RAPID Developer’s Manual


RAPID Kernel Reference Manual Syntax Summary

4: <statement> ::=
<simple statement>
| <compound statement>
| <label>
| <comment>
| <SMT>

<simple statement> ::=


<assignment statement>
| <procedure call>
| <goto statement>
| <return statement>
| <raise statement>
| <exit statement>
| <retry statement>
| <trynext statement>
| <connect statement>

<compound statement> ::=


<if statement>
| <compact if statement>
| <for statement>
| <while statement>
| <test statement>

4.2: <statement list> ::= { <statement> }

4.3: <label> ::= <identifier> ’:’

4.4: <assignment statement> ::= <assignment target> ’:=’ <expression> ’;’

<assignment target> ::=


<variable>
| <persistent>
| <parameter>
| <VAR>

4.5: <procedure call> ::= <procedure> [ <procedure argument list> ] ’;’

<procedure> ::=
<identifier>
| ’%’ <expression> ’%’

<procedure argument list> ::=


<first procedure argument> { <procedure argu-
ment> }

<first procedure argument> ::=


<required procedure argument>
| <optional procedure argument>
| <conditional procedure argument>
| <ARG>

RAPID Developer’s Manual 81


Syntax Summary RAPID Kernel Reference Manual

<procedure argument> ::=


’,’ <required procedure argument>
| <optional procedure argument>
| ’,’ <optional procedure argument>
| <conditional procedure argument>
| ’,’ <conditional procedure argument>
| ’,’ <ARG>

<required procedure argument> ::= [ <identifier> ’:=’ ] <expression>

<optional procedure argument> ::= ’\’ <identifier> [ ’:=’ <expression> ]

<conditional procedure argument> ::=


’\’ <identifier> ’?’ ( <parameter> | <VAR> )

4.6: <goto statement> ::= GOTO <identifier> ’;’

4.7: <return statement> ::= RETURN [ <expression> ] ’;’

4.8: <raise statement> ::= RAISE [ <error number> ] ’;’

<error number> ::= <expression>

4.9 <exit statement> ::= EXIT ’;’

4.10 <retry statement> ::= RETRY ’;’

4.11 <trynext statement> ::= TRYNEXT ’;’

4.12 <connect statement> ::= CONNECT <connect target> WITH


<trap> ’;’

<connect target> ::=


<variable>
| <parameter>
| <VAR>

<trap> ::= <identifier>

4.13: <if statement> ::=


IF <conditional expression> THEN <statement list>
{ ELSEIF <conditional expression>
THEN <statement list> | <EIT> }
[ ELSE <statement list> ]
ENDIF

4.13: <compact if statement> ::=


IF <conditional expression> ( <simple statement>
| <SMT> )

4.15: <for statement> ::=


FOR <loop variable> FROM <expression>
TO <expression> [ STEP <expression> ]

82 RAPID Developer’s Manual


RAPID Kernel Reference Manual Syntax Summary

DO <statement list> ENDFOR

<loop variable> ::= <identifier>

4.16: <while statement> ::=


WHILE <conditional expression> DO
<statement list> ENDWHILE

4.17: <test statement> ::=


TEST <expression>
{ CASE <test value> { ’,’ <test value> } ’:’
<statement list> ) | <CSE> }
[ DEFAULT ’:’<statement list> ]
ENDTEST

<test value> ::= <constant expression>

5: <routine declaration> ::=


[LOCAL] ( <procedure declaration>
| <function declaration>
| <trap declaration> )
| <comment>
| <RDN>

5.1 <parameter list> ::=


<first parameter declaration> { <next parameter
declaration> }

<first parameter declaration> ::=


<parameter declaration>
| <optional parameter declaration>
| <PAR>

<next parameter declaration> ::=


’,’ <parameter declaration>
| <optional parameter declaration>
| ’,’ <optional parameter declaration>
| ’,’ <PAR>

<optional parameter declaration> ::=


’\’ ( <parameter declaration> | <ALT> )
{ ’|’ ( <parameter declaration> |
<ALT> ) }

<parameter declaration> ::=


[ VAR | PERS | INOUT ] <data type>
<identifier> [ ’{’ ( ’*’ { ’,’ ’*’ } ) |
<DIM> ’}’ ]
| ’switch’ <identifier>

5.3 <procedure declaration> ::=


PROC <procedure name>
’(’ [ <parameter list> ] ’)’

RAPID Developer’s Manual 83


Syntax Summary RAPID Kernel Reference Manual

<data declaration list>


<statement list>
[ BACKWARD <statement list> ]
[ ERROR <statement list> ]
ENDPROC

<procedure name> ::= <identifier>

<data declaration list> ::= { <data declaration> }

5.4: <function declaration> ::=


FUNC <data type>
<function name>
’(’ [ <parameter list> ] ’)’
<data declaration list>
<statement list>
[ ERROR <statement list> ]
ENDFUNC

<function name> ::= <identifier>

5.5 <trap declaration> ::=


TRAP <trap name>
<data declaration list>
<statement list>
[ ERROR <statement list> ]
ENDTRAP

<trap name> ::= <identifier>

9.1: <module declaration> ::=


MODULE <module name> [ <module attriutelist>]
<type definition list>
<data declaration list>
<routine declaration list>
ENDMODULE

<module name> ::= <identifier>

<module attribute list> ::=


’(’ <module attribute> { ’,’ <module attribute> } ’)’

<module attribute> ::=


SYSMODULE
| NOVIEW
| NOSTEPIN
| VIEWONLY
| READONLY

<type definition list> ::= { <type definition> }

<routine declaration list> ::= { <routine declaration> }

84 RAPID Developer’s Manual


RAPID Kernel Reference Manual Built-in Routines

11 Built-in Routines
Dim

The dim function is used to get the size of an array (datobj). It returns the number of array
elements of the specified dimension.

FUNC num Dim (REF 1) anytype 2) datobj, num dimno)

legal dimno values : 1 -> select first array dimension


2 -> select second array dimension
3 -> select third array dimension

Present

The present function is used to test if the argument (datobj) is present (see 5.1). It returns
FALSE if datobj is a not present optional parameter, TRUE otherwise.

FUNC bool Present (REF 1) anytype 2) datobj)

Break

The break (breakpoint) procedure causes a temporary stop of program execution. Break is
used for RAPID program code debugging purposes.

PROC Break ()

IWatch

The iwatch procedure activates the specified interrupt (ino). The interrupt can later be deac-
tivated again using the isleep procedure.

PROC IWatch (VAR intnum ino)

ISleep

The isleep procedure deactivates the specified interrupt (ino). The interrupt can later be ac-
tivated again using the iwatch procedure.

PROC ISleep (VAR intnum ino)

IsPers

RAPID Developer’s Manual 85


Built-in Routines RAPID Kernel Reference Manual

The ispers function is used to test if a data object (datobj) is (or is an alias for) a persistent
(see 5.1). It returns TRUE in that case, FALSE otherwise.

FUNC bool IsPers (INOUT anytype 2) datobj)

IsVar

The isvar function is used to test if a data object (datobj) is (or is an alias for) a variable (see
5.1). It returns TRUE in that case, FALSE otherwise.

FUNC bool IsVar (INOUT anytype 2) datobj)


1) Refer to 3.10 for more information on the ref access mode. Note that RAPID routines cannot have REF parameters.

2) The argument can have any data type. Note that anytype is just a marker for this property and should not be confused with a “real”
data type. Also note that RAPID routines cannot be given anytype parameters.

86 RAPID Developer’s Manual


RAPID Kernel Reference Manual Built-in Data Objects

12 Built-in Data Objects

Object Name Object Kind Data Type Description

ERRNO variable*) errnum most recent error number

INTNO variable*) intnum most recent interrupt

ERR_ALRDYCNT constant errnum "variable and trap routine already connected"

ERR_ARGDUPCND constant errnum "duplicated present conditional argument"

ERR_ARGNOTPER constant errnum "argument is not a persistent reference"

ERR_ARGNOTVAR constant errnum "argument is not a variable reference"

ERR_CALLPROC constant errnum "procedure call error (syntax, not procedure) at run time
(late binding)"

ERR_CNTNOTVAR constant errnum "CONNECT target is not a variable reference"

ERR_DIVZERO constant errnum "division by zero"

ERR_EXCRTYMAX constant errnum "exceeded max. number of RETRYs"

ERR_EXECPHR constant errnum "cannot execute placeholder"

ERR_FNCNORET constant errnum "missing return value"

ERR_ILLDIM constant errnum "array dimension out of range"

ERR_ILLQUAT constant errnum "illegal orientation value"

ERR_ILLRAISE constant errnum "error number in RAISE out of range"

ERR_INOMAX constant errnum "no more interrupt number available"

ERR_MAXINTVAL constant errnum "integer value too large"

ERR_NEGARG constant errnum "negative argument not allowed"

ERR_NOTARR constant errnum "data object is not an array"

ERR_NOTEQDIM constant errnum "mixed array dimensions"

ERR_NOTINTVAL constant errnum "not integer value"

ERR_NOTPRES constant errnum "parameter not present"

ERR_OUTOFBND constant errnum "array index out of bounds"

ERR_REFUNKDAT constant errnum "reference to unknown entire data object"

ERR_REFUNKFUN constant errnum "reference to unknown function"

ERR_REFUNKPRC constant errnum "reference to unknown procedure at linking time or at run time
(late binding)"

ERR_REFUNKTRP constant errnum "reference to unknown trap"

ERR_STRTOOLNG constant errnum "string too long"

ERR_UNKINO constant errnum "unknown interrupt number"

*) Read only - can only be updated by the system - not by a RAPID program.

RAPID Developer’s Manual 87


Built-in Data Objects RAPID Kernel Reference Manual

88 RAPID Developer’s Manual


RAPID Kernel Reference Manual Built in objects

13 Built in objects
There are three groups of “Built in objects”: Language kernel reserved objects,
Installed objects and User installed objects.

- Language kernel reserved objects are part of the system and can’t be removed
(or lived out in the configuration). Objects in this group are the instruction
Present, the variables intno, errno and much more. The set of objects in this
group is the same for all tasks (multitasking) and installations.
- Most of the Installed objects are installed at the first system start (or each P-
start) by the internal system configuration and cant be removed (e.g. the
instructions MoveL, MoveJ ...). Data objects corresponding to iosignals and
mecunits are installed according to the user configuration at each system start.
- The last group user installed objects are objects that are defined in RAPID
modules and installed according to the user configuration at the first system
start or each P-start.

The objects could be any RAPID object, that is procedure, function, record, record
component, alias, const, var or pers. Object values of pers and var could be changed,
but not the code it self, because of that a modpos of a built in constant declared robtar-
get is not allowed.

The built in RAPID code could never be viewed.

13.1 Object scope


The scope of object denotes the area in which the object is visible. A built in object is
visible at all other levels in the task, if not the same object name is used for another
object at a level between the use of the reference and the built in level.

The table below show the order of scope levels lookup, for a object referred from dif-
ferent places:

RAPID Developer’s Manual 89


Built in objects RAPID Kernel Reference Manual

Table 2 Object search according to scope rules.

Scope level Global in the


Own module program (global
Own routine Built in objects
(local declared) declared in one
The object is used in a module)

routine declared in a user or system 1 2 3 4


module

data or routine declaration in a user 1 2 3


or system module

routine declared in a user installed 1 2 3


module

data or routine declaration in a user 1 2


installed module

installed object (only for system 1


developers)

There are ways to bind a reference in runtime to objects (not functions) outside its
scope. For data object see the “RAPID Reference Manual” SetDataSearch and for pro-
cedures use late binding with lookup, described in the “RAPID Kernel Reference Man-
ual” chapter “Procedure call”.

13.2 The value of a built in data object durability


The init value of a built in PERS or VAR object is set when the object is installed. It
could though be changed from the normal program. The object will always keep its lat-
est value even if the normal program is reset, erased or replaced. The only way to reinit
the object is to do a P-start or to change the configuration (then an automatic P-start
will be performed).

Note that a built in PERS object is not replacing its init value with its latest as a normal
PERS object do.

90 RAPID Developer’s Manual


RAPID Kernel Reference Manual Built in objects

13.3 The way to define user installed objects


The only way to install a user installed object is to define the object in a RAPID mod-
ule, create an new instance in the system parameter Task modules with the file path to
that module. The attribute Storage must then be set to Built in. (see system parameter,
type Controller). There are also an attribute for Task modules named TextResource
thats only valid for Built in objects, this make it possible to use national language or
site depended names in the RAPID code for identifiers, without changing the code
itself. In the normal case that attribute should not be changed, but for the advanced
users see “Text files” in this manual.

Note that all used references in a Built in module must be known to the system at the
time for that module installation.

RAPID Developer’s Manual 91


Built in objects RAPID Kernel Reference Manual

92 RAPID Developer’s Manual


RAPID Kernel Reference Manual Intertask objects

14 Intertask objects
There are two groups of Intertask objects : Normal persistent data object and Built in
shared object.

- A persistent data object is shared by all task where it is declared with the same
name and type. All declaration must specify an init value to the persistent
object, but only the first module installed or loaded with the declaration will use
it. The object will still exist even if one module where it is declared is removed
as long as that module isn’t the last declaration for that object. A persistent
object could only be of value type.
- A built in object could be configurated as shared for all tasks. This make it pos-
sible to save memory by reusing RAPID code for more than one task. Its also
the only way to share non-value and semi-value data object. (see Built in
objects in this manual). The object could be any RAPID object, that is proce-
dure, function, const ,var or pers.

This chapter will only handle the Built in shared objects.

14.1 Symbol levels


A symbol in RAPID could be found at different levels, in a routine, in a module (local),
in the program of one task (in one module and defined as global) or at the system level.
Built in objects are on the system level.

The system level is departed into two part, a shared part and a task part. Objects in the
task part are local to that task, but objects in the shared part is global to all task.

The shared part is only existing physical ones, and are a part of task 0 (the main task),
but existing logical in each task. A Built in shared object should be installed shared in
task 0.

Shared part
system level system level system level
Task part

global level global level global level Symbol


lookup
direction
module level module level module level

routine level routine level routine level

TASK 0 TASK 1 .......... TASK N

Figure 1 Symbol levels with a departed system level.

RAPID Developer’s Manual 93


Intertask objects RAPID Kernel Reference Manual

The symbol search will start from that position (level) where the object is referred and
then, if not found in nearest level above and so on. See the “Symbol lookup direction”
- arrow in Figure 1.

14.2 Data object handling


Even if the definition is shared for an data object the value of it could be local in the
task .That are the fact for the installed system variables errno, intno and all stack allo-
cated object (object defined in a routine). All other data object share the value with
other tasks. This fact will demand a careful manipulation and reading of those values.

If the object has an atomic type (num, bool ,,,) there are no problem. But if not, make
sure that the total object are read/manipulated without any interfering from another
task. E.g. if the object is of a record type and each component are assign one by one, a
reading (between the setting of two record component ) from another task will get an
inconsistent record.

Also remember that a routine could be called from more than one task at the same time
and therefore should be reentrant, that is use local stack allocated object (parameters
and data object declared in the routine).

14.3 The way to define Built in shared object


The only way to install a Built in shared object is to define the object in a RAPID mod-
ule, create an new instance of Task modules for task 0, in the system parameter with the
file path to the module. The attribute Storage must then be set to Built in, and the
attribute shared set to YES (see also system parameter type Controller).

94 RAPID Developer’s Manual


RAPID Kernel Reference Manual Text files

15 Text files
This is a most effective tool that should be used when the demand for the application
includes:

- National or Site depending names.


- Easily changeable texts, e.g. help and error texts (the customer should also be
able to handle these files)
- Memory saving, text strings in a Text file use a smaller amount of memory than
RAPID strings.

In a Text file you can use ASCII strings, with the help of an off-line editor, and fetch
them from the RAPID code. The RAPID code should not be changed in any way even
if the result from the execution may look totally different.

15.1 Syntax for a text file


The application programmer must build one (or serval) ASCII file(s), the “Text
file(s)”, that contains the strings for a text resource.

The “Text file” is organised as:

<text_resource>::

# <comment>
<index1>:
“<text_string>”

# <comment>
<index2>:
“<text_string>”
...

The parameters

<text_resource>

This name identifies the text resource. The name must end with “::”. If
the name does not exist in the system, the system will create a new text
resource, otherwise the indexes in the file will be added to a resource
that already exists. The application developer is responsible for ensur-
ing that one’s own resources do not crash with another application. A
good rule is to use the application name as a prefix to the resource name,
e.g. MYAPP_TXRES. The name of the resource must not exceed 80
characters. Do not use exclusively alphanumeric as the name to avoid a
collision with system resources.

RAPID Developer’s Manual 95


Text files RAPID Kernel Reference Manual

<index>

This number identifies the <text_string> in the text resource. This


number is application defined and it must end with a “:”

<text_string>

The text string starts on a new line and ends at the end of the line or, if
the text string must be formatted on several lines, the new line character
string “\n” must be inserted.

<comment>

A comment always starts on a new line and goes to the end of the line.
A comment is always preceded by “#”. The comment will not be loaded
into the system.

15.2 RAPID identifier


All kinds of RAPID identifier (routines, const, variables, parameters, records, record
components, alias, or persistents) can be connected to a text index instead of a hard
coded name, if the object is a “User Installed object” (see also chapter “Built in objects”
in this manual).

The RAPID identifier in the code should be defined as: <name>#<text index>#, where
the <name> is a hard coded name that could be used for references to the object as well
as the name found at the text index.

The text resource should be defined under system parameters for the module containing
the symbols that should be “Built in”.

The example below describes a complete site with configuration, text file, and a “Built
in” module. The example is a shell routine that handles a gripper with analog pressure.
The alternative name for the routine gripper in the example will be Claw. An example
of use could look like “Claw CLAWMAX;”.

96 RAPID Developer’s Manual


RAPID Kernel Reference Manual Text files

The module ram1disk:gripper.sys The text file

ALIAS num pressure#1#;


#This is the text file .......
CONST pressure GRIPPERMAX#2#; GRIPP_TXRES::
CONST pressure GRIPPEROFF#3#; # the type name pressure
1:
PROC gripper#10#(pressure press#11) clawstrain
SetAO ao_2,press; # the max and off constant
ENDPROC 2:
CLAWMAX
3:
CLAWOFF
# the instruction gripper
10:
Claw
# the parameter press in gripper
11:
strain

The configuration
CAB_TASK_MODULES:
-File ram1disk:gripper.sys -Task MAIN -Storage BUILTIN -Txres GRIPP_TXRES

Figure 2 The gripper example.

15.3 Retrieving text during program execution


It is also possible to retrieve a text string from the RAPID code. The functions TextGet
and TextTabGet are used for this, see the reference manual.

15.4 Loading text files


Please contact the nearest ABB Flexible Automation centre for more information.

RAPID Developer’s Manual 97


Text files RAPID Kernel Reference Manual

98 RAPID Developer’s Manual


RAPID Kernel Reference Manual Storage allocation for RAPID objects

16 Storage allocation for RAPID objects


All RAPID programs stored on diskette or RAM memory have ASCII format.
At loading of RAPID program from mass memory into the program memory (internal
format), the storage of the program needs about 4 times more memory space.

For memory optimize of RAPID programs, the storage allocation in program memory
(internal format in bytes) for some common instructions, datas etc. are specified below.
For other instructions or datas the storage allocation can be read from the operating
message 10040 after loading of a program or program module.

16.1 Module, routine, program flow and other basic instructions


Table 3 Storage allocation for module, routine, program flow and other basic instructions.

Storage in
Instruction or data
bytes

New empty module: MODULE module1 ... ENDMODULE 1296


New empty procedure without parameters: PROC proc1() ... ENDPROC 184
Procedure call without arguments: proc1; 24
Module numeric variable declaration: VAR num reg1; 152
Numeric assignment: reg1:=1; 52
Compact IF: IF reg1=1 proc1; 76
IF statement: IF reg1=1 THEN proc1; ELSE proc2; ENDIF 120
Waits a given amount of time: WaitTime 1; 60
Comments: ! No of chars 20+No
of chars
Module string constant declaration with 0-80 chars init string value: 320
CONST string string1 := “0-80 characters“;
Module string variable declaration with 0-80 chars init string value: 332
VAR string string1 := “0-80 characters“;
Module string variable declaration: VAR string string1; 232
String assignment: string1:= “0-80 characters”; 140
Write text on Teach Pendant: TPWrite “0-80 characters”; 148

RAPID Developer’s Manual 99


Storage allocation for RAPID objects RAPID Kernel Reference Manual

16.2 Move instructions


Table 4 Storage allocation for move instructions.

Storage in
Instruction or data
bytes

Module robtarget constant declaration: CONST robtarget p1 := [...]; 280


Robot linearly move: MoveL p1,v1000,z50,tool1; 168
Robot linearly move: MoveL *,v1000,z50,tool1; 236
Robot circular move: MoveC *,*,v1000,z50,tool1; 340

16.3 I/O instructions


Table 5 Storage allocation for I/O instructions.

Storage in
Instruction or data
bytes

Set digital output: Set do1; 60


Set digital output: SetDO do1,1; 96
Wait until one digital input is high: WaitDI di1,1; 96
Wait until two digital inputs are high: WaitUntil di1=1 AND di2=1; 144

100 RAPID Developer’s Manual


Data Type byte

byte Decimal values 0 - 255

Byte is used for decimal values (0 - 255) according to the range of a byte.

This data type is used in conjunction with instructions and functions that handle the bit
manipulations and convert features.

Description
Data of the type byte represents a decimal byte value.

Examples
CONST num parity_bit := 8;

VAR byte data1 := 130;

Definition of a variable data1 with a decimal value 130.

BitClear data1, parity_bit;

Bit number 8 (parity_bit) in the variable data1 will be set to 0, e.g. the content
of the variable data1 will be changed from 130 to 2 (decimal representation).

Error handling
If an argument of the type byte has a value that is not in the range between 0 and 255,
an error is returned on program execution.

Characteristics
Byte is an alias data type for num and consequently inherits its characteristics.

Related information
Described in:
Alias data types Basic Characteristics- Data Types
Bit functions RAPID Summary - Bit Functions

RAPID Developer’s Manual 101


byte Data Type

102 RAPID Developer’s Manual


Data Type Add

BitSet Set a specified bit in a byte data


BitSet is used to set a specified bit to 1 in a defined byte data.

Examples
CONST num parity_bit := 8;
VAR byte data1 := 2;

BitSet data1, parity_bit;

Bit number 8 (parity_bit) in the variable data1 will be set to 1, e.g. the content
of the variable data1 will be changed from 2 to 130 (decimal representation).
BitPos 8

BitPos 1

BitPos 8

BitPos 1
0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0

Bit position 8 has value 0. Bit position 8 is set to 1.

VAR byte data1 := 2; BitSet data1, parity_bit;


Content of data1 before BitSet ... : 2 Content of data1 after BitSet ... : 130

Figure 3 Bit manipulation of data type byte when using BitSet.

Arguments
BitSet BitData BitPos
BitData Data type: byte

The bit data, in decimal representation, to be changed.

BitPos (Bit Position) Data type: num

The bit position (1-8) in the BitData to be set to 1.

RAPID Developer’s Manual 103


Add Data Type

Limitations
The range for a data type byte is 0 - 255 decimal.

The bit position is valid from 1 - 8.

Syntax
BitSet
[ BitData’:=’ ] < var or pers (INOUT) of byte > ’,’
[ BitPos’:=’ ] < expression (IN) of num > ’;’

Related information
Described in:
Clear a specified bit in a byte data Instructions - BitClear
Check if a specified bit in a byte data is set Functions - BitCheck
Other bit functions RAPID Summary - Bit Functions

104 RAPID Developer’s Manual


Data Type Add

BitClear Clear a specified bit in a byte data


BitClear is used to clear (set to 0) a specified bit in a defined byte data.

Examples
CONST num parity_bit := 8;
VAR byte data1 := 130;

BitClear data1, parity_bit;

Bit number 8 (parity_bit) in the variable data1 will be set to 0, e.g. the content
of the variable data1 will be changed from 130 to 2 (decimal representation).
BitPos 8

BitPos 1

BitPos 8

BitPos 1
1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0

Bit position 8 has value 1. Bit position 8 is set to 0.

VAR byte data1 := 130; BitClear data1, parity_bit;


Content of data1 before BitClear ... : 130 Content of data1 after BitClear ... : 2

Figure 4 Bit manipulation of data type byte when using BitClear.

Arguments
BitClear BitData BitPos
BitData Data type: byte

The bit data, in decimal representation, to be changed.

BitPos (Bit Position) Data type: num

The bit position (1-8) in the BitData to be set to 0.

RAPID Developer’s Manual 105


Add Data Type

Limitations
The range for a data type byte is 0 - 255 decimal.

The bit position is valid from 1 - 8.

Syntax
BitClear
[ BitData’:=’ ] < var or pers (INOUT) of byte > ’,’
[ BitPos’:=’ ] < expression (IN) of num > ’;’

Related information
Described in:
Set a specified bit in a byte data Instructions - BitSet
Check if a specified bit in a byte data is set Functions - BitCheck
Other bit functions RAPID Summary - Bit Functions

106 RAPID Developer’s Manual


Data Type Pow

BitCheck Check if a specified bit in a


byte data is set
BitCheck is used to check if a specified bit in a defined byte data is set to 1.

Example
CONST num parity_bit := 8;
VAR byte data1 := 130;

IF BitCheck(data1, parity_bit) = TRUE THEN


...
ELSE
...
ENDIF

Bit number 8 (parity_bit) in the variable data1 will be checked, e.g. if the spec-
ified bit is set to 1 in the variable data1, this function will return TRUE.
BitPos 8

BitPos 1

1 0 0 0 0 0 1 0

Bit position 8 has value 1.

VAR byte data1 := 130;


Return value from BitCheck ... : TRUE

Figure 5 Bit check of data type byte.

Return value Data type: bool

TRUE if the specified bit is set to 1, FALSE if the specified bit is set to 0.

RAPID Developer’s Manual 107


Abs Data Type

Arguments
BitCheck (BitData BitPos)
BitData Data type: byte

The bit data, in decimal representation, to be checked.

BitPos (Bit Position) Data type: num

The bit position (1-8) in the BitData to be checked.

Limitations
The range for a data type byte is 0 - 255 decimal.

The bit position is valid from 1 - 8.

Syntax
BitCheck’(’
[BitData ’:=’] <expression (IN) of byte> ’,’
[BitPos ’:=’] <expression (IN) of num>
’)’ ’;’

A function with a return value of the data type bool.

Related information
Described in:
Set a specified bit in a byte data Instructions - BitSet
Clear a specified bit in a byte data Instructions - BitClear
Other bit functions RAPID Summary - Bit Functions

108 RAPID Developer’s Manual


Data Type Pow

BitAnd Logical bitwise AND - operation


on byte data
BitAnd is used to execute a logical bitwise AND - operation on data types byte.

Example
VAR byte data1 := 38;
VAR byte data2 := 34;
VAR byte data3;

data3 := BitAnd(data1, data2);

The logical bitwise AND - operation will be executed on the data1 and data2,
the result will be returned to data3 (decimal representation).
BitPos 8

BitPos 1

0 0 1 0 0 1 1 0 data1 : 38 dec.
AND

0 0 1 0 0 0 1 0 data2 : 34 dec.

0 0 1 0 0 0 1 0 data3 : 34 dec.

Figure 6 Logical bitwise AND - operation.

Return value Data type: byte

The result of the logical bitwise AND - operation in decimal representation.

RAPID Developer’s Manual 109


Pow Data Type

Arguments
BitAnd (BitData1 BitData2)
BitData1 Data type: byte

The bit data 1, in decimal representation.

BitData2 Data type: byte

The bit data 2, in decimal representation.

Limitations
The range for a data type byte is 0 - 255 decimal.

Syntax
BitAnd’(’
[BitData1 ’:=’] <expression (IN) of byte> ’,’
[BitData2 ’:=’] <expression (IN) of byte>
’)’ ’;’

A function with a return value of the data type byte.

Related information
Described in:
Logical bitwise OR - operation on byte data Functions - BitOr
Logical bitwise XOR - operation on byte data Functions - BitXOr
Logical bitwise NEGATION - operation on Functions - BitNeg
byte data
Other bit functions RAPID Summary - Bit Functions

110 RAPID Developer’s Manual


Data Type Pow

BitOr Logical bitwise OR - operation


on byte data
BitOr (Bit inclusive Or) is used to execute a logical bitwise Or- operation on data types
byte.

Example
VAR byte data1 := 39;
VAR byte data2 := 162;
VAR byte data3;

data3 := BitOr(data1, data2);

The logical bitwise OR - operation will be executed on the data1 and data2, the
result will be returned to data3 (decimal representation).
BitPos 8

BitPos 1

0 0 1 0 0 1 1 1 data1 : 39 dec.
OR

1 0 1 0 0 0 1 0 data2 : 162 dec.

1 0 1 0 0 1 1 1 data3 : 167 dec.

Figure 7 Logical bitwise OR - operation.

Return value Data type: byte

The result of the logical bitwise OR - operation in decimal representation.

RAPID Developer’s Manual 111


Pow Data Type

Arguments
BitOr (BitData1 BitData2)
BitData1 Data type: byte

The bit data 1, in decimal representation.

BitData2 Data type: byte

The bit data 2, in decimal representation.

Limitations
The range for a data type byte is 0 - 255 decimal.

Syntax
BitOr’(’
[BitData1 ’:=’] <expression (IN) of byte> ’,’
[BitData2 ’:=’] <expression (IN) of byte>
’)’ ’;’

A function with a return value of the data type byte.

Related information
Described in:
Logical bitwise AND - operation on byte data Functions - BitAnd
Logical bitwise XOR - operation on byte data Functions - BitXOr
Logical bitwise NEGATION - operation on Functions - BitNeg
byte data
Other bit functions RAPID Summary - Bit Functions

112 RAPID Developer’s Manual


Data Type Abs

BitXOr Logical bitwise XOR - operation


on byte data
BitXOr (Bit eXclusive Or) is used to execute a logical bitwise XOR - operation on data
types byte.

Example
VAR byte data1 := 39;
VAR byte data2 := 162;
VAR byte data3;

data3 := BitXOr(data1, data2);

The logical bitwise XOR - operation will be executed on the data1 and data2,
the result will be returned to data3 (decimal representation).
BitPos 8

BitPos 1

0 0 1 0 0 1 1 1 data1 : 39 dec.
XOR

1 0 1 0 0 0 1 0 data2 : 162 dec.

1 0 0 0 0 1 0 1 data3 : 133 dec.

Figure 8 Logical bitwise XOR - operation.

Return value Data type: byte

The result of the logical bitwise XOR - operation in decimal representation.

RAPID Developer’s Manual 113


Pow Data Type

Arguments
BitXOr (BitData1 BitData2)
BitData1 Data type: byte

The bit data 1, in decimal representation.

BitData2 Data type: byte

The bit data 2, in decimal representation.

Limitations
The range for a data type byte is 0 - 255 decimal.

Syntax
BitXOr’(’
[BitData1 ’:=’] <expression (IN) of byte> ’,’
[BitData2 ’:=’] <expression (IN) of byte>
’)’ ’;’

A function with a return value of the data type byte.

Related information
Described in:
Logical bitwise AND - operation on byte data Functions - BitAnd
Logical bitwise OR - operation on byte data Functions - BitOr
Logical bitwise NEGATION - operation on Functions - BitNeg
byte data
Other bit functions RAPID Summary - Bit Functions

114 RAPID Developer’s Manual


Data Type Pow

BitNeg Logical bitwise NEGATION - operation


on byte data
BitNeg (Bit Negation) is used to execute a logical bitwise NEGATION - operation
(one’s complement) on data types byte.

Example
VAR byte data1 := 38;
VAR byte data2;

data2 := BitNeg(data1);

The logical bitwise NEGATION - operation will be executed on the data1 and
the result will be returned to data2 (decimal representation).
BitPos 8

BitPos 1

BitPos 8

BitPos 1
BitNeg
0 0 1 0 0 1 1 0 1 1 0 1 1 0 0 1

data1 : 38 dec. data2 : 217 dec.

Figure 9 Logical bitwise NEGATION - operation.

Return value Data type: byte

The result of the logical bitwise NEGATION - operation in decimal representation.

Arguments
BitNeg (BitData)
BitData Data type: byte

The byte data, in decimal representation.

Limitations
The range for a data type byte is 0 - 255 decimal.

RAPID Developer’s Manual 115


Pow Data Type

Syntax
BitNeg’(’
[BitData ’:=’] <expression (IN) of byte>
’)’ ’;’

A function with a return value of the data type byte.

Related information
Described in:
Logical bitwise AND - operation on byte data Functions - BitAnd
Logical bitwise OR - operation on byte data Functions - BitOr
Logical bitwise XOR - operation on byte data Functions - BitXOr
Other bit functions RAPID Summary - Bit Functions

116 RAPID Developer’s Manual


Data Type Pow

BitLSh Logical bitwise LEFT SHIFT- operation


on byte data
BitLSh (Bit Left Shift) is used to execute a logical bitwise LEFT SHIFT- operation on
data types byte.

Example
VAR num left_shift := 3;
VAR byte data1 := 38;
VAR byte data2;

data2 := BitLSh(data1, left_shift);

The logical bitwise LEFT SHIFT- operation will be executed on the data1 with 3
(left_shift) steps of left shift and the result will be returned to data2 (decimal rep-
resentation).
BitPos 8

BitPos 1

BitPos 8

BitPos 1
BitLSh
0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 0

data1 : 38 dec. data2 : 48 dec.

Figure 10 Logical bitwise LEFT SHIFT- operation.

Return value Data type: byte

The result of the logical bitwise LEFT SHIFT- operation in decimal representation.

The right bit cells will be filled up with 0-bits.

RAPID Developer’s Manual 117


Pow Data Type

Arguments
BitLSh (BitData ShiftSteps)
BitData Data type: byte

The bit data, in decimal representation, to be shifted.

ShiftSteps Data type: num

Number of the logical shifts (1 - 8) to be executed.

Limitations
The range for a data type byte is 0 - 255 decimal.

The ShiftSteps argument is valid from 1 - 8 according to one byte.

Syntax
BitLSh’(’
[BitData ’:=’] <expression (IN) of byte> ’,’
[ShiftSteps ’:=’] <expression (IN) of num>
’)’ ’;’

A function with a return value of the data type byte.

Related information
Described in:
Logical bitwise RIGHT SHIFT - operation Functions - BitRSh
on byte data
Other bit functions RAPID Summary - Bit Functions

118 RAPID Developer’s Manual


Data Type Pow

BitRSh Logical bitwise RIGHT SHIFT- operation


on byte data
BitRSh (Bit Right Shift) is used to execute a logical bitwise RIGHT SHIFT- operation
on data types byte.

Example
VAR num right_shift := 3;
VAR byte data1 := 38;
VAR byte data2;

data2 := BitRSh(data1, right_shift);

The logical bitwise RIGHT SHIFT- operation will be executed on the data1 with
3 (right_shift) steps of right shift and the result will be returned to data2 (decimal
representation).
BitPos 8

BitPos 1

BitPos 8

BitPos 1
BitRSh
0 0 1 0 0 1 1 0 0 0 0 0 0 1 0 0

data1 : 38 dec. data2 : 4 dec.

Figure 11 Logical bitwise RIGHT SHIFT- operation.

Return value Data type: byte

The result of the logical bitwise RIGHT SHIFT- operation in decimal representation.

The left bit cells will be filled up with 0-bits.

RAPID Developer’s Manual 119


Pow Data Type

Arguments
BitRSh (BitData ShiftSteps)
BitData Data type: byte

The bit data, in decimal representation, to be shifted.

ShiftSteps Data type: num

Number of the logical shifts (1 - 8) to be executed.

Limitations
The range for a data type byte is 0 - 255 decimal.

The ShiftSteps argument is valid from 1 - 8 according to one byte.

Syntax
BitRSh’(’
[BitData ’:=’] <expression (IN) of byte> ’,’
[ShiftSteps ’:=’] <expression (IN) of num>
’)’ ’;’

A function with a return value of the data type byte.

Related information
Described in:
Logical bitwise LEFT SHIFT - operation Functions - BitLSh
on byte data
Other bit functions RAPID Summary - Bit Functions

120 RAPID Developer’s Manual


Data Types datapos

datapos Enclosing block for a data object

datapos is the enclosing block to a data object (internal system data) retrieved with the
function GetNextSym.

Description
Data of the type datapos contains information of where a certain object is defined in
the system. It is used for instructions GetDataVal and SetDataVal.

Example
VAR datapos block;
VAR string name;
VAR bool truevar:=TRUE;
...
SetDataSearch “bool” \Object:=”^my” \InMod:=”mymod”\LocalSym;
WHILE GetNextSym(name,block) DO
SetDataVal name\Block:=block,truevar;
ENDWHILE

This session will set all local bool data object that begin with my in the module
mymod to TRUE.

Characteristics
datapos is a non-value data type.

Related information
Described in:
Define a symbol set in a search session Instructions - SetDataSearch
Get next matching symbol Functions - GetNextSym
Get the value of a data object Instructions - GetDataVal
Set the value of a data object Instructions - SetDataVal
Set the value of many object Instructions - SetAllDataVal

RAPID Developer’s Manual 121


datapos Data Types

122 RAPID Developer’s Manual


Data Types SetDataSearch

SetDataSearch Define the symbol set in a search sequence


SetDataSearch is used together with GetNextSym to retrieve data objects from the sys-
tem.

Example
VAR datapos block;
VAR string name;
...
SetDataSearch “robtarget”\InTask;
WHILE GetNextSym(name,block \Recursive) DO

This session will find all robtarget’s object in the task.

Arguments
SetDataSearch Type [\TypeMod] [\Object] [\PersSym] [\VarSym]
[\ConstSym] [\InTask] | [\InMod] [\InRout]
[\GlobalSym] | [\LocalSym]
Type Data type: string

The data type name of the data objects to be retrieved.

[\TypeMod] (Type Module) Data type: string

The module name where the data type is defined, if using user defined data types.

[\Object] Data type: string

The default behaviour is to set all data object of the data type above, but this
option make it possible to name one or serval data objects with a regular expres-
sion.

A regular expression is a powerful mechanism to specify a grammar to match the


data object names. The string could consist of either ordinary characters or met-
acharacters.

Within a regular expression, all alphanumeric characters match themselves, that


is to say, the pattern “abc” will only match those data object names containing
the character sequence “abc” anywhere in them.

Most other characters also match themselves, but a small set are known as the
metacharacters. These are:

RAPID Developer’s Manual 123


SetDataSearch Data Types

Expression Meaning

^ The beginning of the data object name being compared.


$ The end of the data object name being compared.
. Any character.
[s] Any character in the non-empty set s, where s is a sequence of
characters. Ranges may be specified as c-c.
[^s] Any character not in the set s.
r* Zero or more occurrences of the regular expression r.
r+ One or more occurrences of the regular expression r.
r? Zero or one occurrence of the regular expression r.
(r) The regular expression r. Used for separate that regular
expression from another.
r | r’ The regular expressions r or r’.

The default behaviour is to accept any symbols, but if one or several of following
PersSym, VarSym or ConstSym is specified, only symbols that match the specification
is accepted:

[\PersSym] (Persistent Symbols) Data type: switch

Accept persistent variable (PERS) symbols.

[\VarSym] (Variable Symbols) Data type: switch

Accept variable (VAR) symbols.

[\ConstSym] (Constant Symbols) Data type: switch

Accept constant (CONST) symbols.

If no one of the flags \InTask or \InMod are specified, the search is started at system
level. The system level is the root to all other symbol definitions in the symbol tree. At
the system level all buildin symbols are located plus the handle to the task level. At the
task level all loaded global symbols are located plus the handle to the modules level.

If the \Recursive flag is set in GetNextSym, the search session will enter all loaded mod-
ules and routines below the system level.

[\InTask] (In Task) Data type: switch

Start the search at the task level. At the task level all loaded global symbols are
located plus the handle to the modules level.

If the \Recursive flag is set in GetNextSym, the search session will enter all loaded
modules and routines below the task level.

[\InMod] (In Module) Data type: string

Start the search at the specified module level. At the module level all loaded glo-
bal and local symbols declared in the specified module are located plus the handle
to the routines level.

124 RAPID Developer’s Manual


Data Types SetDataSearch

If the \Recursive flag is set in GetNextSym, the search session will enter all
loaded routines below the specified module level (declared in the specified mod-
ule).

[\InRout] (In Routine) Data type: string

Search only at the specified routine level.

The module name for the routine must be specified in the argument \InMod.

The default behaviour is to match both local and global module symbols, but if one of
following \GlobalSym or \LocalSym is specified, only symbols that match the specifi-
cation is accepted:

[\GlobalSym] (Global Symbols) Data type: switch

Skip local module symbols.

[\LocalSym] (Local Symbols) Data type: switch

Skip global module symbols.

Program Running
The instruction will fail if the specification for one of Type, TypeMod, InMod or InRout
is wrong.

If the system don’t have any matching objects the instruction will accept it and return
successfully, but the first GetNextSym will return FALSE.

Limitations
Array data objects can not be defined in the symbol search set and can not be find in a
search sequence.

For a semivalue data type, it is not possible to search for the associated value data
type. E.g. if searching for dionum no serach hit for signals signaldi and if searching for
num no search hit for signal signalgi or signalai.

RAPID Developer’s Manual 125


SetDataSearch Data Types

Syntax
SetDataSearch
[ Type ’:=’ ] < expression (IN) of string >
[’\’TypeMod ’:=’<expression (IN) of string>]
[’\’Object ’:=’<expression (IN) of string>]
[’\’PersSym ]
[’\’VarSym ]
[’\’ConstSym ]
[’\’InTask ] | [’\’InMod ’:=’<expression (IN) of string>]
[’\’InRout ’:=’<expression (IN) of string>]
[’\’GlobalSym ] | [’\’LocalSym] ’;’

Related information
Described in:
Get next matching symbol Functions - GetNextSym
Get the value of a data object Instructions - GetDataVal
Set the value of a data object Instructions - SetDataVal
Set the value of many data objects Instructions - SetAllDataVal
The related data type datapos Data Types - datapos

126 RAPID Developer’s Manual


Data Types GetNextSym

GetNextSym Get next matching symbol


GetNextSym (Get Next Symbol) is used together with SetDataSearch to retrieve data
objects from the system.

Example
VAR datapos block;
VAR string name;
VAR bool truevar:=TRUE;
...
SetDataSearch “bool” \Object:=”^my” \InMod:=”mymod”\LocalSym;
WHILE GetNextSym(name,block) DO
SetDataVal name\Block:=block,truevar;
ENDWHILE

This session will set all local bool data objects that begin with my in the module
mymod to TRUE.

Return value Data type: bool

TRUE if a new object has been retrived, the object name and its enclosed block is then
returned in its arguments.

FALSE if no more object match.

Arguments
GetNextSym Object Block [\Recursive]
Object Data type: string

Variable (VAR or PERS) to store the name of the data object that will be retrived.

Block Data type: datapos

The enclosed block to the object.

[\Recursive] Data type: switch

This will force the search to enter block below, eg if the serch session has begin
on the task level it will also search modules and routines below the task.

RAPID Developer’s Manual 127


GetNextSym Data Types

Syntax
GetNextSym
[ Object ’:=’ ] < variable or persistent (INOUT) of string > ’,’
[ Block ’:=’] <variable (VAR) of datapos>
[’\’Recursive ] ’;’

A function with a return value of the data type bool.

Related information
Described in:
Define a symbol set in a search session Instructions - SetDataSearch
Get the value of a data object Instructions - GetDataVal
Set the value of a data object Instructions - SetDataVal
Set the value of many data objects Instructions - SetAllDataVal
The related data type datapos Data Types - datapos

128 RAPID Developer’s Manual


Instructions GetDataVal

GetDataVal Get the value of a data object


GetDataVal (Get Data Value) makes it possible to get a value from a data object that
is specified with a string variable.

Example
VAR num value;
...
GetDataVal “reg”+ValToStr(ReadNum(mycom)),value;

This will get the value of a register, the number of which is received from the
serial channel mycom. The value will be stored in the variable value.

VAR datapos block;


VAR string name;
VAR num valuevar;
...
SetDataSearch “num” \Object:=”^my” \InMod:=”mymod”;
WHILE GetNextSym(name,block) DO
GetDataVal name\Block:=block,valuevar;
TPWrite name+" "\Num:=valuevar;
ENDWHILE

This session will print out all num variables that begin with my in the module
mymod with its value to the teach-pendant.

Arguments
GetDataVal Object [\Block] Value
Object Data type: string

The name of the data object.

[\Block ] Data type: datapos

The enclosed block to the data object. This can only be fetched with the
GetNextSym function.

If this argument is omitted, the value of the visible data object in the current pro-
gram execution scope will be fetched. No array data objects will be found.

Value Data type: anytype

Variable for storage of the get value. The data type must be the same as the data
type for the data object to find. The get value can be fetched from a constant, var-
iable or persistent, but must be stored in a variable.

RAPID Developers Manual 4-11


GetDataVal Instructions

Error handling
The system variable ERRNO is set to ERR_SYM_ACCESS if:

- the data object is non-existent


- the data object is routine data or routine parameter and not located in the current
active routine

The error can be handled in the error handler of the routine.

Limitations
Array data objects cannot be defined in the symbol search set and cannot be found in a
search sequence.

For a semivalue data type, it is not possible to search for the associated value data
type. E.g. if searching for dionum, no search hit for signals signaldi will be obtained
and if searching for num, no search hit for signals signalgi or signalai will be obtained.

Syntax
GetDataVal
[ Object ’:=’ ] < expression (IN) of string >
[’\’Block ’:=’<variable (VAR) of datapos>] ’,’
[ Value ’:=’ ] <variable (VAR) of anytype>]’;’

Related information
Described in:
Define a symbol set in a search session Instructions - SetDataSearch
Get next matching symbol Functions - GetNextSym
Set the value of a data object Instructions - SetDataVal
Set the value of many data objects Instructions - SetAllDataVal
The related data type datapos Data Types - datapos

4-12 RAPID Developers Manual


Instructions SetDataVal

SetDataVal Set the value of a data object


SetDataVal (Set Data Value) makes it possible to set a value for a data object that is
specified with a string variable.

Example
VAR num value:=3;
...
SetDataVal “reg”+ValToStr(ReadNum(mycom)),value;

This will set the value 3 to a register, the number of which is received from the
serial channel mycom.

VAR datapos block;


VAR string name;
VAR bool truevar:=TRUE;
...
SetDataSearch “bool” \Object:=”^my” \InMod:=”mymod”\LocalSym;
WHILE GetNextSym(name,block) DO
SetDataVal name\Block:=block,truevar;
ENDWHILE

This session will set all local bool that begin with my in the module
mymod to TRUE.

Arguments
SetDataVal Object [\Block] Value
Object Data type: string

The name of the data object.

[\Block] Data type: datapos

The enclosed block to the data object. This can only be fetched with the
GetNextSym function.

If this argument is omitted, the value of the visible data object in the current pro-
gram execution scope will be set. No array data objects will be found.

Value Data type: anytype

Variable which holds the new value to be set. The data type must be the same as
the data type for the data object to be set. The set value must be fetched from a
variable, but can be stored in a constant, variable or persistent.

RAPID Developers Manual 4-13


SetDataVal Instructions

Error handling
The system variable ERRNO is set to ERR_SYM_ACCESS if:

- the data object is non-existent


- the data object is read-only data
- the data object is routine data or routine parameter and not located in the current
active routine

The error can be handled in the error handler of the routine.

Limitations
Array data objects cannot be defined in the symbol search set and cannot be found in a
search sequence.

For a semivalue data type, it is not possible to search for the associated value data
type. E.g. if searching for dionum, no search hit for signals signaldi will be obtained
and if searching for num, no search hit for signals signalgi or signalai will be obtained.

Syntax
SetDataVal
[ Object ’:=’ ] < expression (IN) of string >
[’\’Block ’:=’<variable (VAR) of datapos>] ’,’
[ Value ’:=’ ] <variable (VAR) of anytype>]’;’

Related information
Described in:
Define a symbol set in a search session Instructions - SetDataSearch
Get next matching symbol Functions - GetNextSym
Get the value of a data object Instructions - GetDataVal
Set the value of many data objects Instructions - SetAllDataVal
The related data type datapos Data Types - datapos

4-14 RAPID Developers Manual


Data Types SetAllDataVal

SetAllDataVal Set a value to all data objects


in a defined set
SetAllDataVal (Set All Data Value) make it possible to set a new value to all data
objects of a certain type that match the given grammar.

Example
VAR mydata mydata0:=0;
...
SetAllDataVal "mydata"\TypeMod:="mytypes"\Hidden,mydata0;

This will set all data objects of data type mydata in the system to the same value
as the variable mydata0 has (in the example to 0). The user defined data type
mydata is defined in the module mytypes.

Arguments
SetAllDataVal Type [\TypeMod] [\Object] [\Hidden] Value
Type Data type: string

The type name of the data objects to be set.

[\TypeMod] (Type Module) Data type: string

The module name where the data type is defined, if using user defined data types.

[\Object] Data type: string

The default behaviour is to set all data object of the data type above, but this
option make it possible to name one or serval objects with a regular expression.
(see also SetDataSearch)

[\Hidden] Data type: switch

This match also data objects that are in routines (routine data or parameters) hid-
den by some routine in the call chain.

Value Data type: anytype

Variable which holds the new value to be set. The data type must be same as the
data type for the object to be set.

RAPID Developer’s Manual 133


SetAllDataVal Data Types

Program Running
The instruction will fail if the specification for Type or TypeMod is wrong.

If the matching data object is an array, all elements of the array will be set to the spec-
ified value.

If the matching data object is read-only data, the value will not be changed.

If the system don’t have any matching data objects the instruction will accept it and
return successfully.

Limitations
For a semivalue data type, it is not possible to search for the associated value data
type. E.g. if searching for dionum no serach hit for signals signaldi and if searching for
num no search hit for signal signalgi or signalai.

Syntax
SetAllDataVal
[ Type ’:=’ ] < expression (IN) of string >
[’\’TypeMod ’:=’<expression (IN) of string>]
[’\’Object ’:=’<expression (IN) of string>]
[’\’Hidden ] ’,’
[’\’Value ’:=’] <variable (VAR) of anytype>’;’

Related information
Described in:
Define a symbol set in a search session Instructions - SetDataSearch
Get next matching symbol Functions - GetNextSym
Get the value of a data object Instructions - GetDataVal
Set the value of a data object Instructions - SetDataVal
The related data type datapos Data Types - datapos

134 RAPID Developer’s Manual


Function AliasIO

AliasIO Define I/O signal with alias name


AliasIO is used to define a signal of any type with an alias name
or to use signals in built-in task modules.

Signals with alias names can be used for predefined generic programs, without any
modification of the program before running in different robot installations.

The instruction AliasIO must be run before any use of the actual signal. See example 1
below for loaded modules and example 2 below for builtin modules.

Example 1
VAR signaldo alias_do;

PROC prog_start()
AliasIO config_do, alias_do;
ENDPROC

The routine prog_start is connected to the START event in system parameters.


The program defined digital output signal alias_do is connected to the config-
ured digital output signal config_do at program start (start the program from
beginning).

Arguments
AliasIO FromSignal ToSignal
FromSignal Data type: signalxx or
string

Loaded modules:

The signal identifier named according to the configuration (data type signalxx)
from which the signal descriptor is copied. The signal must be defined in the IO
configuration.

Built-in modules:

A reference (CONST, VAR, PERS or parameter of these) containing the name of


the signal (data type string) from which the signal descriptor after search in the
system is copied. The signal must be defined in the IO configuration.

ToSignal Data type: signalxx

The signal identifier according to the program (data type signalxx) to which the
signal descriptor is copied. The signal must be declared in the RAPID program.

RAPID Developer’s Manual 135


AliasIO Function

The same data type must be used (or find) for the arguments FromSignal and ToSignal
and must be one of type signalxx (signalai, signalao, signaldi, signaldo, signalgi or sig-
nalgo).

Program execution
The signal descriptor value is copied from the signal given in argument FromSignal to
the signal given in argument ToSignal.

Example 2
VAR signaldi alias_di;

PROC prog_start()
CONST string config_string := "config_di";
AliasIO config_string, alias_di;
ENDPROC

The routine prog_start is connected to the START event in system parameters.


The program defined digital output signal alias_di is connected to the configured
digital output signal config_di (via constant config_string) at program start (start
the program from beginning).

Limitation
When starting the program, the alias signal cannot be used until the AliasIO instruction
is executed.

Instruction AliasIO must be placed in either the

- event routine executed at program start (event START) or


- program part executed after every program start (before use of the signal)

Instruction AliasIO is not available for programming from the Teach Pendant (only
from Program Maker). Option Developer’s Functions is required.

Syntax
AliasIO
[ FromSignal ’:=’ ] < reference (REF) of anytype> ’,’
[ ToSignal ’:=’ ] < variable (VAR) of anytype> ’;’

136 RAPID Developer’s Manual


Function AliasIO

Related information
Described in:
Input/Output instructions RAPID Summary -
Input and Output Signals
Input/Output functionality in general Motion and I/O Principles -
I/O Principles
Configuration of I/O User’s Guide - System Parameters
Defining event routines User’s Guide - System Parameters
Loaded/Built-in task modules User’s Guide - System Parameters

RAPID Developer’s Manual 137


AliasIO Function

138 RAPID Developer’s Manual


Function ArgName

ArgName Gets argument name


ArgName (Argument Name) is used to get the name of the original data object for the
current argument or the current data.

Example
VAR num chales :=5;
...
proc1 chales;

PROC proc1 (num par1)


VAR string name;
...
name:=ArgName(par1);
TPWrite "Argument name "+name+" with value "\Num:=par1;
ENDPROC

The variable name is assigned the string value "chales" and on TP the following
string is written: "Argument name charles with value 5".

Return value Data type: string

The original data object name.

Arguments
ArgName (Parameter)
Parameter Data type: anytype

The formal parameter identifier (for the routine in which ArgName is located) or
the data identity.

Program execution
The function returns the original data object name for an entire object of the type con-
stant, variable or persistent. The original data object can be global, local in the program
module or local in a routine (normal RAPID scope rules).

If it is a part of a data object, the name of the whole data object is returned.

RAPID Developer’s Manual 139


ArgName Function

Example

Convert from identifier to string

This function can also be used to convert from identifier to string, by stating the iden-
tifier in the argument Parameter for any data object with global, local in module or
local in routine scope:

VAR num chales :=5;


...
proc1;

PROC proc1 ()
VAR string name;
...
name:=ArgName(chales);
TPWrite "Global data object "+name+" has value "\Num:=chales;
ENDPROC

The variable name is assigned the string value "chales" and on TP the following
string is written: "Global data object chales has value 5".

Routine call in several steps

Note that the function returns the original data object name:

VAR num chales :=5;


...
proc1 chales;
...
PROC proc1 (num parameter1)
...
proc2 parameter1;
...
ENDPROC

PROC proc2 (num par1)


VAR string name;
...
name:=ArgName(par1);
TPWrite "Original data object name "+name+" with value "\Num:=par1;
ENDPROC

The variable name is assigned the string value "chales" and on TP the following
string is written: "Original data object name charles with value 5".

140 RAPID Developer’s Manual


Function ArgName

Error handling
If one of the following errors occurs, the system variable ERRNO is set to
ERR_ARGNAME:

- Argument is expression value


- Argument is not present
- Argument is of type switch

This error can then be handled in the error handler.

Syntax
ArgName ’(’
[ Parameter’:=’ ] < reference (REF) of any type> ’)’

A function with a return value of the data type string.

Related information
Described in:
String functions RAPID Summary - String Functions
Definition of string Data Types - string
String values Basic Characteristics -
Basic Elements

RAPID Developer’s Manual 141


ArgName Function

142 RAPID Developer’s Manual


Function BookErrNo

BookErrNo Book a RAPID system


error number
BookErrNo is used to book a new RAPID system error number.

Examples
! Introduce a new error number in a glue system
! Note: The new error variable must be declared with the initial value -1
VAR errnum ERR_GLUEFLOW := -1;

! Book the new RAPID system error number


BookErrNo ERR_GLUEFLOW;

The variable ERR_GLUEFLOW will be assigned to a free system error number


for use in the RAPID code.

! Use the new error number


IF di1 = 0 THEN
RAISE ERR_GLUEFLOW;
ELSE
...
ENDIF

! Error handling
ERROR
IF ERRNO = ERR_GLUEFLOW THEN
...
ELSE
...
ENDIF

If the digital input di1 is 0 the new booked error number will be raised and the
system error number ERRNO will be set to the new booked error number. The
error handling of those user generated errors can then be handled in the error han-
dler as usual.

Arguments
BookErrNo ErrorName
ErrorName Data type: errnum

The new RAPID system error variable name.

RAPID Developer’s Manual 143


BookErrNo Function

Limitations
The new error variable must be declared as a global one in the system.

The new error variable must be declared with an initial value of -1, that gives the
information that this error should be a RAPID system error.

Syntax
BookErrNo
[ ErrorName’:=’ ] < variable (VAR) of errnum > ’;’

Related information
Described in:

Error handling Basic Characteristics -


Error Recovery
Error number Data types - errnum
Call an error handler Instructions - RAISE

- New error numbers must be declared with -1 (fatal error)


- New error number variable must be declared as a global one
(fatal error)

(7) Additon information:


This function was introduced according to the RAPID-SHELL developer demands.

144 RAPID Developer’s Manual


Function TextTabGet

TextTabGet Get text table number


TextTabGet is used to get the text table number of a user defined text table during runt-
ime.

Example
A new text table named deburr_part1 for user defined texts. The new text table has the
file name deburr.eng.

deburr.eng

# deburr.eng - USERS deburr_part1 english text description file


#
# DESCRIPTION:
# Users text file for RAPID development
#
deburr_part1::
0:
RAPID S4: Users text table deburring part1
1:
Part 1 is not in pos
2:
Identity of worked part: XYZ
3:
Part error in line 1
#
# End of file

RAPID - Code

VAR num text_res_no;


VAR string user_text;
...
text_res_no := TextTabGet("deburr_part1");

The variable text_res_no is assigned the text table number for the definded text
table deburr_part1.

ErrWrite TextGet(text_res_no, 1), TextGet(text_res_no, 2);

A message is stored in the robot log. The message is also shown on the teach pen-
dant display. The messages will be taken from the text table deburr_part1 :
1: Part 1 is not in pos
2: Identity of worked part: XYZ

RAPID Developer’s Manual 145


TextTabGet Function

Return value Data type: num

The text table number of the defined text table.

Arguments
TextTabGet ( TableName )
TableName Data type: string

The text table name (a string with max. 16 characters).

Syntax
TextTabGet ’(’
[ TableName ’:=’ ] < expression (IN) of string > ’;’

A function with a return value of the data type num.

Related information
Described in:
Get text from system text tables Functions - TextGet
String functions RAPID Summary - String Functions
Definition of string Data Types - string
String values Basic Characteristics -
Basic Elements

146 RAPID Developer’s Manual


Function TextGet

TextGet Get text from system text tables


TextGet is used to get a text string from the system text tables (installed at cold start).

Example
VAR string text1;
...
text1 := TextGet(14, 5);

The variable text1 is assigned the text stored in text resource 14 and index 5.

Return value Data type: string

Specified text from the system text tables.

Arguments
TextGet ( Table Index )
Table Data type: num

The text table number (positive integer).

Index Data type: num

The index number (positive integer) within the text table.

Syntax
TextGet ’(’
[ Table ’:=’ ] < expression (IN) of num > ’,’
[ Index ’:=’ ] < expression (IN) of num > ’)’

A function with a return value of the data type string.

RAPID Developer’s Manual 147


TextGet Function

Related information
Described in:
Get text table number Functions - TextTabGet
String functions RAPID Summary - String Functions
Definition of string Data Types - string
String values Basic Characteristics -
Basic Elements

- Arguments only positive integer values (fatal error)


- Error tx_get (fatal error)

148 RAPID Developer’s Manual


Function IsSysId

IsSysId Test system identity


IsSysId (System Identity) can be used to test the system identity.

Example
IF NOT IsSysId("6400-1234") THEN
ErrWrite "System identity fault","Faulty system identity for this program";
EXIT;
ENDIF

The program is made for a special robot system and can’t be used of another one.

Return value Data type: bool

TRUE = The system identity is the same as specified in the test.

FALSE = The system identity is not the same as specified in the test.

Arguments
IsSysId ( SystemId)
SystemId Data type: string

The system identity.

Syntax
IsSysId ’(’
[ SystemId’:=’ ] < expression (IN) of string> ’)’

A function with a return value of the data type bool.

Related information
Described in:

Test if option is present Functions - IsOptId

RAPID Developer’s Manual 149


IsSysId Function

150 RAPID Developer’s Manual


Function SetSysData

SetSysData Set system data


SetSysData activates the specified system data name for the specified data type.

With this instruction it is possible to change the current active Tool or Work Object.

Example
SetSysData tool5;

The tool tool5 is activated.

SetSysData tool0 \ObjectName := “tool6”;

The tool tool6 is activated.

SetSysData anytool \ObjectName := “tool2”;

The tool tool2 is activated.

Arguments
SetSysData SourceObject [\ ObjectName ]
SourceObject Data type: anytype

Persistent, which name should be active as current system data name.

The data type of this argument also specifies the type of system data (Tool or
Work Object) to be activated.

The value of this argument is not affected.


The value of the current system data is not affected.

[\ObjectName] Data type: string

If this optional argument is specified, it specifies the name of the data object to
be active (overrides name specified in argument SourceObject). The data type of
the data object to be active is always fetched from the argument SourceObject.

Program execution
The current active system data object for the Tool or Work Object is set according to
the arguments.

Note that this instruction only activates a new data object (or the same as before) and
never changes the value of any data object.

RAPID Developer’s Manual 151


SetSysData Function

Syntax
SetSysData
[ SourceObject’:=’] < persistent(PERS) of anytype>
[’\’ObjectName’:=’ < expression(IN) of string> ] ’;’

Related information
Described in:
Definition of tools Data Types - tooldata
Definition of work objects Data Types - wobjdata
Get system data Instructions - GetSysData

152 RAPID Developer’s Manual


Function IsStopStateEvent

IsStopStateEvent Test whether moved PP


IsStopStateEvent returns information about the movement of the Program Pointer (PP).

Example
IF IsStopStateEvent (\PPMoved) = TRUE THEN
! PP has been moved during the last program stop
ELSE
! PP has not been moved during the last program stop
ENDIF

IF IsStopStateEvent (\PPToMain) THEN


! PP has been moved to main routine during the last program stop
ENDIF

Return value Data type: bool

Status if and how PP has been moved during the last stop state.

TRUE if PP has been moved during the last stop.


FALSE if PP has not been moved during the last stop.

If PP has been moved to the main routine, both \PPMoved and \PPToMain will return
TRUE.

If PP has been moved to a routine, both \PPMoved and \PPToMain will return TRUE.

When calling a routine or a service routine (keep execution context in main program
sequence) \PPMove will return TRUE and \PPToMain will return FALSE.

RAPID Developer’s Manual 153


IsStopStateEvent Function

Arguments
IsStopStateEvent ( [\PPMoved] | [\PPToMain] )
[\PPMoved] Data type: switch

Test whether PP has been moved.

[\PPToMain] Data type: switch

Test whether PP has been moved to main.

Limitations
This function can in most cases not be used at forward or backward execution, because
the system is in stop state between every single step.

Syntax
IsStopStateEvent’(’
[’\’ PPMoved] | [’\’ PPToMain] ’)’

A function with a return value of the data type bool.

Related information
Described in:
Making own instructions RAPID Reference Manual
- Programming off-line

154 RAPID Developer’s Manual


Function ReadCfgData

ReadCfgData Reads attribute of a system parameter


ReadCfgData is used to read one attribute of a named system parameter (configuration
data).

Examples
ReadCfgData “/MOC/MOTOR_CALIB/irb_1”,”cal_offset”,offset1;

Reads the value of the calibration offset for axis irb_1 into the num variable
offset1.

ReadCfgData “/EIO/EIO_USER_SIGNAL/process_error”,”Unit”,io_unit;

Reads the name of the I/O unit where the signal process_error is defined, into
the string variable io_unit.

Arguments
ReadCfgData InstancePath Attribute CfgData
InstancePath Data type: string

Specifies a path to the named parameter to be accessed. The format of this string
is /DOMAIN/TYPE/InstanceName

Attribute Data type: string

The name of the attribute of the parameter to be read.

CfgData Data type: any type

The variable where the attribute will be stored. Depending on the attribute type,
the valid types are bool, num, or string.

Program execution
The value of the attribute specified by the Attribute argument is stored in the variable
specified by the CfgData argument.

RAPID Developer’s Manual 155


ReadCfgData Function

Limitations
Only named parameters can be accessed, i.e. parameters where the first attribute is
‘name’, ‘Name’, or ‘NAME’.

RAPID strings are limited to 80 characters. In some cases, this can be in theory too
small for the definition InstancePath, Attribute, or CfgData.

Error handling
If it is not possible to find the data specified with “InstancePath + Attribute” in the con-
figuration database, the system variable ERRNO is set to ERR_CFG_NOTFND.

If the data type for parameter CfgData is not equal to the real data type for the found
data specified with “InstancePath + Attribute” in the configuration database, the sys-
tem variable ERRNO is set to ERR_CFG_ILLTYPE.

These errors can then be handled in the error handler.

Syntax
ReadCfgData
[ InstancePath ’:=’ ] < expression (IN) of string >’,’
[ Attribute ’:=’ ] < expression (IN) of string > ’,’
[ CfgData ’:=’ ] < variable (VAR) of anytype > ’;’

Related information
Described in:
Definition of string Data types- string
Write attribute of a system parameter Instructions - WriteCfgData
Configuration User’s Guide - System Parameters

156 RAPID Developer’s Manual


Instructions WriteCfgData

WriteCfgDataWrites attribute of a system parameter


WriteCfgData is used to write one attribute of a named system parameter (configura-
tion data).

Examples
WriteCfgData “/MOC/MOTOR_CALIB/irb_1”,”cal_offset”,offset1;

Writes the value of the num variable offset1 as calibration offset for axis irb_1.

WriteCfgData “/EIO/EIO_USER_SIGNAL/process_error”,”Unit”,io_unit;

Writes the value of the string variable io_unit as the name of the I/O unit where
the signal process_error is defined.

Arguments
WriteCfgData InstancePath Attribute CfgData
InstancePath Data type: string

Specifies a path to the named parameter to be modified. The format of this string
is /DOMAIN/TYPE/InstanceName

Attribute Data type: string

The name of the attribute of the parameter to be written.

CfgData Data type: any type

The variable where the attribute is read. Depending on the attribute type, valid
types are bool, num, or string.

Program execution
The value of the attribute specified by the Attribute argument is set according to the
value of the variable specified by the CfgData argument.

RAPID Reference Manual 8-WriteCfgData-1


WriteCfgData Instructions

Limitations
You must manual restart the controller in order for the change to have effect.

Only named parameters can be accessed, i.e. parameters where the first attribute is
‘name’, ‘Name’, or ‘NAME’.

RAPID strings are limited to 80 characters. In some cases, this can be in theory too
small for the definition of InstancePath, Attribute, or CfgData.

Error handling
If it is not possible to find the data specified with “InstancePath + Attribute” in the con-
figuration database, the system variable ERRNO is set to ERR_CFG_NOTFND.

If the data type for parameter CfgData is not equal to the real data type for the found
data specified with “InstancePath + Attribute” in the configuration database, the sys-
tem variable ERRNO is set to ERR_CFG_ILLTYPE.

If the data for parameter CfgData is outside limits (max./min. value), the system vari-
able ERRNO is set to ERR_CFG_LIMIT.

These errors can then be handled in the error handler.

Syntax
WriteCfgData
[ InstancePath ’:=’ ] < expression (IN) of string >’,’
[ Attribute ’:=’ ] < expression (IN) of string > ’,’
[ CfgData ’:=’ ] < variable (VAR) of anytype > ’;’

Related information
Described in:
Definition of string Data types- string
Read attribute of a system parameter Instructions - ReadCfgData
Configuration User’s Guide - System Parameters

8-WriteCfgData-2 RAPID Reference Manual


Function PFIOResto

PFIOResto Restore Digital Output Signals


after Power Failure
PFIOResto (Power Failure Output Restore) is used to restore the values of all digital
output signals, including groups of digital output signals, to the values at the time of
power failure (if not already affected from RAPID program or TP at power up after
power fail).

Example
PFIOResto;

All digital output signals are restored to the values before power failure.

Program execution
All digital output signals are restored to the values before power failure. If a digital out-
put signal has been affected after the power failure and after the restart of the system,
e.g. from the RAPID program or from the TP, then this output will not be changed.

Syntax
PFIOResto’;’

Related information
Described in:
Input/Output instructions RAPID Summary -
Input and Output Signals
Input/Output functionality in general Motion and I/O Principles -
I/O Principles
Configuration of I/O System Parameters
Power Failure ...

RAPID Developer’s Manual 159


PFIOResto Function

160 RAPID Developer’s Manual


Function PFDOVal

PFDOVal Digital Output Value before Power Failure


PFDOVal (Power Failure Digital Output Value) is used to get the value of the specified
digital output signal at the time for power failure.

Example
SetDO do15, PFDOVal(do15);

First the function PFDOVal(do15) gets the value of do15 at the time of power
failure, then do15 is set to this value.

Return value Data type: dionum

The value of the specified digital output signal at the time for power failure.

Arguments
PFDOVal (Signal)

Signal Data type: signaldo

The name of the signal to be read.

Syntax
PFDOVal’(’
[ Signal ':=' ] < variable (VAR) of signaldo >’)’

A function with a return value of the data type dionum.

RAPID Developer’s Manual 161


PFDOVal Function

Related information
Described in:
Input/Output instructions RAPID Summary -
Input and Output Signals
Input/Output functionality in general Motion and I/O Principles -
I/O Principles
Configuration of I/O System Parameters
Power Failure ...

162 RAPID Developer’s Manual


Function PFGOVal

PFGOVal Group Output Value before Power Failure


PFGOVal (Power Failure Group Output Value) is used to get the value of the specified
group of digital output signals at the time for power failure.

Example
SetGO go2, PFGOVal(go2);

First the function PFGOVal(go2) gets the value of go2 at the time for power fail-
ure, then go2 is reset to this value.

Return value Data type: num

The value of the specified group of digital output signals at the time for power failure.

Arguments
PFGOVal (Signal)

Signal Data type: signalgo

The name of the signal group to be read.

Syntax
PFGOVal’(’
[ Signal ':=' ] < variable (VAR) of signalgo > ’)’

A function with a return value of the data type num.

RAPID Developer’s Manual 163


PFGOVal Function

Related information
Described in:
Input/Output instructions RAPID Summary -
Input and Output Signals
Input/Output functionality in general Motion and I/O Principles -
I/O Principles
Configuration of I/O System Parameters
Power Failure ...

164 RAPID Developer’s Manual


Function PFRestart

PFRestart Check interrupted path after power failure


PFRestart (Power Failure Restart) is used to check if the path has been interrupted at
power failure. If so it might be necessary to make some specific actions. The function
checks the path on current level, base level or on interrupt level.

Example
IF PFRestart() = TRUE THEN

It is checked if an interrupted path exists on the current level. If so the function


will return TRUE.

Return value Data type: bool

TRUE if an interrupted path exists on the specified path level, otherwise FALSE.

Arguments
PFRestart ([\Base] | [\Irpt])
[\Base] (Base Level) Data type: switch

Returns TRUE if an interrupted path exists on base level.

[\Irpt] (Interrupt Level) Data type: switch

Returns TRUE if an interrupted path exists on interrupt level.

If no argument is given, the function will return TRUE if an interrupted path


exists on current level.

Syntax
PFRestart’(’
[’\’Base] | [’\’Irpt]’)’

A function with a return value of the data type bool.

RAPID Developer’s Manual 165


PFRestart Function

Related information
Described in:
Power Failure ...

166 RAPID Developer’s Manual


Instructions TriggSpeed

TriggSpeed Defines TCP speed proportional analog


output with fixed position-time scale event
TriggSpeed is used to define conditions and actions for control of an analog output sig-
nal with output value proportional to the actual TCP speed. The beginning, scaling, and
ending of the analog output can be specified at a fixed position-time along the robot’s
movement path. It is possible to use time compensation for the lag in the external
equipment for the beginning, scaling, and ending of the analog output and also for
speed dips of the robot.

The data defined is used in one or more subsequent TriggL, TriggC, or TriggJ instruc-
tions.
(Only if the robot is equipped with the option “Advanced functions”.)

Examples
VAR triggdata glueflow;

TriggSpeed glueflow, 0, 0.05, glue_ao, 0.8\DipLag=:0.04 \ErrDO:=glue_err;


TriggL p1, v500, glueflow, z50, gun1;

TriggSpeed glueflow, 10, 0.05, glue_ao, 1;


TriggL p2, v500, glueflow, z10, gun1;

TriggSpeed glueflow, 0, 0.05, glue_ao, 0;


TriggL p3, v500, glueflow, z50, gun1;

Path with glue flow


Path without glue flow
New glue flow scale value

p1 p2

Glue flow starts

p3
Glue flow ends

Figure 12 Example of TriggSpeed sequence.

The glue flow (analog output glue_ao) with scale value 0.8 start when TCP is 0.05 s
before point p1, new glue flow scale value 1 when TCP is 10 mm plus 0.05 s before
point p2 and the glue flow ends (scale value 0) when TCP is 0.05 s before point p3.

Any speed dip by the robot is time compensated in such a way that the analog output

RAPID Reference Manual 167


TriggSpeed Instructions

signal glue_ao is affected 0.04 s before the TCP speed dip occurs.

If overflow of the calculated logical analog output value in glue_ao, the digital output
signal glue_err is set. If no overflow any more, glue_err is reset.

Arguments
TriggSpeed TriggData Distance [ \Start ] ScaleLag
AOp ScaleValue [ \DipLag ] [ \ErrDO ]
TriggData Data type: triggdata

Variable for storing the triggdata returned from this instruction. These triggdata
are then used in the subsequent TriggL, TriggC or TriggJ instructions.

Distance Data type: num

Defines the position on the path for change of the analog output value.

Specified as the distance in mm (positive value) from the end point of the move-
ment path (applicable if the argument \ Start is not set).

See the section entitled Program execution for further details.

[ \Start ] Data type: switch

Used when the distance for the argument Distance starts at the movement start
point instead of the end point.

ScaleLag Data type: num

Specify the lag as time in s (positive value) in the external equipment for change
of the analog output value (starting, scaling and ending).

For compensation of external equipment lag, this argument value means that the
analog output signal is set by the robot at specified time before the TCP physi-
cally reaches the specified distance in relation to the movement start or end point.

The argument can also be used to extend the analog output beyond the end point.
Set the time in seconds that the robot shall keep the analog output. Set the time
with a negative sign. The limit is -0.10 seconds.

168 RAPID Reference Manual


Instructions TriggSpeed

Start point End point

Distance Distance
\Start

+ - + -

ScaleLag

Figure 13 Use of argument ScaleLag.

AOp (Analog Output) Data type: signalao

The name of the analog output signal.

ScaleValue Data type: num

The scale value for the analog output signal.

The physical output value for the analog signal is calculated by the robot:

- Logical output value = Scale value * Actual TCP speed in mm/s


- Physical output value = According definition in configuration for actual analog
output signal with above Logical output value as input

[ \DipLag ] Data type: num

Specify the lag as time in s (positive value) for the external equipment when
changing of the analog output value due to robot speed dips.

For compensation of external equipment lag, this argument value means that the
analog output signal is set by the robot at a specified time before the TCP speed
dip occurs.

This argument can only be used by the robot for the first TriggSpeed (in combi-
nation with one of TriggL, TriggC, or TriggJ) in a sequence of several Trigg-
Speed instructions. The first specified argument value is valid for all the
following TriggSpeed in the sequence.

[ \ErrDO ] (Error Digital Output) Data type: signaldo

The name of the digital output signal for reporting analog value overflow.

If during movement the calculation of the logical analog output value for signal
in argument AOp result in overflow due to overspeed, this signal is set and the
physical analog output value is reduced to the maximum value. If no overflow
any more, the signal is reset.

This argument can only be used by the robot for the 1:st TriggSpeed (in combi-

RAPID Reference Manual 169


TriggSpeed Instructions

nation with one of TriggL, TriggC or TriggJ) in a sequence of several TriggSpeed


instructions. The 1:st given argument value is valid for all the following Trigg-
Speed in the sequence.

Program execution
When running the instruction TriggSpeed, the trigger condition is stored in the speci-
fied variable for the argument TriggData.

Afterwards, when one of the instructions TriggL, TriggC or TriggJ is executed, the fol-
lowing are applicable, with regard to the definitions in TriggSpeed:

The distance specified in the argument Distance:


Linear movement The straight line distance
Circular movement The circle arc length

Non-linear movement The approximate arc length along the path


(to obtain adequate accuracy, the distance should
not exceed one half of the arc length).

End point with


corner path

If the Distance is 0, the scale value is


changed when the robot’s TCP is here

Figure 14 Fixed position-time scale value event on a corner path.

The position-time related scale value event will be generated when the start point (end
point) is passed, if the specified distance from the end point (start point) is not within
the length of movement of the current instruction (Trigg...).

The 1:st TriggSpeed used by one of TriggL, TriggC or TriggJ instruction will internally
in the system create a process with the same name as the analog output signal. The same
process will be used by all succeeding Trigg..., which refer to same signal name and
setup by a TriggSpeed instruction.

The process will immediately set the analog output to 0, in the event of a program emer-
gency stop. In the event of a program stop, the analog output signal will stay TCP-speed
proportional until the robot stands still. The process keeps “alive” ready for a restart.
When the robot restarts, the signal is TCP-speed proportional directly from the start.

170 RAPID Reference Manual


Instructions TriggSpeed

Program stop
TCP Speed

Analog output signal

Emergency stop
TCP Speed

Analog output signal

The process will “die” after handling a scale event with value 0, if no succeeding
Trigg... is in the queue at the time.

Examples
VAR triggdata flow;

TriggSpeed flow, 10 \Start, 0.05, flowsignal, 0.5 \DipLag:=0.03;

MoveJ p1, v1000, z50, tool1;


TriggL p2, v500, flow, z50, tool1;

The analog output signal flowsignal is set to a logical value = (0.5 * actual TCP
speed in mm/s) 0.05 s before the TCP passes a point located 10 mm after the start
point p. The output value is adjusted to be proportional to the actual TCP speed
during the movement to p2.

...
TriggL p3, v500, flow, z10, tool1;

The robot moves from p2 to p3 still with the analog output value proportional to
the actual TCP speed. The analog output value will be decreased at time 0.03 s
before the robot reduce the TCP speed during the passage of the corner path z10.

Limitations

Accuracy of position-time related scale value event:

Typical absolute accuracy values for scale value events +/- 5 ms.
Typical repeat accuracy values for scale value events +/- 2 ms.

RAPID Reference Manual 171


TriggSpeed Instructions

Accuracy of TCP speed dips adaptation (deceleration - acceleration phases):

Typical absolute accuracy values for TCP speed dips adaptation +/- 5 ms.
Typical repeat accuracy values for TCP speed dips adaptation +/- 2ms
(the value depends of the configured Path resolution).

Negative ScaleLag

If a negative value on parameter ScaleLag is used to move the zero scaling over to the
next segment, the analog output signal will not be reset if a program stop occurs. An
emergency stop will always reset the analog signal.

The analog signal is no longer TCP-speed proportional after the end point on the seg-
ment.
Start segment TCP movements End segment

AO active
Not TCP-speed
proportial

Error handling
Given two consecutive segments with TriggL/TriggSpeed instructions. A negative
value in parameter ScaleLag makes it possible to move the scale event from the first
segment to the beginning of the second segment. If the second segment scales at the
beginning, there is no control if the two scalings interfere.

V
Wanted analog output signal

Segment n Segment n+1

V
Possible results in the event
of interferences

172 RAPID Reference Manual


Instructions TriggSpeed

Related system parameters


The servo parameter Event Preset Time is used to delay the robot to make it possible
to activate/control the external equipment before the robot runs through the position.

Table 6 Recommendation for setup of system parameter Event Preset Time 1)

Required Event Preset Time Recommended Event Preset Time


ScaleLag DipLag
to avoid runtime execution error to obtain best accuracy

ScaleLag > DipLag Always DipLag, if DipLag > Servo Lag ScaleLag in s plus 0.090 s

ScaleLag < DipLag DipLag < Servo Lag ----------------- “ -------------- 0.090 s

---------- “ --------- DipLag > Servo Lag ---------------- “ --------------- DipLag in s plus 0.030 s

1) Typical Servo Lag is 0.056 seconds

Syntax
TriggSpeed
[ TriggData ’:=’ ] < variable (VAR) of triggdata> ‘,’
[ Distance ’:=’ ] < expression (IN) of num>
[ ’\’ Start ] ‘,’
[ ScaleLag ’:=’ ] < expression (IN) of num> ‘,’
[ AOp ’:=’] < variable (VAR) of signalao> ‘,’
[ ScaleValue ’:=’ ] < expression (IN) of num>
[ ’\’ DipLag ’:=’ < expression (IN) of num> ]
[ ’\’ ErrDO ’:=’ < variable (VAR ) of signaldo> ] ‘;’

Related information
Described in:
Use of triggers Instructions - TriggL, TriggC, TriggJ
Definition of other triggs Instruction - TriggIO, TriggInt,
TriggEquip
More examples Data Types - triggdata
Configuration of Event preset time System Parameters - Manipulator

RAPID Reference Manual 173


TriggSpeed Instructions

174 RAPID Reference Manual


Instructions StepBwdPath

StepBwdPath Move backwards one step on path


StepBwdPath is used to move the TCP backwards on the robot path from a RESTART
event routine.

It’s up to the user, to introduce a restart process flag, so StepBwdPath in the RESTART
event routine is only executed at process restart and not at all program restart.

Example
StepBwdPath 30, 1;

Move backwards 30 mm in 1 second.

Arguments
StepBwdPath StepLength StepTime
StepLength Data type: num

Specifies the distance, in millimetres, to move backwards during this step. This
argument must be a positive value.

StepTime Data type: num

Specifies the time, in seconds, the movement will take. This argument must have
a positive value.

Program execution
The robot moves back on its path, for the specified distance. The path is exactly the
same, in the reverse way, as it was before the stop occurred. In the case of a quick stop
or emergency stop, the RESTART event routine is called after the regain phase has
completed, so the robot will already be back on its path when this instruction is exe-
cuted.

The actual speed for this movement is the lowest of:


- StepLength / StepTime
- The programmed speed on the segment
- 250 mm/s

RAPID Reference Manual 175


StepBwdPath Instructions

Limitations
After the program has been stopped, it is possible to step backwards on the path with
the following limits:
- The 1st step backward will be reduced to the current segment for the robot
- Further backward steps will be limited to the previous segment

If an attempt is made to move beyond these limit, the error handler will be called with
ERRNO set to ERR_BWDLIMIT.

Syntax
StepBwdPath
[ StepLength ’:=’ ] < expression (IN) of num >’,’
[ StepTime ’:=’ ] < expression (IN) of num > ’;’

Related information
Described in:
Motion in general Motion and I/O Principles
Positioning instructions RAPID Summary- Motion

176 RAPID Reference Manual


Instructions restartdata

restartdata Restart data for trigg signals

restartdata mirrors the pre- and postvalues of specified I/O signals (process signals) at
the stop sequence of the robot movements.
The I/O signals to supervise are specified in the instruction TriggStopProc.

TriggStopProc and restartdata are intended to be used for restart after program stop
(STOP) or emergency stop (QSTOP) of own process instructions defined in RAPID
(NOSTEPIN routines).

Definition

Table 7 Definition of the time point for reading the pre- and postvalues for the I/O signals

Read time for I/O signal prevalue Read time for I/O signal postvalue
Type of stop
(pretime) (postvalue)

STOP on path When all robot axes are standing About 400 ms after the pretime
still

QSTOP off path As soon as possible About 400 ms after the pretime

Description
restartdata mirrors the following data after program execution is stopped:

- valid restart data


- robot stopped on path or not
- prevalue of the I/O signals
- postvalue of the I/O signals
- number of flanks between pretime and posttime of the shadow signal
for the ongoing process

Components
restartstop (valid restartdata after stop) Data type: bool

TRUE = Mirror last STOP or QSTOP


FALSE = Invalid restart data. All I/O signals values are set to -1.

stoponpath (stop on path) Data type: bool

TRUE = The robot is stopped on the path (STOP)

RAPID Reference Manual 177


restartdata Instructions

FALSE = The robot is stopped but not on the path (QSTOP)

predo1val (pre do1 value) Data type: dionum

The prevalue of the digital signal “do1” specified in the argument DO1 in instruc-
tion TriggStopProc.

postdo1val (post do1 value) Data type: dionum

The postvalue of the digital signal “do1” specified in the argument DO1 in
instruction TriggStopProc.

prego1val (pre go1 value) Data type: num

The prevalue of the digital group signal “go1” specified in the argument GO1 in
instruction TriggStopProc.

postgo1val (post go1 value) Data type: num

The postvalue of the digital group signal “go1” specified in the argument GO1 in
instruction TriggStopProc.

prego2val (pre go2 value) Data type: num

The prevalue of the digital group signal “go2” specified in the argument GO2 in
instruction TriggStopProc.

postgo2val (post go2 value) Data type: num

The postvalue of the digital group signal “go2” specified in the argument GO2 in
instruction TriggStopProc.

prego3val (pre go3 value) Data type: num

The prevalue of the digital group signal “go3” specified in the argument GO3 in
instruction TriggStopProc.

postgo3val (post go3 value) Data type: num

The postvalue of the digital group signal “go3” specified in the argument GO3 in
instruction TriggStopProc.

prego4val (pre go4 value) Data type: num

The prevalue of the digital group signal “go4” specified in the argument GO4 in
instruction TriggStopProc.

postgo4val (post go4 value) Data type: num

The postvalue of the digital group signal “go4” specified in the argument GO4 in
instruction TriggStopProc.

178 RAPID Reference Manual


Instructions restartdata

preshadowval (pre shadow value) Data type: dionum

The prevalue of the digital signal “shadow” specified in the argument


ShadowDO in instruction TriggStopProc.

shadowflanks (number of shadow flanks) Data type: num

The number of value transitions (flanks) of the digital signal “shadow” between
the pretime and the posttime.
The signal “shadow” is specified in the argument ShadowDO in instruction
TriggStopProc.

postshadowval (post shadow value) Data type: dionum

The postvalue of the digital signal “shadow” specified in the argument


ShadowDO in instruction TriggStopProc.

Structure
< dataobject of restartdata>
< restartstop of bool>
< stoponpath of bool>
< predo1val of dionum>
< postdo1val of dionum>
< prego1val of num>
< postgo1val of num>
< prego2val of num>
< postgo2val of num>
< prego3val of num>
< postgo3val of num>
< prego4val of num>
< postgo4val of num>
< preshadowval of dionum>
< shadowflanks of dionum>
< postshadowval of dionum>

Related information
Described in:
Predefined process instructions Instructions - TriggL, TriggC
Setup mirror of restart data Instructions - TriggStopProc
Move backwards on path Instructions - StepBwdPath

RAPID Reference Manual 179


restartdata Instructions

180 RAPID Reference Manual


Instructions TriggStopProc

TriggStopProc Generate restart data


for trigg signals at stop
The instruction TriggStopProc creates an internal supervision process in the system for
zero setting of specified process signals and the generation of restart data in a specified
persistent variable at every program stop (STOP) or emergency stop (QSTOP) in the
system.

TriggStopProc and the data type restartdata are intended to be used for restart after
program stop (STOP) or emergency stop (QSTOP) of own process instructions defined
in RAPID (NOSTEPIN routines).

It is possible in a user defined RESTART event routine, to analyse the current restart
data, step backwards on the path with instruction StepBwdPath and activate suitable
process signals before the movement restarts.

Arguments
TriggStopProc RestartRef [\DO1] [\GO1] [\GO2] [\GO3] [\GO4]
ShadowDO
RestartRef (Restart Reference) Data type: restartdata

The persistent variable in which restart data will be available after every stop of
program execution.

[\DO1] (Digital Output 1) Data type: signaldo

The signal variable for a digital process signal to be zero set and supervised in
restart data when program execution is stopped.

[\GO1] (Group Output 1) Data type: signalgo

The signal variable for a digital group process signal to be zero set and super-
vised in restart data when program execution is stopped.

[\GO2] (Group Output 2) Data type: signalgo

The signal variable for a digital group process signal to be zero set and super-
vised in restart data when program execution is stopped.

[\GO3] (Group Output 3) Data type: signalgo

The signal variable for a digital group process signal to be zero set and super-
vised in restart data when program execution is stopped.

[\GO4] (Group Output 4) Data type: signalgo

The signal variable for a digital group process signal to be zero set and super-

RAPID Reference Manual 2-TriggStopProc-379


TriggStopProc Instructions

vised in restart data when program execution is stopped.

At least one of the option parameters DO1, GO1 ... GO4 must be used.

ShadowDO (Shadow Digital Output) Data type: signaldo

The signal variable for the digital signal, which must mirror whether or not the
process is active along the robot path.

This signal will not be zero set by the process TriggStopProc at STOP or QSTOP,
but its values will be mirrored in restartdata.

Program execution

Setup and execution of TriggStopProc

TriggStopProc must be called from both:

- the START event routine or in the init part of the program


(set PP to main kill the internal process for TriggStopProc)
- the POWERON event routine
(power off kill the internal process for TriggStopProc)

The internal name of the process for TriggStopProc is the same as the signal name in
the argument ShadowDO. If TriggStopProc, with same the signal name in argument
ShadowDO, is executed twice, only the last executed TriggStopProc will be active.

Execution of TriggStopProc only starts the supervision of I/O signals at STOP and
QSTOP.

Program stop STOP

The process TriggStopProc comprises the following steps:

- Wait until the robot stands still on the path.


- Store the current value (prevalue according to restartdata) of all used
process signals.
Zero set all used process signals except ShadowDO.
- Do the following during the next time slot, about 500 ms:
- If some process signals change its value during this time:
- Store its current value again (postvalue according to restatdata)
- Zero set that signal, except ShadowDO
- Count the number of value transitions (flanks) of the signal ShadowDO
- Update the specified persistent variable with restart data.

2-TriggStopProc-380 RAPID Reference Manual


Instructions TriggStopProc

Emergency stop (QSTOP)

The process TriggStopProc comprises the following steps:

- Do the next step as soon as possible.


- Store the current value (prevalue according to restartdata) of all used
process signals.
Zero set all used process signals except ShadowDO.
- Do the following during the next time slot, about 500 ms:
- If some process signal changes its value during this time:
- Store its current value again (postvalue according to restatdata)
- Zero set that signal, except ShadowDO
- Count the number of value transitions (flanks) of the signal ShadowDO
- Update the specified persistent variable with restart data.

Critical area for process restart

Both the robot servo and the external equipment have some lags. All the instructions
in the Trigg family are designed so that all signals will be set at suitable places on the
robot path, independently of different lags in external equipment, to obtain process
results that are as good as possible. Because of this, the settings of I/O signals can be
delayed between 0 - 80 ms internally in the system, after the robot stands still at pro-
gram stop (STOP) or after registration of an emergency stop (QSTOP). Because of this
disadvantage for the restart functionality, both the prevalue and postvalue and also the
shadow flanks are introduced in restart data.

If this critical timeslot of 0 - 80 ms coincides with following process cases, it is difficult


to perform a good process restart:

- At the start of the process


- At the end of the process
- During a short process
- During a short interrupt in the process

RAPID Reference Manual 2-TriggStopProc-381


TriggStopProc Instructions

Figure 22 Process phases at STOP or QSTOP within critical time slot 0-80 ms

No active process: shadowval:


preshadowval = 0
1
shadowflanks = 0
postshadowval = 0 0

Active process: shadowval:


preshadowval = 1
1
shadowflanks = 0
postshadowval = 1 0

Start of process: shadowval:


preshadowval = 0
1
shadowflanks = 1
postshadowval = 1 0

End of process: shadowval:


preshadowval = 1
1
shadowflanks = 1
postshadowval = 0 0

Short process: shadowval:


preshadowval = 0
1
shadowflanks = 2
postshadowval = 0 0

Short interrupt in process: shadowval:


preshadowval = 1
1
shadowflanks = 2
postshadowval = 1 0

2-TriggStopProc-382 RAPID Reference Manual


Instructions TriggStopProc

Performing a restart
A restart of own process instructions (NOSTEPIN routines) along the robot path must
be done in a RESTART event routine.

The RESTART event routine can consist of the following steps:


- After QSTOP, the regain to path is done at program start
- Analyse the restart data from the latest STOP or QSTOP
- Determine the strategy for process restart from the result of the analyse such as:
- Process active, do process restart
- Process inactive, do no process restart
- Do suitable actions depending of which type of process application if:
- Start of process
- End of process
- Short process
- Short interrupt in process
-
- Process start-up or process end-up take suitable actions depending on which
type
of process application
- Step backwards on the path
- Activate suitable process signals with values according to restart data
- Continue the program results in restart of the movement.

Limitation
No support for restart of own process instructions after a power failure.

Syntax
TriggStopProc
[ RestartRef ’:=’ ] < persistent (PERS) of restartdata>
[ ’\’ DO1 ’:=’ < variable (VAR) of signaldo> ]
[ ’\’ GO1 ’:=’ < variable (VAR) of signalgo> ]
[ ’\’ GO2 ’:=’ < variable (VAR) of signalgo> ]
[ ’\’ GO3 ’:=’ < variable (VAR) of signalgo> ]
[ ’\’ GO4 ’:=’ < variable (VAR) of signalgo> ] ’,’
[ ShadowDO ’:=’ ] < variable (VAR) of signaldo> ’;’

RAPID Reference Manual 2-TriggStopProc-383


TriggStopProc Instructions

Related information
Described in:
Predefined process instructions Instructions - TriggL, TriggC
Restart data Data Types - restartdata
Step backward on path Instructions - StepBwdPath

2-TriggStopProc-384 RAPID Reference Manual


Data Types dir

dir File Directory structure

dir (directory) is used to traverse directory structures.

Description
Data of the type dir contains a reference to a directory on disk or network. It can be
linked to the physical directory by means of the instruction OpenDir and then used for
reading.

Example
PROC lsdir(string dirname)
VAR dir directory;
VAR string filename;
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
TPWrite filename;
ENDWHILE
CloseDir directory;
ENDPROC

This example prints out the names of all files or subdirectories under the speci-
fied directory.

Characteristics
dir is a non-value data type and cannot be used in value-oriented operations.

Related information
Described in:
Open a directory OpenDir
Read a directory ReadDir
Close a directory CloseDir
Check file type IsFile

RAPID Developer’s Manual 187


dir Data Types

188 RAPID Developer’s Manual


Data Types

MakeDir Create a new directory


MakeDir is used to create a new directory. The user must have write and execute per-
mission for the parent directory under which the new directory is created.

Examples
MakeDir “HOME:/newdir”;

This example creates a new directory under HOME:

Arguments
MakeDir Path
Path Data type: string

The name of the new directory, specified with full or relative path.

Error handling
If the directory cannot be created, the system variable ERRNO is set to
ERR_FILEACC. This error can then be handled in the error handler.

Syntax
MakeDir
[ Path’:=’ ] < expression (IN) of string>’;’

Related information
Described in:
Remove a directory RemoveDir
Remove a file RemoveFile

RAPID Developer’s Manual 189


Data Types

190 RAPID Developer’s Manual


Data Types OpenDir

OpenDir Open a directory


OpenDir is used to open a directory for further investigation.

Example
PROC lsdir(string dirname)
VAR dir directory;
VAR string filename;
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
TPWrite filename;
ENDWHILE
CloseDir directory;
ENDPROC

This example prints out the names of all files or subdirectories under the speci-
fied directory.

Arguments
OpenDir Dev Path
Dev Data type: dir

A variable with reference to the directory, fetch by OpenDir.


This variable is then used for reading from the directory.

Path Data type: string

Path to the directory.

Limitations
Open directories should always be closed by the user after reading (instruction
CloseDir).

Error handling
If the path points to a not existing directory or if there are too many directories open at
the same time, the system variable ERRNO is set to ERR_FILEACC. This error can
then be handled in the error handler.

RAPID Developer’s Manual 191


OpenDir Data Types

Syntax
OpenDir
[ Dev’:=’ ] < variable (VAR) of dir>’,’
[ Path’:=’ ] < expression (IN) of string>’;’

Related information
Described in:
Directory dir
Read a directory ReadDir
Close a directory CloseDir
Check file type IsFile

192 RAPID Developer’s Manual


Data Types CloseDir

CloseDir Close a directory


CloseDir is used to close a directory in balance with OpenDir.

Example
PROC lsdir(string dirname)
VAR dir directory;
VAR string filename;
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
TPWrite filename;
ENDWHILE
CloseDir directory;
ENDPROC

This example prints out the names of all files or subdirectories under the speci-
fied directory.

Arguments
CloseDir Dev
Dev Data type: dir

A variable with reference to the directory fetched with instruction OpenDir.

Syntax
CloseDir
[ Dev’:=’ ] < variable (VAR) of dir>’;’

Related information
Described in:
Directory dir
Open a directory OpenDir
Read a directory ReadDir
Check file type IsFile

RAPID Developer’s Manual 193


CloseDir Data Types

194 RAPID Developer’s Manual


Instructions RemoveDir

RemoveDir Delete a directory


RemoveDir is used to remove a directory.

The user must have write and execute permission for the directory and the directory
must be empty.

Examples
RemoveDir “HOME:/mydir”;

In this example, the mydir directory under HOME: is deleted.

Arguments
RemoveDir Path
Path Data type: string

The name of the directory to be removed, specified with full or relative path.

Error handling
If the directory does not exist or the directory is not empty, the system variable ERRNO
is set to ERR_FILEACC. This error can then be handled in the error handler.

Syntax
RemoveDir
[ Path’:=’ ] < expression (IN) of string>’;’

RAPID Developers Manual 9-RemoveDir-11


RemoveDir Instructions

Related information
Described in:
Directory dir
Make a directory MakeDir
Open a directory OpenDir
Read a directory ReadDir
Close a directory CloseDir

9-RemoveDir-12 RAPID Developers Manual


Data Types ReadDir

ReadDir Read next entry in a directory


ReadDir is used to retrieve the name of the next file or subdirectory under a directory
that has been opened with the instruction OpenDir.

As long as the function returns TRUE, there can be more files or subdirectories to
retrieve.

Example

PROC lsdir(string dirname)


VAR dir directory;
VAR string filename;
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
TPWrite filename;
ENDWHILE
CloseDir directory;
ENDPROC

This example prints out the names of all files or subdirectories under the speci-
fied directory.

Return value Data type: bool

The function will return TRUE if it has retrieved a name, otherwise FALSE.

Arguments
ReadDir ( Dev FileName )
Dev Data type: dir

A variable with reference to the directory, fetched by instruction OpenDir.

FileName Data type: string

The retrieved file or subdirectory name.

Program execution
This function returns a bool that specifies success or not.

RAPID Developer’s Manual 197


ReadDir Data Types

Example
This example implements a generic traverse of a directory structure function.

PROC searchdir(string dirname, string actionproc)


VAR dir directory;
VAR string filename;
IF IsFile(dirname \Directory) THEN
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
! .. and . is the parent and resp. this directory
IF filename <> ".." AND filename <> "." THEN
searchdir dirname+"/"+filename, actionproc;
ENDIF
ENDWHILE
CloseDir directory;
ELSE
%actionproc% dirname;
ENDIF
ERROR
RAISE;
ENDPROC

PROC listfile(string filename)


TPWrite filename;
ENDPROC

PROC main()
! Execute the listfile routine for all files found under the
! tree in ram1disk:
searchdir "ram1disk:","listfile";
ENDPROC

This program traverses the directory structure under the "ram1disk:", and for
each file found it calls the listfile procedure. The searchdir is the generic part that
knows nothing about the start of the search or which routine should be called for
each file. It uses IsFile to check whether it has found a subdirectory or a file and
it uses the late binding mechanism to call the procedure specified in actionproc
for all files found. The actionproc routine should be a procedure with one param-
eter of the type string.

Error handling
If the directory is not opened (see OpenDir), the system variable ERRNO is set to
ERR_FILEACC. This error can then be handled in the error handler.

198 RAPID Developer’s Manual


Data Types ReadDir

Syntax
ReadDir ’(’
[ Dev’:=’ ] < variable (VAR) of dir>’,’
[ FileName’:=’ ] < var or pers (INOUT) of string>’)’

A function with a return value of the data type bool.

Related information
Described in:
Directory dir
Open a directory OpenDir
Close a directory CloseDir
Check file type IsFile

RAPID Developer’s Manual 199


ReadDir Data Types

200 RAPID Developer’s Manual


Data Types

IsFile Check the type of a file


The IsFile function obtains information about the named file and checks whether it is
the same as the specified type. If no type is specified, only an existence check is per-
formed. The path argument specifies the file. Read, write or execute permission for the
named file is not required, but all directories listed in the path name leading to the file
must be searchable.

Example
PROC printFT(string filename)
IF IsFile(filename \Directory) THEN
TPWrite filename+" is a directory";
RETURN;
ENDIF
IF IsFile(filename \Fifo) THEN
TPWrite filename+" is a fifo file";
RETURN;
ENDIF
IF IsFile(filename \RegFile) THEN
TPWrite filename+" is a regular file";
RETURN;
ENDIF
IF IsFile(filename \BlockSpec) THEN
TPWrite filename+" is a block special file";
RETURN;
ENDIF
IF IsFile(filename \CharSpec) THEN
TPWrite filename+" is a character special file";
RETURN;
ENDIF
ENDPROC

This example prints out the type of the specified file on the teach pendant.

Return value Data type: bool

The function will return TRUE if the specified type and actual type match, otherwise
FALSE. When no type is specified, it returns TRUE if the file exists and otherwise
FALSE.

RAPID Developer’s Manual 201


Data Types

Arguments
IsFile ( Path [\Directory] [\Fifo] [\RegFile] [\BlockSpec]
[\CharSpec] )
Path Data type: string

The file specified with a full or relative path.

[\Directory] Data type: switch

Is the file a directory.

[\Fifo] Data type: switch

Is the file a fifo, e.g. a serial channel.

[\RegFile] Data type: switch

Is the file a regular file, i.e. a normal binary or ascii file.

[\BlockSpec] Data type: switch

Is the file a block special device.

[\CharSpec] Data type: switch

Is the file a character special device.

Program execution
This function returns a bool that specifies match or not.

202 RAPID Developer’s Manual


Data Types

Example
This example implements a generic traverse of a directory structure function.

PROC searchdir(string dirname, string actionproc)


VAR dir directory;
VAR string filename;
IF IsFile(dirname \Directory) THEN
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
! .. and . is the parent and resp. this directory
IF filename <> ".." AND filename <> "." THEN
searchdir dirname+"/"+filename, actionproc;
ENDIF
ENDWHILE
CloseDir directory;
ELSE
%actionproc% dirname;
ENDIF
ERROR
RAISE;
ENDPROC

PROC listfile(string filename)


TPWrite filename;
ENDPROC

PROC main()
! Execute the listfile routine for all files found under the
! tree of HOME:
searchdir "HOME:","listfile";
ENDPROC

This program traverses the directory structure under the “HOME:” and for each
file found, it calls the listfile procedure. The searchdir is the generic part that
knows nothing about the start of the search or which routine should be called for
each file. It uses IsFile to check whether it has found a subdirectory or a file and
it uses the late binding mechanism to call the procedure specified in actionproc
for all files found. The actionproc routine should be a procedure with one param-
eter of the type string.

Error handling
If the file does not exist and there is a type specified, the system variable ERRNO is
set to ERR_FILEACC. This error can then be handled in the error handler.

RAPID Developer’s Manual 203


Data Types

Syntax
Isfile ’(’
[ Path’:=’ ] < expression (IN) of string>
[ [ '\'Directory ] | [ '\'Fifo ] | [ '\'RegFile ] | [ '\'BlockSpec ] | [ '\'CharSpec ] ]
’)’

A function with a return value of the data type bool.

Related information
Described in:
Directory dir
Open a directory OpenDir
Close a directory CloseDir
Read a directory ReadDir

204 RAPID Developer’s Manual


Data Types

FileSize Retrieve the size of a file


FileSize is used to retrieve the size of specified file.

Example
PROC listfile(string filename)
VAR num size;
size := FileSize(filename);
TPWrite filename+" size: "+NumToStr(size,0)+" Bytes";
ENDPROC

This procedure prints out the name of specified file together with a size
specification.

Return value Data type: num

The size in bytes.

Arguments
FileSize ( Path )
Path Data type: string

The file name specified with full or relative path.

Program execution
This function returns a numeric that specifies the size in bytes of the specified file.

RAPID Developer’s Manual 205


Data Types

Example
This example lists all files bigger than 1 KByte under the “HOME:” directory
structure, including all subdirectories.

PROC searchdir(string dirname, string actionproc)


VAR dir directory;
VAR string filename;
IF IsFile(dirname \Directory) THEN
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
! .. and . is the parent and resp. this directory
IF filename <> ".." AND filename <> "." THEN
searchdir dirname+"/"+filename, actionproc;
ENDIF
ENDWHILE
CloseDir directory;
ELSE
%actionproc% dirname;
ENDIF
ERROR
RAISE;
ENDPROC

PROC listfile(string filename)


IF FileSize(filename) > 1024 THEN
TPWrite filename;
ENDIF
ENDPROC

PROC main()
! Execute the listfile routine for all files found under the
! tree of HOME:
searchdir "HOME:","listfile";
ENDPROC

This program traverses the directory structure under “HOME:” and for each file
found it calls the listfile procedure. The searchdir is a generic part that knows
nothing about the start of the search or which routine should be called for each
file. It uses IsFile to check whether it has found a subdirectory or a file and it uses
the late binding mechanism to call the procedure specified in actionproc for all
files found. The actionproc routine listfile checks whether the file is bigger than
1KBytes.

206 RAPID Developer’s Manual


Data Types

Error handling
If the file does not exist, the system variable ERRNO is set to ERR_FILEACC. This
error can then be handled in the error handler.

Syntax
FileSize ’(’
[ Path ’:=’ ] < expression (IN) of string> ’)’

A function with a return value of the data type num.

Related information
Described in:
Directory dir
Open a directory OpenDir
Close a directory CloseDir
Read a directory ReadDir

Internt
Exekveringsmod: Beskrivning:
Kontinuerligt framåt Enligt ovan.
Stegvis framåt Enligt ovan.
Stegvis bakåt Exekverar aldrig bakåt
Simulering Enligt ovan

RAPID Developer’s Manual 207


Data Types

REVISION PAGE
Document Registration number: filesize.ard REVISION
REVIEWED BY DEP NAME DATE SIGNATURE

Author KCF Ingemar Reyier

Project KCF Sven-Erik Johansson

Subject KCF Sven-Erik Johansson

Others

User Documentation

Quality: User Manual

Test: User Manual

Fact: User Manual

Final: User Manual

208 RAPID Developer’s Manual


Data Types

REV. PAGE (P) DESCRIPTION DATE


CHAPT (C) DEPT./SIGN.

w0.1 New to RW3.1 971223 KCF/INRE


w0.2 Reviewed and approved 980122 KCF/SEJO
w0.3 RW4.0, ram1disk: replaced by HOME: 990913 KSG/PIHI
w0.4 Approved for RW4.0 991116 KSG/SEJO
English language reviewed 000101 jw

RAPID Developer’s Manual 209


Data Types

210 RAPID Developer’s Manual


Data Types

FSSize Retrieve the size of a file system


FSSize (File System Size) is used to retrieve the size of the file system in which a spec-
ified file resides. The size is returned as a num.

Example
PROC main()
VAR num totalfsyssize;
VAR num freefsyssize;
freefsyssize := FSSize("HOME:/spy.log" \Free);
totalfsyssize := FSSize("HOME:/spy.log" \Total);
TPWrite NumToStr(((totalfsyssize - freefsyssize)/totalfsyssize)*100,0)
+" percent used";
ENDPROC

This procedure prints out the amount of disk space used on the HOME: file sys-
tem (flash disk /hd0a/ ) as a percentage.

Return value Data type: num

The size in bytes.

Arguments
FSSize ( Name [\Total] | [\Free] )
Name Data type: string

The name of a file in the file system, specified with full or relative path.

[\Total] Data type: switch

Retrieves the total amount of space in the file system.

[\Free] Data type: switch

Retrieves the amount of free space in the file system.

Program execution
This function returns a numeric that specifies the size of the file system in which the
specified file resides.

RAPID Developer’s Manual 211


Data Types

Example
This is a complete example for implementing an alert service that prints a warning
on the TP when the remaining free space in the “HOME:” file system is less than
10%.

LOCAL VAR intnum timeint;

LOCAL TRAP mytrap


IF FSSize("HOME:/spy.log" \Free)/FSSize("HOME:/spy.log" \Total) <= 0.1 THEN
TPWrite "The disk is almost full";
alertFree;
ENDIF
ENDTRAP

PROC alertInit(num freq)


CONNECT timeint WITH mytrap;
ITimer freq,timeint;
ENDPROC

PROC alertFree()
IDelete timeint;
ENDPROC

Error handling
If the file system does not exist, the system variable ERRNO is set to ERR_FILEACC.
This error can then be handled in the error handler.

Syntax
FSSize’(’
[ Name ’:=’ ] < expression (IN) of string>
[ '\'Total ] | [ '\'Free ]’)’

A function with a return value of the data type num.

212 RAPID Developer’s Manual


Data Types

Related information
Described in:
File size. FileSize

RAPID Developer’s Manual 213


Data Types

214 RAPID Developer’s Manual


Data Types

RemoveFile Delete a file


RemoveFile is used to remove a file. The user must have write and execute permission
for the directory where the file resides and write permission for the file itself.

Examples
RemoveFile “HOME:/mydir/myfile.log”;

In this example, the file myfile.log in directory mydir on disk HOME: is deleted.

Arguments
RemoveFile Path
Path Data type: string

The name of the file to be deleted, specified with full or relative path.

Error handling
If the file does not exist, the system variable ERRNO is set to ERR_FILEACC. This
error can then be handled in the error handler.

Syntax
RemoveFile
[ Path’:=’ ] < expression (IN) of string>’;’ Related information

Related information
Described in:
Make a directory MakeDir
Remove a directory RemoveDir

RAPID Developer’s Manual 215


Data Types

216 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

Elementary IO Configuration File


Elementary IO is the term used in the robot system when refering to simple I/O such
as analog and digital inputs and outputs signals.

The Elemetary I/O (EIO) system comprises such item as I/O units, analog signals, dig-
ital signals, groups of digital signal and cross connections of digital signals.

The EIO System is configured using a configuration file. This file may be created and
edited by use of the Teach Pendant or by use of a regular text editor.

The coniguration file is divided into sections. Each section recognizes a set of param-
eters defining characteristics of the IO system. The sections are related as shown in
Figure 16 below.

Each section contains a list of configuration items one on each line. The configuration
items are configured by specifying values for the parameters, recognized by each sec-
tion.

Example:

EIO_UNIT:
-Name UNIT_A -Type d328 -Address 4 \
-Digin 16 -Digout 16 <-- End of first item
-Name UNIT_B -Type d328 -Address 7 \
-Digin 8 -Digin 8 <-- End of second item

As shown in the example above, each configuration item may be split into several lines
by use of the backslash character.

Type_A par_A
EIO_UNIT_TYPE
EIO_PARAM

Unit_A Unit_B
EIO_UNIT EIO_UNIT val_B
EIO_PARAM_VALUE

Signal_A Signal_B Signal_C Signal_C Signal_D


EIO_SIGNAL EIO_SIGNAL EIO_SIGNAL EIO_SIGNAL EIO_SIGNAL

Cross_A
EIO_CROSS

Figure 16 The different sections of the configuration file are hierarchically related.

RAPID Developer’s Manual 217


Elementary IO Configuration File System Parameters

The different sections are as listed below.

Section Name Description


EIO_UNIT_TYPE Type definition of a certain kind of elementary I/O unit with its
characteristics. It specifies the capacity/limits of valid data for
the unit (module/device).
EIO_PARAM Defines the available configuration parameters for a certain
unit type.
EIO_UNIT Definition and configuration of a specific physical elementary
I/O unit (module/device).
EIO_PARAM_VALUEDefines values for the configurable parameters of a specific
unit.
EIO_SIGNAL Defines and configures an elementary I/O signal
EIO_GROUP Defines and configures a set of IO signals into a group. The
group is handled as one signal
EIO_CROSS Defines and configures cross connections between elementary
I/O signals

Defining a IO module type section (EIO_UNIT_TYPE)


Different types of units (modules/devices) are defined in the EIO_UNIT_TYPE sec-
tion. For each type of unit the parameter specifies that unit’s overall constraints.

The robot system is delivered with a set of predefined unit types1. If a unit does not fit
within these types, a new type may be defined in the EIO_UNIT_TYPE section. This
is done by giving appropriate values to the parameters.

Example:

This configuration item defines a DSQC-328 I/O Board. The board has 16 digital inputs
and 16 digital outputs.

EIO_UNIT_TYPE:
-Name d328 -VendorId 75 -VendorName “ABB Robotics” -DeviceType 7 \
-ProductId 0 -ProductName “24 Vdc IO” -MajorRev 0 -MinorRev 0

Parameters of EIO_UNIT_TYPE
-Name Mandatory

The name that will be used to refer to this type in the rest of the configuration file

-VendorId Mandatory

A number that identifies the vendor of the I/O module.

1. The predefined unit types are listed in chapter .

218 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

-VendorName Optional

The name of the vendor in readable text.

-DeviceType Mandatory

A numeric code that identifies the type of I/O module.

-ProductId Mandatory

A number that identifies the product that this type defines.

-ProductName Optional

The name of the product in readable text.

-MajorRev Mandatory

The major part of the software revision of the I/O module

-MinorRev Mandatory

The minor part of the software revision of the I/O module

-MaxDigin Optional

Specifies the maximum number of digital inputs available on the unit type.

For modules connected to the BASE bus, this parameter is not used, since it is possible
to obtain this information from the I/O module itself.

-MaxDigout Optional

Specifies the maximum number of digital outputs available on the unit type.

For some modules connected to the BASE bus, this parameter is not used, since it is
possible to obtain this information from the I/O module itself.

-MaxAnin Optional

Specifies the maximum number of analog inputs available on the unit type.

For some modules connected to the BASE bus, this parameter is not used, since it is
possible to obtain this information from the I/O module itself.

-MaxAnout Optional

Specifies the maximum number of analog outputs available on the unit type.

For some modules connected to the BASE bus, this parameter is not used, since it is
possible to obtain this information from the I/O module itself.

RAPID Developer’s Manual 219


Elementary IO Configuration File System Parameters
-Param Optional

Name of the section that defines the parameters that is available on the unit type.

Some of the parameters must be given values, other may be left out and will then get
the default value. The table below defines the characteristics for each parameter in the
EIO_UNIT_TYPE section.

Default
Parameter Values Type
Value

-Name 1..20 String No Default


letters
-VendorId 0..65535 Integer No Default
-VendorName 1..20 String An empty
letters string
-DeviceType 0..255 Integer No Default
-ProductId 0..255 Integer No Default
-ProductName 1..20 String An empty
letters string
-MajorRev 0..255 Integer No Default
-MinorRev 0..255 Integer No Default
-MaxDigin 0..255 Integer 0
-MaxDigout 0..255 Integer 0
-MaxAnin 0..255 Integer 0
-MaxAnout 0..255 Integer 0
-Param 1..20 String An empty
letters string

Defining Parameters to a unit type. (EIO_PARAM)

Some I/O modules may have configurable parameters, that shall be down-loaded to the
unit by the robot controller at start-up. If so, these parameters are defined in the
EIO_PARAM section. The section is given a name as shown in this example.

Example:

D328_PARAM = EIO_PARAM:
-Name on_off_delay -Path “6, 20 0F 24 01 30 01,4,4” -Service 20 -DefValue 100

The name of this section is assigned to the -Param parameter of the EIO_UNIT_TYPE
section.

220 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

Example:

EIO_UNIT_TYPE:
-Name d328 -VendorId 75 -VendorName “ABB Robotics” -DeviceType 7 \
-ProductId 0 -ProductName “24 Vdc IO” -MajorRev 0 -MinorRev 0 \
-Param D328_PARAM

Each configuration item in the EIO_PARAM section describes one parameter by the
following parameters

Parameters of EIO_PARAM
-Name Mandatory

The name that will be used to refer to this parameter when giving it a specific value for
a specific unit as described in the EIO_PARAM_VALUE section below.

-Path Mandatory

A description used by the driver software when accessing the parameter.

The syntax of the value that shall be assigned to this parameter depends on what bus
the unit type is connected to.

For deviceNet compatible I/O modules, the value can be found in the EDS-file for the
I/O module.

-Service Mandatory

A numeric code that describes for the driver software how to set the parameter.

Valid values for this parameter depends on what bus the unit type is connected to.

For deviceNet compatible I/O modules, the value can be found in the EDS-file for the
I/O module.

-DefValue Mandatory

The value that will be assigned to the parameter if the parameter is omitted in the cor-
responding EIO_PARAM_VALUE section.

Defining a IO unit (EIO_UNIT)

The EIO_UNIT section is used to define and configure a physical IO unit (module/
device) of some type. The unit type has to be one of the types previosly defined in the
EIO_UNIT_TYPE section. Each configuration item describes a single unit by use of
the following parameters.

Parameters of EIO_UNIT
-Name Mandatory

The name that will be used to refer to this unit.

RAPID Developer’s Manual 221


Elementary IO Configuration File System Parameters

-Type Mandatory

Specifies the type of unit. The value of this parameter must be a name of an configura-
tion item defined in the EIO_UNIT_TYPE section.

-Bus Mandatory

Specifies what bus this unit is connected to. Available buses are listed in section .

-Address Mandatory

The address of the I/O module.

The syntax of the address depends on what bus the unit is connected to see below.

-Digin Optional

Specifies the amount of physical digital inputs to use on the unit.

If no digital input signals are used this parameter may be omitted

-Digout Optional

Specifies the amount of physical digital outputs to use on the unit.

If no digital output signals are used this parameter may be omitted

-Anin Optional

Specifies the amount of physical analogue inputs to use on the unit.

If no analogue input signals are used this parameter may be omitted

-Anout Optional

Specifies the amount of physical analogue outputs to use on the unit.

If no analogue output signals are used this parameter may be omitted

-PollRate Optional

Some units needs to be polled for update of input and output signals. The -PollRate
parameter specifies the time between two consecutive polls of a unit.

NOTE: The I/O modules produced by ABB Robotics Products that connects to the
BASE I/O Bus is event driven. With these modules the polling mechanism is used as
heart-beat only. It is recomended to use the default poll rate, 1 second, with these mod-
ules.

-TrustLevel Optional

222 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

The different levels of trust for a unit are:

Trust Level 0: The robot controller will not start until connection has been established
with all units with trust level 0.

Trust Level 1 (default if parameter omitted): If a unit with trust level equal to 1 is lost,
an error message will be generated. If signals that are located on the lost unit is
accessed, an error message will be reported and program execution will stop.

Trust Level 2: If a unit with trust level equal to 2 is lost, NO error message will be gen-
erated. If however signals, that are located on the lost unit, are accessed, an error mes-
sage will be reported and program execution will stop.

-Disabled Optional

Specifies that the I/O module will not be present on the bus at start-up.

It is not possible to disable a unit with trust level equal to 0.

-Signal Optional

This parameter is for internal use only.

-Param Optional

Name of the section that defines values for the configurable parameters of the unit.

Some of the parameters must be given values, other may be left out and will then get
the default value. The table below defines the characteristics for each parameter in the
EIO_UNIT section.

Parameter Values Type Default Value

-Name 1..20 letters String No Default


-Type The name of a String No Default
EIO_UNIT_TYPE
-Bus The name of an I/O String No Default
Bus
-Address Syntax depends on String No Default
selected I/O Bus
-Digin 1..MaxDigIn Integer MaxDigIn
-Digout 1..MaxDigOut Integer MaxDigOut
-Anin 1..MaxAnaIn Integer MaxAnaIn
-Anout 1..MaxAnaOut Integer MaxAnaOut
-PollRate 10..1000 Integer 1000 ms
-TrustLevel [0,1,2] Integer 1

RAPID Developer’s Manual 223


Elementary IO Configuration File System Parameters

Parameter Values Type Default Value

-Disabled True/False Boolean False


-Param 1..20 letters String An empty
string

Address Syntax

Units connected to the BASE I/O Bus uses Addresses between 0 and 62. User defined
units may use addresses between 10 and 62. The address shall be specified in decimal
form.

Units connected to the IBS I/O Bus .....???

Defining values for configurable unit parameters. (EIO_PARAM_VALUE)

The unit which is of a certain unit type may have a number of configurable parameters,
depending on whether that unit type has reference to a EIO_PARAM section as
described in the EIO_PARAM section above.

If a unit needs to give a parameter a value that differs from the default value of that
parameter, a EIO_PARAM_VALUE section needs to be defined. The section is given
a name, that is referred to by the -Param parameter in the EIO_UNIT section.

Example:

UNIT_A_VALUES = EIO_PARAM_VALUES:
-Name on_of_delay -Value 200

The section holds one configuration item for each parameter that is to be assigned a
value. The parameters are defined in the corresponding EIO_PARAM section.

Parameters of EIO_PARAM_VALUE
-Name Mandatory

The name of the parameter that shall be assigned a value.

The parameter name must match one of the configuration items in the EIO_PARAM
section.

-Value Mandatory

The parameter will be set to this value

Defining input and output signals. (EIO_SIGNAL)

The EIO_SIGNAL sections defines all the I/O signals, digital as well as analog, in the
system. These logical signals are attached to physical channels located on previously
defined units.
224 RAPID Developer’s Manual
System Parameters Elementary IO Configuration File

Note that several signals can be connected to the same physical channel. The same sig-
nals cannot, however, be connected to different physical channels.

The I/O signals are divided into groups for easier handling. Each group are given a sep-
arate section name as shown below.

User Signals

EIO_USER_SIGNAL = EIO_SIGNAL:

The section lists all the user defined signals.

Grouped Signals

EIO_GROUP_PHS = EIO_SIGNAL:

This section lists all the user defined signal groups. A signal group is a digital signal
with a length greater that one.

System Signals

EIO_SYSTEM_SIGNAL = EIO_SIGNAL:

These signals are defined by application software packages such as ArcWare, Spot-
Ware etc.

They shall not be altered by users.

All the groups described above have the same parameters, listed below:

Parameters of EIO_SIGNAL
-Name Mandatory

Name of the signal as it appear in the user programs.

-Type Mandatory

Specifies the type of the signal. The type is one of:


Digital Input Signal DI
Digital Output Signal DO
Analog Input Signal AI
Analog Output Signal AO
Group of Digital Input Signals GI
Group of Digital Output Signals GO

-Unit Mandatory

Specifies the unit that this signal is connected to.

-Phsig Mandatory

Specifies number of the physical signal on the unit. Each signal type is numbered from
one(1) and up.

RAPID Developer’s Manual 225


Elementary IO Configuration File System Parameters

-Length Mandatory

A logical signal may consist of a group of digital physical signals. The value of such a
signal will thus be a positive integer that is binary coded using the individual digital
signals as a basis.

The -Length parameter specifies the number of physical signals that shall be grouped
into this logical signal. A maximum of 16 digital physical signals may be grouped
together. All signals must reside on the same I/O unit.

The Length parameter must be one(1) for the signal types; DI, DO, AI and AO.

-Disabled Optional

This parameter is for internal use only.

-LogMax Optional

Specifies the logical maximum value of the signal. This parameter together with Log-
Min, PhMax and PhMin is used for scaling. See description below.

This parameter can NOT be used with the signal types: DI, DO, GI, DO.

-LogMin Optional

Specifies the logical minimum value of the signal. This parameter together with Log-
Max, PhMax and PhMin is used for scaling. See description below.

This parameter can NOT be used with the signal types: DI, DO, GI, DO.

-PhMax Optional

Specifies the maximum value of the physical signal. This parameter together with Log-
Max, LogMin and PhMin is used for scaling. See description below.

This parameter can NOT be used with the signal types: DI, DO, GI, DO.

226 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

-PhMin Optional

Specifies the minimum value of the physical signal. This parameter together with Log-
Max, LogMin and PhMax is used for scaling. See description below.

This parameter can NOT be used with the signal types: DI, DO, GI, DO.
Scaling of analog signals
Physical value of the
output signal (V, mA, etc.)

Physical Max

Logical Max
Logical value in the
Logical Min program

Physical Min

Figure 17 Diagram to show how analog signal values are scaled.

Logical max/min. is the maximum/minimum value that an


analog input or output can be set to, from a RAPID program or
from the teach pendant. The units are user define (e.g. meter or
minute).
Physical max/min. is the maximum/minimum physical value
to be set on the output or input. To get the physical limit for a
specified board see the Product Manual.
Example: An analog board is controlling a current source with
an amplification of 50 A/V and a max current of 500A. You
can have the following settings.
Physical Max = 10 V
Physical Min = 0 V
Logical Max = 500 A/V
Logical Min = 0 A/V
-FiltPas Optional

Specifies the time (in millisecs) that a digital input signal has to be passive (logical 0)
for the system to detect it as passive (logical 0).

This parameter can NOT be used with the signal types; DO, GI, GO, AI and AO

-FiltAct Optional

Specifies the time (in millisecs) that a digital input signal has to be active (logical 1)
for the system to detect it as active (logical 1).

A maximum of 10 different filter times can be used. If two signals are connected to the
same physical channel, the filter time for these signals must be the same. The filter
parameters must be set to 0 for analog signal and digital outputs.

RAPID Developer’s Manual 227


Elementary IO Configuration File System Parameters

-Acthigh Optional

If specified, the logical input signal is active when the physical input is passive and vice
versa.

This parameter can NOT be used with the signal types; DO, GI, GO, AI, AO.

-Invert Optional

If specified, the physical output signal will be inverted in relation to the logical output
signal.

This parameter can NOT be used with the signal types; DI, GI, GO, AI, AO.

-Pfailout Optional

Specifies what value the output signal shall obtain after a power fail.

This parameter can NOT be used with the signal types: DI, AI and GI.

-Store Optional

If specified, the output signals value will be stored on power-fail and restored at restart.

This parameter can NOT be used with the signal types: DI, AI and GI.

-Default Optional

Specifies the default value for the signal.

The default value is used for calculating cross connections when the actual signal state
is undefined. The signal state is undefined when the system has lost connection with
the unit to which the signal is connected.

-Set Optional

This parameter is for internal use only.

Some of the parameters must be given values, other may be left out and will then get
the default value. The table below defines the characteristics for each parameter in the
EIO_SIGNAL section.

Parameter Values Type Default Value

-Name 1..16 letters String No Default


-Type DI, DO, AI, AO, String No Default
GI, or GO
-Unit The name of a String No Default
EIO_UNIT
-Phsig 1..256 Integer No Default

228 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

Parameter Values Type Default Value


-Length 1..16 Integer 1
-Disabled True/False Boolean False
-LogMax 1.17549435e-38.. Float No Default
3.40282347e+38
-PhMax 1.17549435e-38.. Float No Default
3.40282347e+38
-LogMin 1.17549435e-38.. Float No Default
3.40282347e+38
-PhMin 1.17549435e-38.. Float No Default
3.40282347e+38
-FiltPas 100..10 000 Integer 1000 ms
-FiltAct 100..10 000 Integer 1000ms
-Acthigh True/False Boolean False
-Invert True/False Boolean False
-Pfailout 0..65535 or Integer/ 0
1.17549435e-38.. Floata
3.40282347e+38
-Store True/False Boolean False
-Default 0..65535 or Integer/ 0
1.17549435e-38.. Floata
3.40282347e+38
a. If the signal is a digital signal or a digital group, then this parameter is
integer. If the signal is analog, then this parameter is float.

Defining signal groups. (EIO_GROUP_SIGNAL = EIO_SIGNAL)

Digital signals can be grouped together and handled as if they were one signal. The
value of such a signal will thus be a positive integer that is binary coded using the indi-
vidual digital signals as a basis.

A group is defined by specifying a signal length greater than one. A group may be up
to 16 signals wide.

Example:

EIO_GROUP_PHS = EIO_SIGNAL:

-Name SignalA -Type GI -Unit UNITA -Phsig 1 -Length 16

RAPID Developer’s Manual 229


Elementary IO Configuration File System Parameters

Defining cross connections. (EIO_CROSS)

A digital input or output signal can be logically connected to one or several digital input
or output signals. This means that a cross-connected signal will automatically be
changed when the “activation” signal is changed.

Example:

EIO_CROSS:
-Lact di1 +di2 +do3 -Lres do1 + do2

A maximum of 20 signals can be cross connected. Make sure that the same signal is not
connected on both the ”Lact” and ”Lres” sides, in the same chain.

Parameters of EIO_CROSS
-Lact Mandatory

Lists the activation signals in this cross connection. A maximum of five signals is
allowed in the list.

As an option, boolean expressions maybe used together with the activators. The follow-
ing boolean functions maybe used:

AND &
OR !
NOT *

Example:

EIO_CROSS:
-Lact di1 & di2 ! *do3 -Lres do1 + do2

-Lres Mandatory

Lists the resultant signals in this cross connection. More that one signal may be the
resultant in a cross connection by putting a +-sign between the signals.

Predefined Buses and Unit types in the Elementary I/O System

Predefined Elementary I/O Buses

The robot controller is delivered with set of predefined elementary I/O buses that can
be used with the system. These are:

BASE The CAN based I/O field bus.


SIM The simulated bus used by simulated I/O units.

230 RAPID Developer’s Manual


System Parameters Elementary IO Configuration File

Predefined Elementary I/O Unit Types

The robot controller is delivered with a set of predefined Elementary I/O Unit Types.
These are:

For use with the CAN based I/O field Bus:


• d320 Digital 120 VAC I/O Module

• d327 A D Combi I/O Module

• d328 Digital 24 VDC I/O Module

• d331 Panel I/O Module

• d335 Analog I/O Module

• d351 IBS-S Slave Module

• d350 A-B Remote I/O Slave Module

• d352 Profibus DP Slave Module

RAPID Developer’s Manual 231


Topic: Communication System Parameters

Topic: Communication
The following parameters are found under the Communication topic:

- Specification of physical channels.


- Transmission protocols.
- Application protocols.

Defining physical channels

Parameters Description
Name Name of physical channel.
Type Type of physical channel (sio)
Channel Channel number (1 - 4).
Baud rate Baud rate for the serial channel (300 - 19200).
Parity Type of parity for serial channel. (Odd, Even, None).
No. of bits Number of data bits (7,8).
No. of stops bits Number of stop bits (1, 2).

Defining Transmission Protocol

Parameters Description
Name Name of the transmission protocol.
Type Type of transmission protocol (None, XON/XOFF, SLIP).
PhyChannel Name of the physical channel the protocol should use.
For Slip only:
Local Address Local address of the SLIP connection.
Remote Address Remote address of the SLIP connection.
PortNo The TCP protocol port number of the remote computer.

232 RAPID Developer’s Manual


System Parameters Topic: Communication

Defining Application Protocol


Parameters Description
Name Name of the application protocol.
Type Type of application protocol (RAP).
Trans. Prot. Name of the transmission protocol the protocol should use.
For RAP only:
Enable SysEvent See RAP Service Specification, Start-up Log Event.
(TRUE/FALSE)

RAPID Developer’s Manual 233


Topic: Communication System Parameters

234 RAPID Developer’s Manual


INDEX

D
17 Index data 2-89, 2-93, 2-95
Data Declarations 33
A
Data Objects 16
Add 3-103 Data Types 18, 25
Aggregates 43 datapos 4-121
Alias types 29 declaration
AliasIO 5-135 persistent 2-91, 2-94, 2-97
AND 3-109 variable 2-94, 2-96
ArgName 5-139 Defining a IO 9-218
Assignment Statement 51 dir 8-187
Atomic Types 26
E
B
Elementary IO Configuration 9-217
Backward Execution 17 Error Classification 20
backward handler 17 error handler 17
Backward Handlers 65 Error Handlers 67
bit manipulation 3-101 Error Recovery 17, 67
BitAnd 3-109 Exit Statement 54
BitCheck 3-107
F
BitClear 3-105
BitLSh 3-117 For Statement 57
BitNeg 3-115 Function calls 44
BitRSh 3-119 Function Declarations 63
BitXOr 3-113 Functions 5-151
BookErrNo 5-143
Break 85 G
Built in objects 2-89
Built-in Data Objects 87 GetDataVal 4-121, 4-129
Built-in Data Types 18 GetNextSym 4-123, 4-127
Built-in Routines 85 Goto Statement 53
byte 3-101, 3-103, 3-105, 3-107 I
C If Statement 56
CloseDir 8-193 Installed Data Types 18
Communication 9-232 Interrupt Manipulation 69
compact if statemen 57 Interrupt Recognition and Response 69
Connect Statement 56 Interrupts 17, 69
constant 2-89, 2-93 IO Configuration 9-217
Constant Declarations 37 ISleep 85
Constants 43 IsPers 85, 5-153
IsSysId 5-149
IsVar 86

RAPID Developer’s Manual 235


IWatch 85 Routine Declarations 59
Routines 16
L
S
Label Statement 50
LEFT SHIFT 3-117 scope
Lexical Elements 21 data scope 2-89, 2-95
Scope Rules 26, 62
M SetAllDataVal 4-133
MakeDir 189 SetDataSearch 4-123, 4-127
Module Declarations 74 SetDataVa 4-121
SetDataVal 4-131
N Statement Lists 50
Statement Termination 49
NEGATION 3-115 Statements 49
Num 23 StepBwdPath
Move backward one step on path 175
O
Syntax Summary 77
OpenDir 8-191 System Modules 76
Operators 46 system modules 15
Or 3-111
T
P
Task - Modules 15
Parameters 43 task buffer 15
persistent 2-89, 2-93 Task Modules 73
Persistent Declarations 36 task modules 15
PFDOVal 6-161 Test Statement 58
PFGOVal 6-163 TextGet 5-147
PFIOResto 6-159 TextTabGet 5-145
PFRestart 6-165 Trap Routines 70
Placeholders 19 Trynext Statement 55
Predefined Data Objects 34
U
Present 85
Procedure Call 51 User-defined Data Types 19
Procedure Declarations 62
V
R
variable 2-89, 2-93
Raise Statement 54 Variable Declarations 35
ReadCfgData
Read configuration data 155 W
Record Types 27
RemoveDir 195 While Statement 58
RemoveFile 215 WriteCfgData
Reserved Words 22 Write configuration data 157
Retry Statement 55 X
Return Statement 53
RIGHT SHIFT 3-119 XOR 3-113

236 RAPID Developer’s Manual