BRAND.02 / KRC4 + KRC5
The C-influenced robot language that drives every KRC controller on the factory floor.
KRL — KUKA Robot Language — was introduced with the KRC1 controller in the late 1990s and is still the language of today's KRC4 and KRC5 systems. Programs are split between an SRC file (the logic, in DEF … END blocks) and a DAT file (the data, in DEFDAT … ENDDAT). Motion is expressed with PTP / LIN / CIRC, I/O through $OUT[]and $IN[], and timing through WAIT FOR and WAIT SEC.
KRL splits code into a SRC file (logic, DEF Main … END) and a DAT file (data, DEFDAT … ENDDAT). DEFFCT/ENDFCT declares functions; INTERRUPT DECL arms async handlers.
DEF Main() ; logic here END
PTP is point-to-point joint motion (fastest, free path). LIN is linear in Cartesian space. CIRC traces an arc through an auxiliary point. Spline variants SPL/SLIN/SCIRC blend smoothly.
PTP P1 Vel=100% PDAT1 LIN P2 Vel=0.5 m/s CPDAT1 CIRC P_AUX P_END Vel=0.3
Every motion is interpreted in the active TOOL (TCP) and BASE (work-object) frame. $IPO_MODE switches between #BASE and #TCP interpolation for advanced cases.
$TOOL = TOOL_DATA[1] $BASE = BASE_DATA[2] $IPO_MODE = #BASE
POS = X,Y,Z,A,B,C + Status/Turn (full Cartesian pose). AXIS = joint angles A1..A6. FRAME = pose without S/T (for offsets). INT, REAL, BOOL, CHAR for primitives.
DECL POS P1 = {X 800, Y 0, Z 300, A 0, B 90, C 0, S 2, T 35}
DECL INT i = 0Digital inputs and outputs are read/written as system arrays. $OUT[1] = TRUE drives an output high. WAIT FOR $IN[2] blocks until the input asserts. PULSE() emits a timed pulse.
$OUT[1] = TRUE WAIT FOR $IN[2] PULSE($OUT[3], TRUE, 0.5)
IF/ELSE/ENDIF, FOR/TO/STEP/ENDFOR, WHILE/ENDWHILE, REPEAT/UNTIL, SWITCH/CASE/DEFAULT/ENDSWITCH. Note KRL uses == for equality and = for assignment.
FOR i = 1 TO 5
IF $IN[i] == TRUE THEN
$OUT[i] = TRUE
ENDIF
ENDFOR| Instruction | Category | Purpose | Example |
|---|---|---|---|
| PTP | Motion | Point-to-point joint move (fastest, path not guaranteed) | PTP P1 Vel=100% PDAT1 Tool[1] Base[0] |
| LIN | Motion | Linear move in Cartesian space | LIN P2 Vel=0.5 m/s CPDAT1 |
| CIRC | Motion | Circular move through an auxiliary point | CIRC P_AUX P_END Vel=0.3 m/s CPDAT2 |
| PTP_REL | Motion | Joint move relative to current position | PTP_REL {A1 30} |
| LIN_REL | Motion | Linear move relative to current TCP | LIN_REL {X 100, Y 0, Z 0} |
| SPL | Motion | Spline segment (PTP-style, blended) | SPL P3 |
| SLIN | Motion | Linear spline segment | SLIN P4 |
| SCIRC | Motion | Circular spline segment | SCIRC P_AUX P5 |
| BAS | Motion | Basic motion subroutine call (init/move helpers) | BAS(#PTP_PARAMS, 100) |
| $OUT[] | I/O | Set / read a digital output | $OUT[1] = TRUE |
| $IN[] | I/O | Read a digital input | IF $IN[2] == TRUE THEN ... |
| PULSE | I/O | Pulse a digital output for a given time | PULSE($OUT[3], TRUE, 0.5) |
| WAIT FOR | Wait | Block until a boolean expression becomes TRUE | WAIT FOR $IN[1] |
| WAIT SEC | Wait | Wait a fixed number of seconds | WAIT SEC 0.5 |
| IF | Flow | Conditional (IF / ELSE / ENDIF) | IF count > 10 THEN ... ENDIF |
| ELSE | Flow | Else branch of an IF block | ELSE |
| FOR | Flow | Counted loop (TO / STEP / ENDFOR) | FOR i = 1 TO 5 ... ENDFOR |
| WHILE | Flow | Pre-test conditional loop | WHILE running ... ENDWHILE |
| REPEAT | Flow | Post-test loop (UNTIL exits when TRUE) | REPEAT ... UNTIL done |
| SWITCH | Flow | Multi-way branch (CASE / DEFAULT / ENDSWITCH) | SWITCH mode CASE 1 ... ENDSWITCH |
| GOTO | Flow | Jump to a labelled line | GOTO ENDPROG |
| RETURN | Flow | Return from a routine (or function with value) | RETURN |
| DEF | Structure | Declare a procedure (DEF / END) | DEF Main() ... END |
| DEFFCT | Structure | Declare a function with return type (DEFFCT / ENDFCT) | DEFFCT INT Add(a:IN, b:IN) ... ENDFCT |
| DEFDAT | Structure | Data list module (DEFDAT / ENDDAT) | DEFDAT MyDat ... ENDDAT |
| GLOBAL | Structure | Marks a routine or data as globally visible | GLOBAL DEF Helper() ... END |
| LOCAL | Structure | Marks a routine as file-local | LOCAL DEF Inner() ... END |
| INTERRUPT | Structure | Declare and arm an interrupt | INTERRUPT DECL 1 WHEN $IN[5] DO Stop() |
| BRAKE | Structure | Stop the robot inside an interrupt handler | BRAKE |
| TRIGGER | Structure | Path-triggered action (distance/time-based) | TRIGGER WHEN DISTANCE=0 DELAY=0 DO $OUT[1]=TRUE |
| DECL | Data | Declare a variable | DECL INT count = 0 |
| INT | Data | Integer type | DECL INT i |
| REAL | Data | Floating-point type | DECL REAL speed = 0.5 |
| BOOL | Data | Boolean type (TRUE / FALSE) | DECL BOOL ready = FALSE |
| CHAR | Data | Character / string element | DECL CHAR msg[20] |
| ENUM | Data | Enumeration type | ENUM Mode HOME, RUN, STOP |
| STRUC | Data | Composite record type | STRUC Point REAL X, Y, Z |
| POS | Data | Cartesian pose with status/turn (X,Y,Z,A,B,C,S,T) | DECL POS P1 = {X 800, Y 0, Z 300, A 0, B 90, C 0, S 2, T 35} |
| AXIS | Data | Joint-angle target | DECL AXIS J1 = {A1 0, A2 -90, A3 90, A4 0, A5 90, A6 0} |
| FRAME | Data | Pose without S/T (used for offsets) | DECL FRAME OFS = {X 50, Y 0, Z 0, A 0, B 0, C 0} |
| $BASE | Frames | Active work-object / base frame | $BASE = BASE_DATA[1] |
| $TOOL | Frames | Active tool frame (TCP) | $TOOL = TOOL_DATA[1] |
| $IPO_MODE | Frames | Interpolation mode (#BASE or #TCP) | $IPO_MODE = #BASE |
| $VEL | System | Velocity override structure (CP and joint) | $VEL.CP = 0.5 ; m/s |
| $ACC | System | Acceleration override structure | $ACC.CP = 2.3 |
| $APO | System | Approximation / blending tolerance | $APO.CDIS = 100 ; mm |
| HALT | System | Stop program execution and require operator action | HALT |
| ; | System | Comment to end of line | ; this is a KRL comment |