Universal Robots Forum

Starting a Programm with several IF-Cases

Good morning together,

My UR10e is connected to a Siemens PLC.
There I´m using a recipe to select the product.

The Programm itself is a simple pick and place procedure.
Depending on an Integer (written in the recipe) the robot has different positions for Pick/ Drop.

Is it possible to start a Roboter programm directly with IF-Cases?

IF “Read_Input_Integer_Register” = 0 —> WAIT (no Job)
IF “Read_Input_Integer_Register” = 1 —> Do Pick-Drop Job 1
IF “Read_Input_Integer_Register” = 2 —> Do Pick-Drop Job 2
and so on.

i Want the Robot to stay in that IF case until the value of the Input register is changed.

Thank you very much.

You can use the Switch node for something like this which can be found in the Program Tab → Advanced → Switch. There you can set a number of cases based on the read value and what should happen at those cases.

Switch read_input_integer_register(2)
    case 0:
        "Do Nothing"
    case 1:
        "Do Job 1"
    case 2:
        "Do Job 2"


Here I also put 2 as the register address as an example.

Thank you very much.
I´ll check that out today.

1 additional question.

Switch read_input_integer_register(2)
case 0:
“Do Nothing”
----> Move to home position

**case 1:**

** “Do Job 1”**
** // Wait: Read_Input_boolean_register(0)= True (Condition to start the Pick Process)**
** Pick…**
** …**
** And so on…**

case 2:
    "Do Job 2"

My question is, if im already in case 1, the programm will be stuck there until the “Input-boolean-register(0)” is true.
When i try to stop the process (via the PLC) i will send a “0” to the integer register and the Input-boolean-register(0) will never turn true . The Robot will do nothing, cause it´s “Stuck” in case 1.
Is there any way to abbort the case function and “jump” to case 0 when the “Input_Integer_Register” will turn to 0?

Unless something has changed and/or I didn’t see the check box in the switch case method for “continuously check”, I don’t think you can easily “break” from a case in the Switch/Case method on a UR, I mainly use the CONTINUOUSLY CHECK if/elif/else functionality to do this and use a thread to continuously refresh a value from the PLC. However you might have the main program loop and just check if it needs to pick or not and then enter the switch-case to determine A) stay still B) do job XX or C) stop the program from looping. Is this kind of what you are kind of looking for:

Before Start

PICK:=false // not picking, going home
JOB:=0 // no job, doing nothing

Main Program (check program loops forever)

if PICK = true
   // pick process code here
   // go home code here
   // go home code here
Switch-Case: JOB
   Case: 0
      sync() // do nothing, use up remaining physical time
   Case: 1
      // job 1 code here
      JOB := 0
   Case: 2
      // job 2 code here
      JOB := 0
… more jobs …
   Case: 9999
      halt() // stop infinite program loop


sync() // use up remaining physical time

Might have to add some waits() for a second to give the PLC time to change the “PICK” since the UR tick is quick at 2ms, this is me kind of shooting from the hip so it may not be the best way. Hopefully this helps gives you some direction or ideas for code structure. Anyways best of luck!

1 Like

Thank you very much for your answer.

I´ve done it now in a different way like this:

In Row 11 I´m using a loop (if my input integer register (0)= 1) //First product is selected.
In Row 12 I move the robot to a “Prepick-Position”.
If the Robot has reached that Position (Row 15) I again use a IF case.
So once my Robot is at the “Prepick-Position” i check again IF he gets a “Do Job Signal” (Read input boolean register (1)=True).
If so, The Robot will do its Pick n Place routine.

I have added an “Elseif” at Row 35 (Read input integer register (0) =0) //Stop-Request/ go to Home-Position.

So with this IF and Elseif I can get my Robot “out” of the Loop.

At my first trial, the robot always stopped with a “Safety-Cycle-Stop”. Therefore i had to add a “Wait” command in line 16. Since then it seems to work.

Thanks a lot.

Greetings from Luxemburg.