Interrupt move

Hello,
I want to use an interrupt to halt the robot's movement and return to the beginning of the program. Let me explain: while the robot is moving to a specific point, a TRAP signal is received, causing it to stop. Afterward, it needs to retract and return to the start of the program. Could you help me with this?

I’ve done this in the past with ExitCycle. As long as the robot execution mode is set to continuous it will go back to the start of the program and start immediately. Here is a rough example with an input (diButtonPressed) triggering the trap and emulating PPToMain, Play.

VAR intnum intButtonPressed;

PROC Main ()
    IDelete intButtonPressed;
    CONNECT intButtonPressed WITH TrapButtonPressed;
    ISignalDI diButtonPressed, 1, intButtonPressed;
    RunRoutine;
ENDPROC

PROC RunRoutine ()
    WHILE TRUE DO
        MoveJ p1, v500, fine, tool0;
        WaitTime 1;
        MoveJ p2, v500, fine, tool0;
        WaitTime 1;
    ENDWHILE
ENDPROC

TRAP TrapButtonPressed
    StopMove;
    WaitRob \ZeroSpeed;
    ! StorePath;
    ! ClearPath;
    ExitCycle;
ENDTRAP

The robots I’ve used always had the path recovery option so not completely sure if StorePath/ClearPath is needed either way ExitCycle is probably the main thing you really need here.

Hi…
I would use ExitCycle only if absolutely necessary. If you need the robot to return to the start of the program at a specific point, I would use a trap with error handling there; I assume you don’t want to return to the beginning every time, but rather under a specific condition. By using error handling, you can manage how and where the return happens. See if this example works for you. Just create the DI and test it.

MODULE ModuleMain
    ! GLOBAL ATTRIBUTES ######################
    VAR intnum int_stop;
    ! ########################################

    PROC Main()
        ! Configures the interrupt only once
        IDelete int_stop;
        CONNECT int_stop WITH trap_stop;

        ! When the digital signal 'di_signal_trap' goes to 1, the TRAP is called immediately
        ISignalDI DigitalIN_Rede,1,int_stop;

        ! Main loop...
        WHILE TRUE DO
            ! RETURN ends the PRG routine and goes back to the WHILE in Main
            PRG;
        ENDWHILE
    ENDPROC

    PROC PRG()
        CONST robtarget p1:=[[804.23,-97.38,1378.67],[0.370054,0.433333,0.340794,0.747758],[-1,1,-1,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        CONST robtarget p2:=[[-233.32,-775.78,1378.67],[0.83429,0.550778,0.0237029,-0.00649835],[-2,1,-1,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        CONST robtarget pRetreat:=[[76.73,806.46,1378.67],[0.0757021,0.0778335,-0.545765,-0.830874],[0,1,-1,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];


        ! -- The robot starts its trajectory
        MoveL p1,v1000,fine,tool0;

        ! If the signal is received during this movement, the robot stops INSTANTLY
        MoveL p2,v1000,fine,tool0;

        ! -- the rest of the code

        ! The use of parentheses (ERR_X) defines the Long Jump
    ERROR
        IF ERRNO=ERR_PATH_STOP THEN
            ! Clears the current trajectory from the motion base level
            ClearPath;

            ! Resumes the movement state of the system required by the controller
            StartMove;

            ! Now, the robot is clear to move to the retreat position
            MoveJ pRetreat,v500,fine,tool0;

            WaitUntil DigitalIN_Rede=0;
            
            ! RETURN ends the PRG routine and goes back to the WHILE in Main
            RETURN ;
        ENDIF
    ENDPROC

    TRAP trap_stop
        ! Creates an asynchronous error connected to the current move instruction[cite: 5]
        ProcerrRecovery\SyncLastMoveInst;

        RETURN ;
    ENDTRAP
ENDMODULE

Good work.

1 Like