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?
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.
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.