1、 KUKA China | 20.06.2016 | Seite 1 PM Team KUKA机器人变量说明文档 KUKA China | 20.06.2016 | page 2 Simple data types KUKA China | 20.06.2016 | page 3 Simple data types KUKA China | 20.06.2016 | page 4 Definition of “variables” In addition to the use of constants (digits, characters, etc.), memory location
2、s are also defined in the robot controller in which these values can be stored. This stored information can thus be retrieved at various points in the program for evaluation and further processing. A variable is a fixed memory area, whose contents can be addressed via the variable name. Example: . P
3、art_counter = 37 . Content of the variable Variable name KUKA China | 20.06.2016 | page 5 Declaration of variables DECL Data_Type Variable_Name Variable declarations always have the following syntax: Def Main( ) DECL INT part_counter INI . End Example: KUKA China | 20.06.2016 | page 6 Variables an
4、d names Variable names in KRL can have a maximum length of 24 characters. can consist of letters (A-Z), numbers (0-9) and the signs _ and $. must not begin with a number. must not be a keyword. KUKA China | 20.06.2016 | page 7 Simple data types “A” TRUE 1.43 32 Example ASCII character 1-255 TRUE, F
5、ALSE +/-1.1E-38 . +/-3.4E+38 -231 . (231-1) Range of values 1 character Logic state Floating-point number Integer Meaning CHAR BOOL REAL INT Keyword Character Boolean Real Integer Data type KUKA China | 20.06.2016 | page 8 Basic structure of a robot program DEF NAME( ) END ;- Declaration section -
6、. ;- Initialization section - . ;- Instruction section - . KUKA China | 20.06.2016 | page 9 Activating the DEF line Variables must be declared before the INI line In order to set syntax before the INI line, the DEF line must be activated KUKA China | 20.06.2016 | page 10 Declaration and value assi
7、gnment DEF MAIN_PROGRAM( ) ;- Declaration section - DECL INT PART ;- Initialization section - INI ;Initialization of acceleration and velocity ;- Instruction section - PART=58 ;Value assignment, decimal PART=B111010 Value assignment, binary PART=H3A ;Value assignment, hexadecimal . END Value assignm
8、ents are made in the program advance run! KUKA China | 20.06.2016 | page 11 Lifetime of variables in the SRC file . are only recognized in their own program. . are not recognized in local subprograms. DEF HP1( ) DECL INT CUBE INI CUBE=0 END Variables declared . in the corresponding DAT file . are o
9、nly recognized in their own program, i.e. in the main program and in local subprograms. DEFDAT HP1( ) DECL INT CUBE=0 . ENDDAT in the $CONFIG.DAT file . are recognized in every program. . can be called during program execution. DEFDAT $CONFIG DECL INT CUBE=0 . ENDDAT KUKA China | 20.06.2016 | page 1
10、2 Declaration of constants DECL CONST Datentyp Variable_Name Constant declarations always have the following syntax and they could only declared in a data list: DEFDAT Main( ) Decl CONST REAL PI = 3.14159 . END Example: You can not manipulate Constants in the SRC-file. It causes a error message. KU
11、KA China | 20.06.2016 | page 13 Arrays with simple data types and counting loop KUKA China | 20.06.2016 | page 14 Arrays KUKA China | 20.06.2016 | page 15 Arrays (one-dimensional) Creation: DECL Data_Type Variable_NameNumber of array elements Work: Variable_NameIndex = Value_Assignment Syntax: Ex
12、ample: DEF MAIN_PROGRAM( ) DECL REAL measurement3 INI measurement1 = 17.5 measurement2 = 35.7 measurement3 = 67.2 . END KUKA China | 20.06.2016 | page 16 Simple counting loop FOR Counter = Start TO End Statement ENDFOR DEF INIT_OUTPUTS ( ) DECL INT COUNTER INI FOR COUNTER=1 TO 10 ;Set output 1-10 t
13、o FALSE $OUTx=FALSE ENDFOR . END Syntax: Example: X10 ? yes no $OUTX KUKA China | 20.06.2016 | page 17 Example: Simple counting loop (1) 1 2 3 4 1 * 5 = 5 5 DEF MAIN_PROGRAM( ) DECL INT CELL4 DECL INT FI ;Array index INI FOR FI = 1 TO 4 CELLFI = FI * 5 ENDFOR . END CELL FI = 2 KUKA China | 20.06.20
14、16 | page 18 Example: Simple counting loop (2) 1 2 3 4 2 * 5 = 10 5 10 DEF MAIN_PROGRAM( ) DECL INT CELL4 DECL INT FI ;Array index INI FOR FI = 1 TO 4 CELLFI = FI * 5 ENDFOR . END CELL FI = 3 KUKA China | 20.06.2016 | page 19 Example: Simple counting loop (3) 1 2 3 4 3 * 5 = 15 5 10 15 DEF MAIN_PR
15、OGRAM( ) DECL INT CELL4 DECL INT FI ;Array index INI FOR FI = 1 TO 4 CELLFI = FI * 5 ENDFOR . END CELL FI = 4 KUKA China | 20.06.2016 | page 20 Example: Simple counting loop (4) CELL 1 2 3 4 4 * 5 = 20 5 10 15 20 DEF MAIN_PROGRAM( ) DECL INT CELL4 DECL INT FI ;Array index INI FOR FI = 1 TO 4 CELLFI
16、 = FI * 5 ENDFOR . END FI = 5 KUKA China | 20.06.2016 | page 21 Two-dimensional array DEF MAIN_PROGRAM( ) DECL INT MEAS_VALUE 2,4 DECL INT ROW,COLUMN INI ; - Pre-assignment of an array - FOR ROW = 1 TO 2 FOR COLUMN = 1 TO 4 MEAS_VALUE ROW,COLUMN = 0 ENDFOR ENDFOR . END Row 1 Column Row 2 1 2 3 4 0
17、0 0 0 0 0 0 0 KUKA China | 20.06.2016 | page 22 Row Column Example: Three-dimensional array BOOL MATRIX 3, 3, 3 Level KUKA China | 20.06.2016 | page 23 Three-dimensional array DEF MAIN_PROGRAM( ) BOOL MATRIX 3,3,3 INT ROW, COLUMN, LEVEL INI FOR LEVEL = 1 TO 3 FOR COLUMN = 1 TO 3 FOR ROW = 1 TO 3 M
18、ATRIX ROW, COLUMN, LEVEL = FALSE ENDFOR ENDFOR ENDFOR . END The keyword “DECL” may also be omitted when declaring simple data types. KUKA China | 20.06.2016 | page 24 Structure KUKA China | 20.06.2016 | page 25 Structures Example: Exact definition of a car Air conditioning Motor Color Manufacturer
19、 KUKA China | 20.06.2016 | page 26 Structures A structure is a combination of different data types. A structure is initialized with an aggregate. Not all the parameters have to be specified in an aggregate. The order of the parameters is insignificant. User-defined structures should end in .TYPE! K
20、UKA China | 20.06.2016 | page 27 DEF WELD ( ) STRUC WELDTYPE REAL V_WIRE, INT CHARAC, BOOL PULSE DECL WELDTYPE SEAM1 INI SEAM1=V_WIRE 0.7, CHARAC 5, PULSE FALSE . SEAM1.PULSE=TRUE . END User-defined structure Name of the structure Variable name Data type Modification of a value in an aggregate usin
21、g a point separator KUKA China | 20.06.2016 | page 28 Predefined structures The following structures are predefined in the KUKA robot system: STRUC AXIS REAL A1,A2,A3,A4,A5,A6 STRUC E6AXIS REAL A1,A2,A3,A4,A5,A6,E1,E2,E3,E4,E5,E6 STRUC FRAME REAL X,Y,Z,A,B,C STRUC POS REAL X,Y,Z,A,B,C INT S,T STRUC
22、 E6POS REAL X,Y,Z,A,B,C,E1,E2,E3,E4,E5,E6, INT S,T KUKA China | 20.06.2016 | page 29 Calculating or manipulating robot positions: XP1.x = 450 ; New X value 450 mm XP1.z = 30.0*distance ; New Z value is calculated PTP XP1 Modify the position from the DAT file once ; X value is offset by 450 mm each
23、time XP2.x = XP2.x + 450 PTP XP2 Modify the position from the DAT file every time it is executed myposition = XP3 myposition.x = myposition.x + 100 ; added 100mm to the X value myposition.z = 10.0*distance ; Calculate new Z PTP XP3 ; Position was not changed PTP myposition ; Calculated position Position is applied and saved in a variable