public void onProgramStart() throws InterruptedException, ExecutionException {
ExecutorService executorService = null;
executorService = Executors.newFixedThreadPool(3);
Future future = executorService.submit(new CallablePopup());
Integer result = future.get();
System.out.println("Result is: " + result);
}
public class CallablePopup implements Callable { @Override
public Integer call() throws Exception {
int popupIndex = 0;
JOptionPane.showOptionDialog(jPanel, aComboBox, "Selection: ", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
popupIndex = aComboBox.getSelectedIndex();
return popupIndex;
}
This works well if I launch the program while standing inside the “URCap instruction” added to the Robot Program.
But when I launch the Robot Program, outside of that instruction the JOptionPane appears, but I can’t interact with it and everything else freezes.
I can’t figure why it is happening. Certainly it’s something with JPanel but I lack the knowledge to workaround this.
it seems to me you are mixing up urscript and java.
You could do your selection in the installation and store the selected value in the datamodel. In generateScript you could read your stored value and write it to a urscript variable.
API
com.ur.urcap.api.domain.data
DataModel (set/get)
Hi, thanks for your answer. I could do what you proposed but I’m trying to show a custom popup when program starts. That’s why I’m using urscript to launch a Java function. I tought that was the right way to do that. Is this correct?
Please correct me if I wrong. When I’m in the JPanel of the buildUI the popup appears and works well, but when I’m outside the JPanel the popup appears but freeze everything else. There is a way of calling the popup without JPanel as parent frame? I tried to call the optionPane with NULL parent in the first argument but with no better results.
There’s a way for the popup to belong to the entire polyscope instead of belonging only to my buildUI JPanel?
In 2018 I had a similar question - I wanted to offer a java-selection/configuration menu for the user on startup of the robot program …
I can share my experience but Iam not an expert. UR-Developer please correct me if Iam wrong with the next lines.
If you start your robot-program you will leave the “java-section” and urscript will be triggered on the controller. With generateScript you are able to insert ursript-code from your configuration in installationNode or from your programNodes.
Iam really not sure about timing and at which point(s) generateScript will be triggered (assuming at start and save)
But I think at this point (run program) no java-code with user interaction should be implemented.
If you have started your robot-program you should interact with your robot by the offered interfaces.
eg via daemon, primary, secondary, rtde, profinet …
Are you using the CB-Series or the e-Series?
In the e-Series you have the possibility to interact with the toolbar.
eg IO via API or URScript via primary, secondary and realtime interface should also work - maybe this could help you.
In urscript is also a popup-function but with less possibilities like in java.
What selection could the user do in your JPanel? Maybe there is a workaround.
Mr. Mike, I really appreciate your kindness. I understand what you say and maybe there’s another way to achieve my goal. I want to implement a simple product selection. I’m attaching a photo of Pally software for palletizing. I want something similar but for cb10 robot instead. How do you think it has to be implemented in Java / urscript?
Not knowing about the implemenation of this selection-frame and corresponding to the ur-guidelines.
It looks like one of the most requested features of the forum: Runtime Interaction GUI elements
You could create a programNode with a comboBox for product selection and add it to program tree. But I think you want to achieve the selection without opening the robot program source-tree.
You could create a urcap with a daemon which is waiting via socket for a value. But in this case the selection is on another device.
Are you working with a PLC (and a HMI) in your environment?
You could write a value to a register of the robot. In this case you also trigger this event from another device.
With RTDE you could also write to a register - but … from another device.
You could sacrifice your digital inputs ?!
But now Iam running out of ideas - maybe someone has a better simpler idea?
Thanks again Mike, we are currently using a integer input like “index position” on a couple of vectors who have our working values saved.
I believe there is a way to do what I’m asking since Pally software has this feature. I also understand there is no easy and standard way to implement it.