Operating Manual: Introduction To RAPID
Operating Manual: Introduction To RAPID
Operating Manual: Introduction To RAPID
Introduction to RAPID
Controller software IRC5
RobotWare 5.0
Operating manual
Introduction to RAPID
RobotWare 5.0
Document ID: 3HAC029364-001
Revision: -
The information in this manual is subject to change without notice and should not be
construed as a commitment by ABB. ABB assumes no responsibility for any errors that
may appear in this manual.
Except as may be expressly stated anywhere in this manual, nothing herein shall be
construed as any kind of guarantee or warranty by ABB for losses, damages to persons
or property, fitness for a specific purpose or the like.
In no event shall ABB be liable for incidental or consequential damages arising from
use of this manual and products described herein.
This manual and parts thereof must not be reproduced or copied without ABB's written
permission, and contents thereof must not be imparted to a third party nor be used for
any unauthorized purpose. Contravention will be prosecuted.
Additional copies of this manual may be obtained from ABB at its then current charge.
Table of Contents
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Product documentation, M2004 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1 RAPID basics
11
1.2.1 Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.2 Persistent variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3 Controlling the program flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3.1 IF THEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3.2 Examples with logical conditions and IF statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.3.3 FOR loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.3.4 WHILE loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.4 Rules and recommendations for RAPID syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
23
3 Structure
35
43
4.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2 Composite data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5 RAPID instructions and functions
47
5.1 Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6 What to read next
49
3HAC029364-001 Revision: -
51
Table of Contents
3HAC029364-001 Revision: -
Overview
Overview
About This Manual
This manual is intended as a first introduction to RAPID. A lot of functionality in RAPID is
left out, but the most essential parts are described so that it can be easily understood for
everybody. This manual does not make you an expert RAPID programmer, but it can help you
understand the concept of programming with RAPID. The details can always be found in the
reference manuals.
Usage
This manual should be read before starting to program. It does not contain everything you
need to know, but you need to be familiar with most things in this manual, before starting to
write a RAPID program.
This manual does not replace the educational courses in RAPID, but can complement it.
Who Should Read This Manual?
This manual is intended for someone with no previous experience in programming, e.g. a
robot operator who wants to learn how to program the robot.
Prerequisites
There are no prerequisites for this manual.
Organization of Chapters
The manual is organized in the following chapters:
Chapter
Contents
1. RAPID basics
3. Structure
References
Reference
Document Id
3HAC16580-1
3HAC16581-1
3HAC16585-1
3HAC16590-1
Overview
Continued
Revisions
Revision Description
First edition
3HAC029364-001 Revision: -
Safety information
Part list
Circuit diagrams
The following manuals describe the robot software in general and contain relevant reference
information:
RAPID Instructions, Functions and Data types: Description and syntax for all
RAPID instructions, functions and data types.
Application manuals
Specific applications (for example software or hardware options) are described in
Application manuals. An application manual can describe one or several applications.
An application manual generally contains information about:
What is included (for example cables, I/O boards, RAPID instructions, system
parameters, CD with PC software)
3HAC029364-001 Revision: -
RobotStudio
3HAC029364-001 Revision: -
Safety
Safety
Safety of personnel
A robot is heavy and extremely powerful regardless of its speed. A pause or long stop in
movement can be followed by a fast hazardous movement. Even if a pattern of movement is
predicted, a change in operation can be triggered by an external signal resulting in an
unexpected movement.
Therefore, it is important that all safety regulations are followed when entering safeguarded
space.
Safety regulations
Before beginning work with the robot, make sure you are familiar with the safety regulations
described in Operating manual - IRC5 with FlexPendant.
3HAC029364-001 Revision: -
Terminology
Terminology
About the terms
This manual is generally written for beginners, regarding both programming and robots.
However, some terms are used that may be familiar only to those with some knowledge about
programming and/or industrial robots. These terms are described in this terminology.
Terms
Description
FlexPendant
Robot controller
Syntax
Term
10
3HAC029364-001 Revision: -
1 RAPID basics
1.1. About RAPID
1 RAPID basics
1.1. About RAPID
What is RAPID
If you want a computer to do something, a program is required. RAPID is a programming
language for writing such a program.
The native language of computers consists of only zeros and ones. This is virtually impossible
for humans to understand. Therefore computers are taught to understand a language that is
relatively easy to understand - a high level programming language. RAPID is a high level
programming language, it uses some English words (like IF and FOR) to make it
understandable for humans.
Simple RAPID program example
Let us look at a simple example to see what a RAPID program can look like:
MODULE MainModule
VAR num length;
VAR num width;
VAR num area;
PROC main()
length := 10;
width := 5;
area := length * width;
TPWrite "The area of the rectangle is " \Num:=area;
END PROC
ENDMODULE
This program will calculate the area of a rectangle and write on the FlexPendant:
3HAC029364-001 Revision: -
11
1 RAPID basics
1.2.1. Variables
Description
num
string
bool
A boolean (logical) variable. Can only have the values TRUE or FALSE.
All other data types are based on these three. If you understand them, how to perform
operations on them and how they can be combined to more complex data types, you can easily
understand all data types.
Variable characteristics
A variable contains a data value. If the program is stopped and started the variable keeps its
value, but if the program pointer is moved to main the variable data value is lost.
Declaring a variable
Declaring a variable is the way of defining a variable name and which data type it should
have. A variable is declared using the keyword VAR, according to the syntax:
VAR datatype identifier;
Example
VAR num length;
VAR string name;
Assigning values
A value is assigned to a variable using the instruction :=
length := 10;
name := "John"
finished := TRUE;
Note that := is not an equal sign. It means that the expression to the right is passed to the
variable on the left. There can only be a variable to the left of :=
For example, the following is a correct RAPID code resulting in reg1 having the value 3:
reg1 := 2;
reg1 := reg1 + 1;
The assignment can be made at the same time as the variable declaration:
VAR num length := 10;
VAR string name := "John";
VAR bool finished := TRUE;
12
3HAC029364-001 Revision: -
1 RAPID basics
1.2.2. Persistent variables
Example
Consider the following code example:
PERS num nbr := 1;
PROC main()
nbr := 2;
ENDPROC
If this program is executed, the initial value is changed to 2. The next time the program is
executed the program code will look like this:
PERS num nbr := 2;
PROC main()
nbr := 2;
ENDPROC
3HAC029364-001 Revision: -
13
1 RAPID basics
1.2.3. Constants
1.2.3. Constants
What is a constant?
A constant contains a value, just like a variable, but the value is always assigned at declaration
and after that the value can never be changed. The constant can be used in the program in the
same way as a variable, except that it is not allowed to assign a new value to it.
Constant declaration
The constant is declared using the keyword CONST followed by data type, identifier and
assignment of a value.
CONST num gravity := 9.81;
CONST string greating := "Hello"
Using a constant instead of writing the value directly in the program is better if you need to
update the program with another value on the constant. Then you only have to change in one
place and can be sure you have not forgotten any occurrence of the value.
14
3HAC029364-001 Revision: -
1 RAPID basics
1.2.4. Operators
1.2.4. Operators
Numerical operators
These operators operate on the data type num and return the data type num. I.e. in the examples
below, variables reg1, reg2 and reg3 are of data type num.
Operator
Description
Example
Addition
Subtraction
Unary minus
Multiplication
Division
Relational operators
These operators return the data type bool.
In the examples, reg1 and reg2 are data type num while flag1 is bool.
Operator
Description
Example
equal to
<
less than
>
greater than
<=
>=
<>
not equal to
Logical operators are often used together with the IF instruction. For code examples, see
Examples with logical conditions and IF statements on page 18.
String operator
Operator
Description
Example
String concatenation
3HAC029364-001 Revision: -
15
1 RAPID basics
1.3.1. IF THEN
ELSE
An IF statement can also contain program code to be executed if the condition is false.
Example
In this example the string string1 is written on the FlexPendant if it is not an empty string.
If string1 is an empty string, then the text "The string is empty" is written.
VAR string string1 := "Hello";
IF string1 <> "" THEN
TPWrite string1;
ELSE
TPWrite "The string is empty";
ENDIF
3HAC029364-001 Revision: -
If the logical condition in the IF statement is true, then the program code between the
keywords THEN and ELSE is executed. If the condition is false, then the code between the
keywords ELSE and ENDIF is executed.
1 RAPID basics
1.3.1. IF THEN
Continued
ELSEIF
Sometimes you have more than two alternative program sequences. You can then use ELSEIF
to set up several alternatives.
Example
In this example different texts are written depending on the value on the variable time.
VAR num time := 38.7;
IF time < 40 THEN
TPWrite "Part produced at fast rate";
ELSEIF time < 60 THEN
TPWrite "Part produced at average rate";
ELSE
TPWrite "Part produced at slow rate";
ENDIF
Note that since the first condition is true the first text will be written. The two other texts will
not be written (even though it is true that time is less than 60).
3HAC029364-001 Revision: -
17
1 RAPID basics
1.3.2. Examples with logical conditions and IF statements
Example
If it takes more than 60 seconds to produce a part, write a message on the FlexPendant. If the
boolean variable full_speed is FALSE the message will tell the operator to increase the
robot speed. If full_speed is TRUE, the message will ask the operator to examine the reason
for the slow production.
VAR num time := 62.3;
PROC main()
IF time > 60 THEN
IF full_speed THEN
TPWrite "Examine why the production is slow";
ELSE
TPWrite "Increase robot speed for faster production";
ENDIF
ENDIF
ENDPROC
18
3HAC029364-001 Revision: -
1 RAPID basics
1.3.3. FOR loop
The counter does not have to be declared, but acts as a numeric variable inside the FOR loop.
The first time the code is executed, the counter has the value specified by the startvalue. The
value of the counter is then increased by 1 for each time the code is executed. The last time
the code executes is when the counter is equal to endvalue. After that, the execution continues
with the programming code after ENDFOR.
Using the counter value
The value of the counter can be used in the FOR loop.
For example, calculating the sum of all numbers from 1 to 50 (1+2+3+...+49+50) can be
programmed like this:
VAR num sum := 0;
FOR i FROM 1 TO 50 DO
sum := sum + i;
ENDFOR
3HAC029364-001 Revision: -
19
1 RAPID basics
1.3.4. WHILE loop
If the condition is false to begin with, the code sequence will never be executed. If the
condition is true, the code sequence will be executed repeatedly until the condition is no
longer true.
Example
The following program code will add numbers (1+2+3+...) until the sum reaches 100.
VAR num sum := 0;
VAR num i := 0;
WHILE sum <= 100 DO
i := i + 1;
sum := sum + i;
ENDWHILE
Heavy loops (with lots of calculations and writing on the FlexPendant, without move
instructions) can require some waiting instruction even if the number of loops are limited.
WHILE TRUE DO
! Some code
...
! Wait instruction that waits for 1 second
WaitTime 1;
ENDWHILE
Note that move instructions work as waiting instructions, since the execution does not
continue until the robot has reached its target.
20
3HAC029364-001 Revision: -
If the condition never becomes false the loop will continue constantly and consume vast
amount of computer power. It is allowed to write an eternal loop, but then it must contain
some waiting instruction that allows the computer to perform other tasks in the meantime.
1 RAPID basics
1.4.1. General RAPID syntax rules
Assigning values:
area := length * width;
Exceptions
Some special instructions do not end with a semicolon. Instead there are special keywords to
indicate where they end.
Example of instructions that do not end with semicolon:
Instruction keyword
Terminating keyword
IF
ENDIF
FOR
ENDFOR
WHILE
ENDWHILE
PROC
ENDPROC
These keywords are very important to create a good structure of a RAPID program. They are
thoroughly described later in this manual.
Comments
A line starting with ! will not be interpreted by the robot controller. Use this to write
comments about the code.
Example
! Calculate the area of the rectangle
area := length * width;
3HAC029364-001 Revision: -
21
1 RAPID basics
1.4.2. Recommendations for RAPID code
Note that it is easy to see where the IF statement starts and ends. If you would have several
IF statements and no indentations, it would be virtually impossible to find which ENDIF
corresponds to which IF.
22
3HAC029364-001 Revision: -
where:
MoveL is an instruction that moves the robot linearly (in a straight line) from its current
p10 specifies the position that the robot shall move to.
v1000 specifies that the speed of the robot shall be 1000 mm/s.
fine specifies that the robot shall go exactly to the specified position and not cut any
corners on its way to the next position.
tool0 specifies that it is the mounting flange at the tip of the robot that should move
ToPoint
The destination point defined by a constant of data type robtarget. When programming
with the FlexPendant you can assign a robtarget value by pointing out a position with the
robot. When programming offline, it can be complicated to calculate the coordinates for a
position.
robtarget will be explained further later, in section Composite data types on page 44. For
now, let us just accept that the position x=600, y=-100, z=800 can be declared and assigned
like this:
CONST robtarget p10 := [ [600, -100, 800], [1, 0, 0, 0], [0, 0, 0,
0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];
Speed
The speed of the movement defined by a constant of data type speeddata. There are plenty
of predefined values, such as:
Predefined speeddata
Value
v5
5 mm/s
v100
100 mm/s
v1000
1000 mm/s
23
Value
vmax
A complete list of predefined speeddata values is found in Technical reference manual RAPID Instructions, Functions and Data types, section Data types and speeddata.
When using a predefined value, it should not be declared or assigned.
Zone
Specifies a corner zone defined by a constant of data type zonedata. There are many
predefined values, such as:
Predefined zonedata
Value
fine
z10
z50
A complete list of predefined zonedata values is found in Technical reference manual RAPID Instructions, Functions and Data types, section Data types and zonedata.
When using a predefined value, it should not be declared or assigned.
The following RAPID instructions will result in the robot path shown below:
MoveL p10, v1000, z50, tool0;
xx0700000358
Tool
Specifies the tool that the robot is using, defined by a persistent variable of data type
tooldata. If a welding gun, glue gun or a pen is attached to the robot, we want to program
the ToPoint for the tip of this tool. This is done automatically if a tooldata is declared,
assigned and used in the MoveL instruction.
tool0 is a predefined tool, representing the robot without any tool mounted on it, and should
not be declared or assigned. Any other tool should be declared and assigned before being
used.
24
3HAC029364-001 Revision: -
xx0700000397
For information about how to define a coordinate system, see Technical reference manual RAPID Instructions, Functions and Data types, section Data types and wobjdata.
For more information about coordinate systems, see Technical reference manual - RAPID
overview, section Coordinate systems.
3HAC029364-001 Revision: -
25
xx0700000362
3HAC029364-001 Revision: -
xx0700000363
ENDPROC
3HAC029364-001 Revision: -
27
Use MoveJ to move the robot to a point in the air close to where the robot will work. A MoveL
instruction does not work if, for example, the robot base is between the current position and
the programmed position, or if the tool reorientation is too large. MoveJ can always be used
in these cases.
The syntax of MoveJ is analog with MoveL.
Example
MoveJ p10, v1000, fine, tPen;
MoveC
MoveC is used to move the robot circularly in an arc.
Example
MoveL p10, v500, fine, tPen;
MoveC p20, p30, v500, fine, tPen;
xx0700000364
28
3HAC029364-001 Revision: -
If the calculation of reg1 would not start until the robot was at p10, then the robot would
have to stop there and wait for the next move instruction. What actually happens is that the
code is executed ahead of the robot movement. reg1 is calculated and the robot path in the
corner zone is calculated before the robot reaches p10.
How does this affect my program
In many cases the exact time of execution does not affect the program. There are however
examples of when it does affect the program.
If you want to draw a line with a spray gun between p10 and p20, and write the program like
this:
MoveL p10, v300, z10, tspray;
! Start spraying
SetDO do1, 1;
MoveL p20, v300, z10, tspray;
! Stop spraying
SetDO do1, 0;
MoveL p30, v300, fine, tspray;
Copyright 2007 ABB. All rights reserved.
xx0700000387
Solution
If you want to set signals in corner zones, and not use fine, then there are special instructions
for solving this, e.g. MoveLDO, TriggL and DispL. For more information about these
instructions, see Technical reference manual - RAPID Instructions, Functions and Data types.
29
There is also a limitation as to how many (and complex) calculations the robot controller can
calculate in between move instructions with corner zones. This is mainly a problem when
calling procedures after a move instruction with a corner zone.
30
3HAC029364-001 Revision: -
Digital output
A digital output signal can have the values 0 or 1. The RAPID program can set the value for
a digital output signal, and thus affect external equipment. The value of a digital output signal
is set with the instruction SetDO.
Example
The robot has a grip tool that can be closed with the digital output signal do_grip. The robot
moves to the position where the pen is and closes the gripper. The robot then moves to where
it shall draw, now using the tool tPen.
MoveJ p0, vmax, fine, tGripper;
SetDO do_grip, 1;
MoveL p10, v1000, fine, tPen;
3HAC029364-001 Revision: -
31
xx0700000374
3HAC029364-001 Revision: -
ENDIF
xx0700000376
If the user selects "Square", the numeric variable answer gets the value 1. If the user selects
"Triangle", the numeric variable answer gets the value 2.
Five functions keys can be specified. If a key is not being used, write stEmpty instead of the
text on the button.
TPReadNum
TPReadNum allows the operator to write a number on the FlexPendant, rather than just
making a choice.
VAR num answer;
TPReadNum answer, "How many times shall I draw the figure?";
FOR i FROM 1 TO answer DO
! code to draw figure
ENDFOR
33
xx0700000378
The numeric variable answer gets the value that the operator types.
34
3HAC029364-001 Revision: -
3 Structure
3.1. RAPID procedure
3 Structure
3.1. RAPID procedure
What is a procedure
So far, all the RAPID code examples we have looked at have only executed code in the
procedure main. The execution automatically starts in the procedure named main, but there
can be several procedures.
A procedure must be declared with the keyword PROC followed by the procedure name, the
procedure arguments and the program code that the procedure should execute. A procedure
is called from another procedure (except main, which is automatically called when the
program starts).
Example
If we want to draw four squares of different sizes, we could write almost the same program
code four times. This would result in a lot of code and make the program difficult to
understand. A much more efficient way to write this program is to make a procedure that
draws the square, and let the main procedure call this procedure four times.
PERS tooldata tPen:= ...
CONST robtarget p10:= ...
PROC main()
! Call the procedure draw_square
draw_square 100;
draw_square 200;
draw_square 300;
draw_square 400;
ENDPROC
PROC draw_square(num side_size)
Copyright 2007 ABB. All rights reserved.
35
3 Structure
3.1. RAPID procedure
Continued
Procedure arguments
When declaring a procedure, all arguments are declared inside parenthesis after the procedure
name. This declaration contains data type and argument name for each argument. The
argument gets its value from the procedure call and the argument acts as a variable inside the
procedure (the argument cannot be used outside its procedure).
PROC main()
my_procedure 14, "Hello", TRUE;
ENDPROC
PROC my_procedure(num nbr_times, string text, bool flag)
...
ENDPROC
Inside the procedure my_procedure above, nbr_times has the value 14, text has the
value "Hello" and flag has the value TRUE.
When calling the procedure, the order of the arguments is important to give the right value to
the right argument. No parenthesis are used in the procedure call.
Variables declared inside the procedure
Variables declared inside a procedure only exist inside that procedure. I.e. in the example
above, p10 can be used in all procedures in this module, but p20, p30 and p40 can only be
used in the procedure draw_square.
36
3HAC029364-001 Revision: -
3 Structure
3.2. Modules
3.2. Modules
About modules
A RAPID program can consist of one or several modules. Each module can contain one or
several procedures.
The small and simple programs that are shown in this manual only use one module. In a more
complex programming environment, some standard procedures, used by many different
programs, can be placed in a separate module.
Example
The module MainModule contains code that is specific for this program and specifies what
the robot should do in this particular program. The module figures_module contains
standard code that can be used by any program that wants to draw a square, triangle or circle.
MODULE MainModule
...
draw_square;
...
ENDMODULE
MODULE figures_module
PROC draw_square()
...
ENDPROC
PROC draw_triangle()
...
ENDPROC
PROC draw_circle()
...
ENDPROC
ENDMODULE
Program modules
A program module is saved with the file ending .mod, e.g. figures_module.mod.
It makes no difference for the robot controller if the program is written in several modules.
The reason to use several program modules is only to make the program easier to grasp and
easier to reuse for the programmers.
There can only be one program active on the robot controller, i.e. only one of the modules can
contain a procedure named main.
System modules
A system module is saved with the file ending .sys, e.g. system_data_module.sys.
Data and procedures that should be kept in the system even if the program is changed should
be placed in a system module. For example, if a persistent variable of type tooldata is
declared in a system module, a recalibration of the tool is preserved even if a new program is
loaded.
3HAC029364-001 Revision: -
37
3 Structure
3.3. Structured design
Example
Problem description
Create a RAPID program that can draw squares or triangles on a piece of paper. Let the
operator decide if it is a square or triangle that should be drawn next. When the robot is
finished drawing the figure the user shall be able to make the same selection again until the
operator taps on a Quit button.
Between drawings, check if di1 is 1. If it is, move to a pencil sharpener and set do1 to 1 to
start the sharpener and slowly move the pencil into the sharpener. Normally we would need
to redefine the tool since it gets shorter when it is sharpened, but we will skip that step in this
example.
Design structure
en0700000381
3HAC029364-001 Revision: -
When the robot has drawn 10 figures on the same paper, write a message that the paper should
be replaced and wait for the operator to tap an OK button.
3 Structure
3.3. Structured design
Continued
Program code
MODULE MainModule
PERS tooldata tPen := [ TRUE, [[200, 0, 30], [1, 0, 0 ,0]], [0.8,
[62, 0, 17], [1, 0, 0, 0], 0, 0, 0]];
CONST robtarget p10 := [ [600, -100, 800], [0.707170, 0,
0.707170, 0], [0, 0, 0, 0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9,
9E9] ];
CONST robtarget pSharp1 := [ [200, 500, 850], [1, 0, 0, 0], [0,
0, 0, 0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];
PERS num count := 0;
PROC main()
user_selection;
IF count >= 10 THEN
change_paper;
! Reset count
count := 0;
ENDIF
IF di=1 THEN
sharpen_pencil;
ENDIF
ENDPROC
PROC user_selection()
VAR num answer;
TPReadFK answer, "Select which figure to draw", "Square",
"Triangle", "Quit", stEmpty, stEmpty;
IF answer = 1 THEN
draw_square;
count := count + 1;
ELSEIF answer = 2 THEN
draw_triangle;
Copyright 2007 ABB. All rights reserved.
count := count + 1;
ELSE
quit;
ENDIF
ENDPROC
39
3 Structure
3.3. Structured design
Continued
PROC draw_square()
VAR robtarget p20;
VAR robtarget p30;
VAR robtarget p40;
! Define points that give a square with the side 200 mm
p20 := Offs(p10, 0, 200, 0);
p30 := Offs(p10, 200, 200, 0);
p40 := Offs(p10, 200, 0, 0);
MoveL p10, v200, fine, tPen;
MoveL p20, v200, fine, tPen;
MoveL p30, v200, fine, tPen;
MoveL p40, v200, fine, tPen;
MoveL p10, v200, fine, tPen;
ENDPROC
PROC draw_triangle()
VAR robtarget p20;
VAR robtarget p30;
! Define points for the triangle
p20 := Offs(p10, 0, 200, 0);
p30 := Offs(p10, 200, 100, 0);
MoveL p10, v200, fine, tPen;
MoveL p20, v200, fine, tPen;
MoveL p30, v200, fine, tPen;
MoveL p10, v200, fine, tPen;
ENDPROC
3HAC029364-001 Revision: -
PROC quit()
3 Structure
3.3. Structured design
Continued
PROC sharpen_pencil()
VAR robtarget pSharp2;
VAR robtarget pSharp3;
pSharp2 := Offs(pSharp1, 100, 0, 0);
pSharp3 := Offs(pSharp1, 120, 0, 0);
! Move quickly to position in front of sharpener
MoveJ pSharp1, vmax, z10, tPen;
! Place pencil in sharpener
MoveL pSharp2, v500, fine, tPen;
! Start the sharpener
SetDO do1, 1;
! Slowly move into the sharpener
MoveL pSharp3, v5, fine, tPen;
! Turn off sharpener
SetDO do1, 0;
! Move out of sharpener
MoveL pSharp1, v500, fine, tPen;
ENDPROC
ENDMODULE
Note that in production a program is normally run in continuous mode, so that when the
execution reaches the end of the main procedure it starts from the beginning again. If this is
not used, a WHILE loop can be used to repeat everything inside the main procedure.
3HAC029364-001 Revision: -
41
3 Structure
42
3HAC029364-001 Revision: -
Assigning values
An array can be assigned all its values at once. When assigning the whole array the values are
surrounded by [ ] and separated by commas.
my_array := [5, 10, 7];
It is also possible to assign a value to one of the elements in an array. Which element to assign
a value to is specified inside { }.
my_array{3} := 8;
Example
This example use a FOR loop and arrays to ask the operator for the estimated production time
for each part. It is a very efficient way to write code compared to having one variable for each
part and not be able to use the FOR loop.
VAR num time{3};
VAR string part{3} := ["Shaft", "Pipe", "Cylinder"];
VAR num answer;
PROC main()
FOR i FROM 1 TO 3 DO
TPReadNum answer, "Estimated time for " + part{i} + "?";
time{i} := answer;
ENDFOR
ENDPROC
3HAC029364-001 Revision: -
43
The different components have names instead of numbers. The components in pos are named
x, y and z. The value in one component is identified with the variable name, a point and the
component name:
pos1.z := 850;
orient
The data type orient specifies the orientation of the tool. The orientation is specified by four
numerical values, named q1, q2, q3 and q4.
VAR orient orient1 := [1, 0, 0, 0];
TPWrite "The value of q1 is " \Num:=orient1.q1;
pose
A data type can be composed of other composite data types. An example of this is the data
type pose, which consists of one pos named trans and one orient named rot.
VAR pose pose1 := [[600, 100, 800], [1, 0, 0, 0]];
VAR pos pos1 := [650, 100, 850];
pose1.pos := pos1;
orient1 := pose1.rot;
pose1.pos.z := 875;
robtarget
robtarget is too complex a data type to explain in detail here, so we will settle for a brief
explanation.
robtarget consists of four parts:
Data type
Name
Description
pos
trans
x, y and z coordinates
orient
rot
Orientation
confdata
robconf
extjoint
extax
3HAC029364-001 Revision: -
Detailed descriptions
Detailed descriptions of these data types and many more can be found in Technical reference
manual - RAPID Instructions, Functions and Data types, section Data types.
3HAC029364-001 Revision: -
45
46
3HAC029364-001 Revision: -
Other RAPID instructions perform complicated processes that could not have been
programmed without these premade instructions. For example MoveL, which may seem like
a simple instruction but in the background there are calculations of how much to move each
robot axis and how much current each motor should have. Because the program code for these
calculations is already made, all you have to do is write a simple instruction call.
MoveL p10, v1000, fine, tool0;
Detailed descriptions
3HAC029364-001 Revision: -
47
5.2. Functions
What is a function
A RAPID function is similar to an instruction but returns a value.
! Calculate the cosine of reg2
reg1 : = Cos(reg2);
Since the function returns a value, the result of the function can be assigned to a variable.
The arguments in a function call are written inside parenthesis and are separated with
commas.
Include a function call in a statement
Anywhere, where a value can be used, a function returning a value of the same data type can
be used.
! Perform something if reg1 is smaller than -2 or greater than 2
IF Abs(reg1) > 2 THEN
...
! Convert the num time to string and concatenate with other strings
string1 := name + "s time was " + NumToStr(time);
Detailed descriptions
Detailed descriptions of functions can be found in Technical reference manual - RAPID
Instructions, Functions and Data types, section Functions.
48
3HAC029364-001 Revision: -
More detailed information about the functionality Technical reference manual mentioned in this manual
RAPID overview
What instructions are there for a specific category
(e.g. move instructions or clock functionality)
Descriptions of more advanced functionality (e.g.
interrupts or error handling)
3HAC029364-001 Revision: -
49
50
3HAC029364-001 Revision: -
Index
output signal 31
arguments 36
arrays 43
assigning values 12
B
base coordinate system 25
base frame 25
bool 12
C
comments 21
communication 31, 32
complex data types 44
computer performance 20
conditional execution 16, 20
constants 14
coordinate systems 25
corner zones 27, 29
D
data types 12, 44
declaration of variables 12
design 38
digital input 31
digital output 31
R
RAPID functions 48
RAPID instructions 47
RAPID procedure 35
repetition 19, 20
robot controller 10
robtarget 23, 44
S
safety 9
semicolon 21
signals 31
speeddata 23
string 12
syntax 10
ELSE 16
ELSEIF 17
eternal loops 20
terminology 10
tooldata 24
TPReadFK 33
TPReadNum 33
TPWrite 32
FlexPendant 10, 32
FOR 19
functions 48
variable declaration 12
variables 12
WHILE 20
WObj 25
work object 25
performance 20
pos 44
pose 44
PROC 35
procedure 35
I/O signals 31
IF 16, 18
indentations 22
input signal 31
instructions 47
Z
zonedata 24
L
logical conditions 15, 16, 18
loop 19, 20
M
main 35
module 37
move instructions 23
MoveC 28
MoveJ 28
MoveL 23, 26
N
num 12
O
operators 15
orient 44
3HAC029364-001 Revision: -
51
Index
52
3HAC029364-001 Revision: -
3HAC029364-001, Revision -, en
ABB Robotics
S-721 68 VSTERS
SWEDEN
Telephone: +46 (0) 21 344000
Telefax:
+46 (0) 21 132592