RobotStudio event

Stopping the motion on a digital input signal

Options
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:

1. The ERROR statement with parentheses -- what does it mean? I could not find it in the RAPID documentation.
2. If I use ERROR without parentheses in proc1, the program exits due to unhandled error. Why?
3. If I don't catch and re-raise the error in SensorFailure, the program also exits due to unhandled error. Why?
4. If I don't raise an error from SensorFailure, the program hangs while executing the MoveAbsJ instruction in proc1. Why?

Answers

  • I recently ran into this myself so I hope this helps:

    1. It is called "Error recovery with long jump" and you can find more info in the rapid kernal manual. My understanding of this is that it will jump to this error handler with the parentheses no matter how far nested down you are. If you had it in main it can act like a global error handler.
    2. See below
    3. The first raise is to call the error handler. The second raise in the error handler is used to propagate the error to the calling routine. The trap is not called from a routine so this might be why you might need a long jump (parentheses)
    4. Not sure on this one.

    Dan
  • mkatliar
    mkatliar
    edited September 2021
    Options
    Thank you @DanielWright, what you wrote sheds some light on the issue. I found the "Error recovery with long jump" in the manual. It is not clear though, why two different error handling mechanisms (ERROR and ERROR()) are necessary. Also it seems that they cannot be combined in the same routine (having both ERROR and ERROR() is a syntax error :-))

    Regarding (3), it is still not clear to me: both RAISE are in the same routine SensorFailure, why do they work differently? Why the first RAISE does not propagate to proc1, but the second one does?
  • Fritz
    Options
    mkatliar said:
     Why the first RAISE does not propagate to proc1

    There are some cases where you have to add RETURN; after RAISE; Stupid, but worked for me.
    Try this.

    Fritz.
  • lemster68
    Options
    I always do my error handlers like this:

    ERROR
      TEST ERRNO! this is the built in data to which the current error number is written
         CASE ERR_SENSOR_FAILURE:
            RAISE;
      DEFAULT:
         Stop; !or often times <SMT> this causes an error attempting to execute placeholder, so system                   ! execution error turns ON, bringing attention to the pendant.
         ! What you need to do here is look at the value stored in ERRNO, and then find which
         ! predefined error number matches.  That is your current error which you never anticipated.
      ENDTEST
    Lee Justice