Universal Robots Forum

Is it possible to change the value of a variable in runtime?

Hi,

I’m writing an application that handles a few trays of materials. Every tray has three boolean variables: is it empty or full, and is the robot finished with the tray. My problem is, that the user should be able to fill a previously finished tray with raw material while the robot is working on an other and tell the robot that the tray is ready again.

The user can select, how many and which trays will be in use. When a tray is configured (input ports of sensors, is it full or empty), the user can add it to the program tree under a loop that runs until all the trays’ finished variable is true. The three variables are assigned by an AssignmentNode and saved to the DataModel as well. The assignments are done at the start of the program and the Robot Program is set to only run once, as the LoopNode ensures that the program doesn’t end prematurely. I want the user to be able to change these variables in runtime, but I run into deadends after deadends.

If you have a solution involving URScript, could you please explain what and how should I do elaborately, because I don’t have much experience with the script side.

Thanks,
Viktor

@tarko.viktor99 we do exactly this using threads running in the background. When the operator fills a tray of parts they press a button to tell the robot that the tray has been refilled. We actually use Banner K50 touch buttons to indicate to the operator that we are out of parts in that tray and that they need to refill. When the robot runs out it turns on the output to the button which illuminates it, when the operator is done refilling they press the lit button signaling to the robot to turn off the output and reset the tray counters or flag.

We also have systems where we have light curtains separating the operator and robot at the part presentation point and anytime the light curtains are broken we trigger the robot to reset the tray count. We do this through a separate safety controller so that the robot only goes into safeguard stop if the robot is in a “danger” area when the operator reaches in. We also use light towers at the interface between the operator and robot to indicate when its appropriate to load parts and when its not.

Hi, thanks for the input!

My problem is that I would prefer a button on the GUI. I guess I can use a popup, that has buttons that toggle an internal flag bound programatically to a certain tray, but I’m not sure that works. I don’t really want to use a physical button, as the robot cell is more or less finished minus the URCap operating it.

If I call a popup, will I be able to change the assignments, or just the boolean variables stored in the dataModel? Also, can I customise the popup, so that it can’t be closed during running, but will close at the end of the program?

Thanks,
Viktor

It works, use a variable where you store the value and create a switch case and then put it in to a sequence:
if value = 90 let’s say do something … etc.
You can also link that variable to a physical button input …

The program is already running on an If structure using internal flags (until I cook up how to change predefined variables). I don’t want to use physical buttons if I don’t have to, I’d rather have buttons on the GUI, but I don’t know how to create a custom popup, that starts only when the program starts and stops with the program. Were I able to do that, there would really be no problem, from there I could program the button however I like, but opening a custom popup with textfields and several buttons is where I’m stuck.

Preferably, I would have something like this:

Hello

I have recently made a customized popup. It is a bit complex but what I did is that I have 3 parts/layer in the program: The Java xmlrpc client, an xmlrpc running on a daemon and the URScript part.
I use the xmlrpc running on a daemon as a intermediary such that I can call a boolean method on the xmlrpc from the URScrip layer to trigger a popup (method: sets a boolean to true). When this method is called, a thread running on the Java layer can check this boolean and call a popup window if it is true. The URScript layer is then waiting for the popup to close by listening for the boolean in the xmlrpc to become false (this lets the program wait and continue when the popup is closed).

If you are interested in seeing how it is done then let me know.

When I use custom popup, the urscript is monitoring if the popup is closed or not.
The urscript is waiting while isVisible of jframe is true, and it is flowing in the next step after isVisible is changed to false.

The way to watch “isVisible” is to use xmlrpc.

1 Like

Since my last reply, I ditched internal flags, because I couldn’t toggle their value properly and went back to using variables. The program runs nicely, however now I can’t change the variables in runtime again. I tried sending an assignment in the form of “global xyzvar=False” through a socket, but it didn’t change the variable.

Mainly I’m interested in the possibility of changing any variables inserted by my URCap, secondly, how can I create a popup without calling a method through an ActionListener?

Hi, @tarko.viktor99

Have you ever tried referring my sample on github repositories?
I had created popup without actionlisner.

1 Like

I have not yet, but it seems feasible for me. Thakns to you, the popup question is answered.

In the meantime I tried to send the assignment as a single line instead of a function and it toggled the variables, but halted program execution and I could only restart from the start.

Since my last reply, I realized, that functions can’t change the value of a variable outside of them, so that isn’t going to work. As I can’t use functions and secondary functions, I had to search for something again. I found out that the output registers can both be written and read (write_output_boolean_register() and read_output_boolean_register()), so I used a thread to monitor the boolean registers assigned to the variables and when the register changed value, I could change the variable accordingly from the inside of the thread.

Hopefully this solution will help those, who struggle with changing variables in runtime until this is implemented.