# Setting up a TRAP Routine

**URL:** <https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009>\
**Category:** RAPID Programming\
**Tags:** traps, irc5, rapid-code\
**Created:** [July 30, 2019, 3:05pm UTC](https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009 "2019-07-30T15:05:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulpadman](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/rahulpadman/32/1291_2.png) [@rahulpadman](https://tech-community.robotics.abb.com/u/rahulpadman)\
**Post date:** [July 30, 2019, 3:05pm UTC](https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009/1 "2019-07-30T15:05:29Z")

</div>

Hi

totally new to robotic programming and rapid

When running in automatic, and if the robot motion got stopped due to an error, i need the robot to return to a predefined position so that i can do inspection and then continue with the program.

can some one give a general idea of how to approach this problem and explain how a TRAP instruction needs to be set?

---

<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:** [July 31, 2019, 11:25am UTC](https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009/2 "2019-07-31T11:25:27Z")

</div>

You can find an example in the help manuals of robotstudio. You find it at File-\>Help-\>Documentation-\>RAPID Instructions, Functions and Data Types-\>Programming type examples-\>ERROR handler with movements or TRAP routines with movement

A common approach is to move backwards on the same path.

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [July 31, 2019, 3:51pm UTC](https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009/3 "2019-07-31T15:51:30Z")

</div>

> [@EricH](#):
>
> You can find an example in the help manuals of robotstudio. You find it at File-\>Help-\>Documentation-\>RAPID Instructions, Functions and Data Types-\>Programming type examples-\>ERROR handler with movements or TRAP routines with movement
> 
> A common approach is to move backwards on the same path.

And for the backwards motion you can look into the path recorder.

---

<div class="post-metadata">

**Author:** ![rahulpadman](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/rahulpadman/32/1291_2.png) [@rahulpadman](https://tech-community.robotics.abb.com/u/rahulpadman)\
**Post date:** [July 31, 2019, 3:55pm UTC](https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009/4 "2019-07-31T15:55:30Z")

</div>

Hi @EricH , @lemster68 i will definitely look into the help documentation from Robot Studio. Will get with a progress update soon.

Thanks very Much for your suggestions.  
Rahul-

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [July 31, 2019, 4:50pm UTC](https://tech-community.robotics.abb.com/t/setting-up-a-trap-routine/9009/5 "2019-07-31T16:50:00Z")

</div>

Using an Event Routine for Stop tied to a procedure that collects the current position of the robot might be simpler. Write a procedure that gets the position using CRobT or CJointT and writes it to variables, tie that procedure to an Event Routine for anytime the robot Stops, then use those variables in your error handling if an error is detected.
