# Trap routine not executing

**URL:** <https://tech-community.robotics.abb.com/t/trap-routine-not-executing/9257>\
**Category:** RAPID Programming\
**Tags:** interrupts, trap\
**Created:** [January 3, 2020, 7:30pm UTC](https://tech-community.robotics.abb.com/t/trap-routine-not-executing/9257 "2020-01-03T19:30:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![csmith](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@csmith](https://tech-community.robotics.abb.com/u/csmith)\
**Post date:** [January 3, 2020, 7:30pm UTC](https://tech-community.robotics.abb.com/t/trap-routine-not-executing/9257/1 "2020-01-03T19:30:26Z")

</div>

Hi,

I want to setup a trap routine to execute when the robot runs into a Motion Error.  
In my motion task, I’m setting up the interrupt and tying it to a DO;

```auto

PROC SetupInterrupts()
     IDelete intOverride;
     CONNECT intOverride WITH tOverride;
     ISignalDO errorsig, 1, intOverride;
     TPWrite "Interrupt Setup";
ENDPROC

```

This is my TRAP:

```auto

TRAP tOverride
    ISleep intOverride;
    CONST jointtarget homepos:=[[0,10,20,30,40,50],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
    TPWrite "Interrupt fired";
    MoveAbsJ homepos,v100,fine,tool0;
    IWatch intOverride;
ENDTRAP

```

```auto
VAR intnum intOverride:=0

```

is defined in my System Module

You can see, I want to move to a safe home position in case we get a Motion Error.  
In my main() I ultimately call an EGMRunPose and have the robot controlled by an EGM data-stream.  
Once the robot get’s into a singularity, Dynamic load too high or joint out of range error, I can see the DO toggle,  
but I’m getting a _40210 - Interrupt removed from queue_ error, which means the TRAP routine won’t run.

What am I missing?

Thank you

---

<div class="post-metadata">

**Author:** ![csmith](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@csmith](https://tech-community.robotics.abb.com/u/csmith)\
**Post date:** [January 3, 2020, 8:49pm UTC](https://tech-community.robotics.abb.com/t/trap-routine-not-executing/9257/2 "2020-01-03T20:49:30Z")

</div>

It seems like a TRAP is only executing if the Program is running.  
Am I out of luck after a Motion Error which stops the program execution and turns off the motors ?  
How can I recover from a situation like that? Just turning Motors back on doesn’t seem to work as I immediately trip the same error again.  
Right now I have to go to Manual mode, jog out of the Singularity/Joint out of range, go back to automatic and restart.  
This works but I was hoping there is a more elegant solution.

Thanks

---

<div class="post-metadata">

**Author:** ![graemepaulin](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@graemepaulin](https://tech-community.robotics.abb.com/u/graemepaulin)\
**Post date:** [January 6, 2020, 12:51am UTC](https://tech-community.robotics.abb.com/t/trap-routine-not-executing/9257/3 "2020-01-06T00:51:37Z")

</div>

You are correct the program has to be running to execute an interrupt.

You need to catch the error (if it is a recoverable error) in an error handler at the end of the executing procedure/routine.

I could not find an errnum (error number) for singularity, but for joint out of range it is ERR\_ROBLIMIT (yes the errnum is text not a number!) - but instead of trying to trap an individual error you could just respond to any error and return the robot to the home position as per your trap routine code above.

There is help on error handlers in the RAPID overview manual under the basic programing chapter-\>error recovery.

---

<div class="post-metadata">

**Author:** ![EricH](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@EricH](https://tech-community.robotics.abb.com/u/EricH)\
**Post date:** [January 7, 2020, 2:39pm UTC](https://tech-community.robotics.abb.com/t/trap-routine-not-executing/9257/4 "2020-01-07T14:39:22Z")

</div>

Or you check in a background task for the state of that output signal and try to handle it there. Of Course you can not move the robot from a background task, but you can handle signals for example.

For example, resetting the error by signal (system input and cross connection) and then call an interrupt by signal.
