Hi Khizar,
That sounds interesting, and could probably work.
If your program is partway through executing a movement and a user presses this button, should it interrupt the program where it is, or wait for the movement to finish?
A trap routine is sometimes called an interrupt routine because it ‘interrupts’ the program execution to do something else when the program is executing. The interrupt can be caused by a change in digital or analog IO, a change in persistent value, an error etc. The program executes the Trap routine code, then the program pointer goes back to where it was before, depending on the implementation.
This is the best way I can think of. It isn’t perfect but here is the example code:
MODULE MainModule
VAR errnum en_GoHome:= -1;
VAR intnum in_Sen1;
PERS num n_HomeRegister := 3;
VAR bool b_GoHome := FALSE;
PERS jointtarget jt_StopPoint:=[[0,0,0,0,0,0],[287.559,2315.43,0,287.559,9E+9,0]];
VAR pathrecid pri_Stopped;
PROC Main()
! get an error number
BookErrNo en_GoHome;
! Connect trap to routine
CONNECT in_Sen1 WITH trp_Sen1;
! Connect trap to digital input
ISignalDI sen1, 2, in_Sen1;
! Main execution
WHILE TRUE DO
! Movement 1
n_HomeRegister := 1;
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
MoveAbsJ [[0,0,0,0,0,0],[0,3250,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
! Movement 2
n_HomeRegister := 2;
MoveAbsJ [[0,0,0,0,0,0],[1000,0,0,1000,9E9,0]], vmax, fine, TWeldGun_5845XL;
MoveAbsJ [[0,0,0,0,0,0],[1000,3250,0,1000,9E9,0]], vmax, fine, TWeldGun_5845XL;
! Movement 3
n_HomeRegister := 3;
MoveAbsJ [[0,0,0,0,0,0],[3000,0,0,3000,9E9,0]], vmax, fine, TWeldGun_5845XL;
MoveAbsJ [[0,0,0,0,0,0],[3000,3250,0,3000,9E9,0]], vmax, fine, TWeldGun_5845XL;
ENDWHILE
ERROR(en_GoHome)
! Check error number
TEST ERRNO
CASE en_GoHome: ! Error is for homing
HomingSequence; ! Execute homing required and repoisiton
b_GoHome := FALSE; ! Homing is now done
! Get user to stop pushing button and resume program
TPErase;
TPWrite "Robot returned to program position.";
TPWrite "Let go of button and push play";
Stop;
StartMoveRetry; ! Restart Program
DEFAULT:
RETRY;
ENDTEST
ENDPROC
! Homing procedure
PROC HomingSequence()
! Store current move path
StorePath;
! Store stopped location
jt_StopPoint := CJointT();
! Check register and perform movement code required to home robot
TEST n_HomeRegister
CASE 1:
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL;
CASE 2:
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL;
CASE 3:
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL;
DEFAULT:
! Go straight home
MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL;
ENDTEST
! Robot is now home
TPErase;
TPWrite "Robot is home";
TPWrite "Push Play to return to stop position";
Stop; ! Push Play to restart
! Rewind homing movements
TEST n_HomeRegister
CASE 1:
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
CASE 2:
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
CASE 3:
MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL;
DEFAULT:
! Went straight home, no movement to unwind
ENDTEST
! Move back to stopped pose
MoveAbsJ jt_StopPoint, vmax, fine, TWeldGun_5845XL;
! Restore original path
RestoPath;
ENDPROC
! Trap routine to capture button input
TRAP trp_sen1
IF b_GoHome = FALSE THEN
IF sen1 = 1 THEN ! Button pushed
! Stop moving, raise the go home error
StopMove;
b_GoHome := TRUE;
RAISE en_GoHome;
ELSE ! Button released
! Do Nothing
ENDIF
ELSE
IF sen1 = 1 THEN ! Button pushed
IF IsStopMoveAct(\FromMoveTask) THEN ! If the robot is stopped then start it
StartMove;
ENDIF
ELSE ! Button released
StopMove;
ENDIF
ENDIF
! Capture specific error and raise
ERROR(en_GoHome)
RAISE;
ENDTRAP
ENDMODULE
The robot performs movements and updates the register. When the button is pushed the program is interrupted with the trap routine which throws an error. The custom error is captured in the Main routine using error handling with long jump. The robot stops where it is, its current position is recorded, and it begins to move towards home. If the user lets go of the button at any point the robot stops, when they push it again it will keep moving until it is home and then it will stop at the home position and display a message. When the user pushed play again the program will resume as long as the button is held and the robot will execute reverse movements to go back to where it stopped. Once it is back where it stopped another message is displayed, the button can be released and if play is pressed the program should resume from where it left off.
Hopefully this example code helps, let me know about any questions, it uses a few techniques but can be expanded for as many movements as needed. The move commands were examples I used for my system.\
Regards,
Harry