RobotStudio event

How can I make it so a digital input sends the program pointer back to the beginning of Main?

Avilarinof
edited March 2022 in RAPID Programming
I have code that sort of looks like this:
PROC main()
  !pos 0
  WaitDI diConveyON,0;
  !pos 1
  WaitDI diRunButton,1;

   IF diA=1 THEN
     !do A things
   ELSEIF diB=1 THEN
     !do B things
   ELSEIF diC=1 THEN
     !do C things
   ENDIF
ENDPROC
If diConveyON becomes 1 while the PP is in pos 1, I need to go back to pos 0 and wait until it is 0 again. But if it happens anywhere else, it's irrelevant. What's the simplest and safest way to do that? I thought about using interrupts but surely there must be an easier way?

Thanks in advance.

Best Answers

  • lemster68
    lemster68 ✭✭✭
    Answer ✓
    Read up on system inputs in the system parameter manual.  There is a signal exactly for that.  You have to map it and assign the StartMain action.  The program must not be running, or it will be rejected.  Issue Stop system input, the STartMain when program is no longer executing.
    Lee Justice
  • graemepaulin
    Answer ✓
    If you move the code into a separate routine then you could use something like:
    PROC Main()
               WaitDI di_ConveyOn,0;
               RunProcess;
    ENDPROC

    PROC RunProcess()
             WaitUntil di_RunButton=1 OR di_ConveyOn=1;
            IF di_ConveyOn=1 THEN
                Return;
            ENDIF
            !the rest of your code
    ENDPROC