The following section is excerpted from an article by Andrea Veronese, available on Industrial Robotics Group by Euclid Labs.
Interrupts in KUKA robots can pause the execution of a program and jump to the execution of another program (called interrupt program). At the end of such subroutine, the main program is resumed from the point it was interrupted.
Interrupts have to be declared at the beginning of the program (but not in the declaration section). The declaration syntax follows.
[GLOBAL] INTERRUPT DECL (priority) WHEN (event) DO (subroutine)
- [GLOBAL]: interrupts are accessible only in programs where they are declared or in their subprograms. If an interrupt has to be accessible even in other programs, the keyword GLOBAL has to be present in its declaration.
- (priority): interrupts must be provided with a priority integer, which has to be univocal among the declared interrupts. Priority is useful when more than one interrupts occur at the same time. In this case all the interrupt programs are executed, from the one with the highest priority to the one with the lowest priority. The available priority values are: 1, 2, 4 to 39, 81 to 128. The smaller is the value, the higher is the priority. Up to 32 interrupts can be declared at the same time.
- (event): this is the condition that is monitored by the robot when the interrupt is active. The event can be a global Boolean variable, a signal, a comparison or a logic operation (NOT, AND, OR, EXOR). The event is satisfied only if a rising edge or falling edge of the variable is detected (that is a change of state).
- (subroutine): the name of the subprogram that has to be executed if the condition is met.
Once that interrupts have been declared, they have to be activated to be used. The syntax of the activation instruction follows.
INTERRUPT (action) [(number)]
- (action): this field specifies if the interrupt has to be enabled (action =
ON
) or disabled (action = OFF
). Once that an interrupt is enabled, it can be temporarily disabled (action = DISABLE
) or enabled (action = ENABLE
).
- (number): this field specifies the number of the interrupt that the activation instruction is referred to. The number of the interrupt corresponds to its declared priority. If number is not used, the activation instruction refers to all declared interrupts. A maximum of 16 interrupts can be active at the same time.
Once the INTERRUPT instruction has been executed, the interrupt will be actually activated after an interpolation cycle (= 12 ms).
The subprogram (i.e. the interrupt program) can contain some powerful instructions in addition to the usual robot instructions:
- BRAKE: this instruction can be used only in interrupt programs and stops the robot motion with a STOP 2. When this instruction is used, the program execution continues only after the robot has been stopped. Using BRAKE F stops the robot with a STOP 1.
- RESUME: this instruction can be used only in interrupt programs and cancels the execution of all the subprograms up to the program where the interrupt was declared. That is, when this instruction is executed, the program pointer jumps to the next line of the main calling program. Such instruction is very useful when the robot is asked to perform different actions depending on the interrupt event. If the RESUME instruction is not used, the program execution will normally continue after the END instruction of the subprogram.
- $AXIS_INT: when the interrupt condition is met, robots saves its joint position in this variable.
- $POS_INT: when the interrupt condition is met, robots saves its cartesian position in this variable.
In the following example, a robot places parts on a pallet. A laser sensor is used in order to know the correct height where the part can be released. As soon as the laser is intercepted, the interrupt is executed and the robot releases the part.
DEF MAIN()
[…]
; Declare an interrupt with priority 2
INTERRUPT DECL 2 WHEN $IN[2] DO LASER_FOUND()
[…]
; Activate interrupt
INTERRUPT ON 2
PTP OUT_SEARCH
; Start search routine
SEARCH_LASER()
; Release part
GRIPPER_OFF()
; Go back
LIN START_SEARCH()
[…]
END
DEF SEARCH_LASER()
; Reach the starting point of the search trajectory
PTP START_SEARCH
; Move to the end of the search trajectory till the laser is found
LIN END_SEARCH
END
DEF LASER_FOUND()
; Deactivate interrupt
INTERRUPT OFF 2
; Stop the robot motion
BRAKE
LIN $POS_INT
; Jump to the next line of the calling program (i.e. GRIPPER_OFF() in MAIN() program)
RESUME
END
The following section is excerpted from an article by Marta Galvan, available on Industrial Robotics Group by Euclid Labs.
Once the user defines a statement, the robot is able to execute that statement while performing its motion. Then the Trigger function basically triggers the user-defined statement, referring to the start or end point of the motion. Moreover, the trigger point, at which the statement is triggered, can be exactly at the start or end point of a motion, or shifted in time and/or space.
TRIGGER WHEN DISTANCE=Position DELAY=Time DO Statement <PRIO=Priority>
- Position: REAL variable, constant or function (expressed in mm) ; it shifts in space relative to the reference point. If negative value, it is considered as an offset towards the start of the motion; otherwise if positive value, it offsets towards the end of the motion. If no shift in space is desired, set Distance = 0.
- Time: REAL variable, constant or function (expressed in ms). It shifts in time relative to Distance, towards the start of the motion, if negative. If positive, trigger is switched after Time has elapsed. If no shift in time is desired, set Time = 0.
- Statement: it is possible to assign a value to a variable, call a subprogram specifying its Priority or define an OUTstatement, PULSE statement or CYCFLAG statement.
- Priority: INT variable or constant specifying the priority of the trigger in case Statement calls a sub-program. If several triggers call sub-programs at the same time, the trigger with the highest priority is processed first, then the triggers of lower priority.
LIN P_2 C_DIS
TRIGGER WHEN PATH = -20.0 DELAY= -10 DO $OUT[2]=TRUE
LIN P_3 C_DIS
LIN P_4 C_DISLIN P_5
In the image, the approximate position in which the $OUT[2]=TRUE statement would be triggered is indicated by an arrow. The switching range goes from PP_2*start to P_5 because P_2 is approximated, and P_5 is the next exact positioning point after the TRIGGER statement. If P_3 was not approximated, the switching range would be P_2 toP_3, as P_3 is the next exact positioning point in the program after the Trigger statement.