Universal Robots Forum

IfNode "check expression continuously" missing in SDK

Hi,

I’m trying to create an IfNode that checks an expression continuously.
In Polyscope this is done by clicking the “check expression continuously” checkbox.
I’ve noticed there is no way of setting this checkbox/setting in the SDK - you can only simply create an IfNode with an expression.

When comparing this to the LoopNode, a LoopNode has a ConfigFactory used to set the configuration of the LoopNode.


The LoopNodeConfigFactory has a method to create a LoopNode with an Expression and a Bool which enables the “check expression continuously” checkbox on the LoopNode in Polyscope.

Is it possible to somehow enable the “check expression continuously” checkbox of an IfNode pragmatically? Or is there a recommended work around for this?

Thanks in advance!

This is how it looks in the URscript code when checking the box in PolyScope.
So basically it starts the if in a thread, and the program loops the check with the while and checking if it is true as long as the thread is not done and if it is not true meanwhile, kill the thread.
Would be nice to have the same as the LoopNode, but meanwhile I guess you could just set it up the same?

while (True):
   $ 1 "Robot Program"
   $ 2 "If  True "
   global thread_flag_2=0
   thread Thread_if_2():
     # Just a Popup as a holder for whatever the if should do.
     $ 3 "Popup"
     popup("Insert your code here", "Warning", True, False, blocking=True)
     thread_flag_2 = 1
   end
   if (  True  ):
     global thread_handler_2=run Thread_if_2()
     while (thread_flag_2 == 0):
       if not(  True  ):
         kill thread_handler_2
         thread_flag_2 = 2
       else:
         sync()
       end
     end
   else:
     thread_flag_2 = 2
   end
 end

Thanks for the quick reply Rasmus,

This is perfect and works in the case where all your code/nodes are known at the time of writing, however I’m trying to add child nodes (waypoints) dynamically or at run time to this IfNode’s rootTreeNode.

Essentially, I want to monitor an input for the duration of a group of movements, if the input switches at any point during these movements, the movements will cease. I have got this working with custom scripts and the IfNode’s “check continuously” checkbox/function within Polyscope, however I want to abstract the complicated script code from the user.

I’ve tested this using a custom node, where I’ve written a similar script node to the one you provided into the ProcessActive node’s generateScript() function.
ProcessActive node also generates the Move and Waypoint nodes (from my createSubtree() method) as so:

image

When running the program, it never actually got to the Move and Waypoint nodes, they were skipped every time. However it did toggle DO0 OFF when DI0 was ON.
I then saved the program and checked the script file, an excerpt of the code is copied below.
Note that there is no move or Waypoint nodes as there was in the program tree above.

        $ 3 "Process Active"
    	def Process_Active():
    		  if (get_digital_in(0) == True):
    			  set_digital_out(0,False)
    			  sleep(0.5)
    			  return False
    		  end
    		  return True
    	end
    	global thread_flag_2=0
    	thread Thread_if_2():
    		thread_flag_2 = 1
    	end
    	if (Process_Active()):
    		global thread_handler_2=run Thread_if_2()
    		while (thread_flag_2 == 0):
    			if not(Process_Active()):
    				kill thread_handler_2
    				thread_flag_2 = 2
    			else:
    				sync()
    			end
    		end
    	else:
    		thread_flag_2 = 2
    	end
   # end: URCap Program Node

My conclusions from testing this method are that: I still have the problem that my ProcessActive parent node cannot “continuously check” the ProcessActive() script function whilst executing its child nodes, as the child nodes in this case have not actually shown up in the script code - which I find odd in itself (They do show up in the “program.txt” file though).

I finally have it working and have figured out what I was doing wrong in the above reply.

Because the script is called in the GenerateScript method of my ProgramNode (Java) code, I forgot to add the writer.writeChildren(); call where I wanted my child nodes to actually execute.

Doing this, my program executes all child nodes in the ProcessActive node whilst simultaneously checking the state of DI0 throughout the process. The execution of child nodes is done at run time so that a user can modify the subtree and add any child nodes they like - the program will still monitor whilst executing them.

2 Likes