RobotStudio event

Error handling

Hi all,

I have a slight problem with errorhandling in rapid.

In my program there is a gripper test at the beginning of the main routine. Inside the gripper-test-routine I generate an error with the raise statement. In my error handling code I have two choices; one is to try to move the gripper again; second choice is to abort (means ExitCycle). The retry part seems to work.

If the program exits the cycle the gripper test starts again but then rapid comes up with an error message saying an untreated error has occured. I can't figure out what's wrong.

Here is what is in the code:

Main-Routine:

proc main()

GripperTest;

endproc

 

PROC GripperTest()
 
 VAR num i:=0;
 VAR num GripResult := 0;
 
 ! -- Check if gripper is in position

  MoveGripper;
  GripResult := CheckGripperPos();
  IF (GripResult=1 OR GripResult=2 OR GripResult=3) RAISE 10;
  
  
 ERROR
  
 IF (errno = 10) THEN
  WHILE (Result <> 5) DO
   TPErase;
   TPWrite "-- Gripper not in target position --";
   TPWrite "";
   TPWrite "You can retry to move the gripper";
   TPWrite "or abort the current cycle and ";
   TPWrite "move the robot to home position.";
   TPReadFK result, "Make a choice:", "Retry", "", "", "", "Abort";
  
   IF (Result=1) THEN
    MoveGripper;
    GripResult:= CheckGripperPos();
    IF GripResult=0 TRYNEXT;
   ENDIF
     
   IF (result=5) ExitCycle;
  ENDWHILE  
 ENDIF
 
 
ENDPROC 

Thanks for your help

DiMo

Comments

  • The fault you are making is the following, when you RAISE an error you have to handle the "error" in the errorhandler. When you exit the cycle you have to use a trynext (or something...) to handle the error.

    Otherwise the program shall stop at the point where the error is raised, with an error....

  • The problem is that your Main() doesn't have an error handler.
    Even ExitCycle in the error handler is not very beautiful.
    RAISE is helpful in a Error handler because the execution continues in the error handler of the calling function.

    For me the best thing is:

    Main()

      GripperTest;

      ! Should be something here ;)

      ERROR
     
      IF ERRNO=10 THEN
          ! Gripper test failed and aborted
          EXIT;  
          ! Or,  RETRY if you'd like to run GripperTest again.
          ! Exitcycle is not beautiful.
      ENDIF
      RAISE;
    ENDPROC

    PROC GripTest()
      ...

    ERROR

     ...

      IF (Result=5) RAISE;

    ENDPROC
  • Hi,

    thanks for your replies. That might be right (didn't have the time to run it on VIRC) -  but still I don't exactly understand why the error is thrown to the main routine. As I understand it I handled the error in the routine where the error was raised. Why does the error occur then in the main routine? I read in the documentation that the error can be raised to the calling routine with an emtpy RAISE statement - but I didn't do so. 

    Thanks for your help

    DiMo
  • Hi DiMo.

    I found the time to check your program in RobotStudio, and say what? It runs. No errors are reported by the robot.
    I have an old version of RobotStudio, and I simulate an IRB140 over an S4C+ controller.
    It will be intersting to test it over a new system. Maybe we are talking about an ABB bug.
    Anyway, I still think it's not a good idea to exitcycle directly from an error handler. Better to raise back the problem through the calling stack.

    Here the version I tested:


    MODULE ModMain

    PROC main()

    GripperTest;

    ENDPROC


    PROC GripperTest()
     
     VAR num i:=0;
     VAR num GripResult := 0;
     VAR num Result:=0;
     
     ! -- Check if gripper is in position

      !MoveGripper;
      GripResult := 1;
      IF (GripResult=1 OR GripResult=2 OR GripResult=3) RAISE 10;
     
     
     ERROR
     
     IF (errno = 10) THEN
      WHILE (Result <> 5) DO
       TPErase;
       TPWrite "-- Gripper not in target position --";
       TPWrite "";
       TPWrite "You can retry to move the gripper";
       TPWrite "or abort the current cycle and ";
       TPWrite "move the robot to home position.";
       TPReadFK result, "Make a choice:", "Retry", "", "", "", "Abort";
     
       IF (Result=1) THEN
        !MoveGripper;
        GripResult:= 0;
        IF GripResult=0 TRYNEXT;
       ENDIF
        
       IF (result=5) ExitCycle;
      ENDWHILE 
     ENDIF
     
     
    ENDPROC
    ENDMODULE