I need to stop the robot motion when a digital signal (indicating a sensor failure) goes to 1. For this purpose, I connect a trap to an interrupt generated by this signal. The simplified version of my code, based on the example from section “1.43 ClearPath” of the “RAPID Instructions, Functions and Data types” manual, is presented below:
MODULE TRobMain
VAR jointtarget home := [[0., 0., 0., 0., 45, 0.], [9e9, 9e9, 9e9, 9e9, 9e9, 9e9]];
VAR jointtarget p1 := [[90., 0., 0., 0., 45, 0.], [9e9, 9e9, 9e9, 9e9, 9e9, 9e9]];
VAR intnum sensor_fail_int;
VAR errnum ERR_SENSOR_FAILURE := -1;
PROC Main()
TPWrite “==== PROGRAM START ====”;
BookErrNo ERR_SENSOR_FAILURE;
MoveAbsJ home, v500, fine, tool0;
SetDO TEST_DO0, 0;
SetDO \SDelay:=0.5, TEST_DO0, 1;
TPWrite “Move to target”;
proc1;
TPWrite “Move home”;
MoveAbsJ home, v500, fine, tool0;
ERROR
TPWrite "Error ", \Num:=ERRNO;
TRYNEXT;
ENDPROC
PROC proc1()
CONNECT sensor_fail_int WITH SensorFailure;
ISignalDO \Single, TEST_DO0, 1, sensor_fail_int;
MoveAbsJ p1, v500, fine, tool0;
IDelete sensor_fail_int;
ERROR (ERR_SENSOR_FAILURE)
IDelete sensor_fail_int;
TPWrite “RAISE 2”;
RAISE;
ENDPROC
PROC proc2()
ENDPROC
TRAP SensorFailure
TPWrite “SensorFailure”;
StopMove;
ClearPath;
StartMove;
RAISE ERR_SENSOR_FAILURE;
ERROR
TPWrite “RAISE 1”;
RAISE;
ENDTRAP
ENDMODULE
This code does what I want. However, I don’t fully understand why and how it works. My questions are:
- The ERROR statement with parentheses – what does it mean? I could not find it in the RAPID documentation.
- If I use ERROR without parentheses in proc1, the program exits due to unhandled error. Why?
- If I don’t catch and re-raise the error in SensorFailure, the program also exits due to unhandled error. Why?
- If I don’t raise an error from SensorFailure, the program hangs while executing the MoveAbsJ instruction in proc1. Why?