Universal Robots Forum

URScipt + robot code

I have written while loop for the robot via a teaching pendant that checks all the time if the digital_out[0] is True or False and then depending on the outcome, performs some action.

I also have my PC connected to the robot and I communicate via port 30003 where I send a command to set the digital out[0] to either True or False.
The issue I am having is that once I run the code using python and the communication via socket, the code that was defined via a teaching pendant doesn’t run.

Is it possible to run two of those in parallel?

You can make a secondary program https://www.universal-robots.com/articles/ur/secondary-program/ and send it on the secondary interface on port 30002


Thank you, @Ebbe
However, I am looking for an option of running a program that was coded on the robot, and then to change a variable defined in that code using an external URScript which is sent to robot via port 30003.
Do you know if I can run both the URScript and the already programmed program at the same time ?

Yes. As long as the secondary code is simple enough. If you look up the script manual section 1.10 it describes how to run secondary programs, the limitations, and requirements they must meet.

If you only need to change an output then the following example from the same section will do:

sec secondaryProgram():

EDIT: I don’t think you can change a variable in the other script but you can use the built-in registers as a variable and set that with a secondary program.

1 Like

@mads Thank you for your reply, will try to do it

Whenever I run the program on the teaching pendant, and I also run a second program from PC, the program that was running on the teaching pedant stops running and only the PC Script is run.
Do you know how can I run the script from PC so it wont stop the script from teaching pendant?

Did you change your port from 30003 to 30002? This will only work on secondary client interface at port 30002.

Are you specifically looking to control a digital output, or just any straightforward way to communicate a variable change to a running program?

If it’s the latter I’d look into using the general purpose RTDE registers instead of secondary programs:


It includes sample python code at the bottom of the article and you can name the registers in the I/O setup menu in Polyscope to use them directly in your program.

1 Like

I have a script where commands are executed in real-time (RTDE) via my PC . Because I am using an OnRobot gripper and I am unable to operate it from the PC script (there have been some issues with OnRobot communication), I thought of writting a program on the Polyscope that loops all the time, and opens/ closes the gripper when specific variable is True/False.
The issue of mine is that when I first run the program on the polyscope and then run a second program using my PC, when the connection between PC and robot is established the initial program that was created on polyscope is terminated and only the connection via PC is taken into account.

Thus I am looking to communicate a variable change to a running program which I know how to do. The issue again is the fact that when I do change the variable in the running program, that should trigger an action that was defined on the plyscope, but that doesnt happen,

I don’t think you can directly modify variables defined in the main program from a secondary program, they don’t exist within the same scope. I’d still use the RTDE registers here, if you want to do it with a secondary program then you could use write_output_boolean_register() in there instead.

The above wouldn’t explain why your main program is being terminated though. Can you post exactly what you’re sending? Secondary program is not allowed to use any physical time, so no waits, syncs, moves, anything like that. Just a set/write command.

Here is what I am doing, in this example I communicate via port 30003 but its same idea via 30004 (RTDE)

Step 1 (define the program in polyscope)

Step 2 (Run the program in polyscope and test if gripper opens and closes when I change the input-output via polyscope)
It does :slight_smile:

Step 3 (Switch from local control to remote, and use the below attached code to send command to change the digital_out[0])

So when the script is sent from my PC to the robot, the I/O is changed which I can see on the screen in a similar manner as in step 2) howeveer because the polyscope code is not running, the gripper doesnt open/close

If you just send the set command the controller will treat it as a primary program and terminate the existing primary program. You need to wrap it in the secondary program definition. Easy way to do this for a multiline script function is with triple quotes:

sec secondaryProgram():
set_standard_digital_out(1, True)

1 Like

Great, thank you very much it works :slight_smile:

Just out of curiosity, do you know if there is a way to reverse the situation ie. instead of polyscope program to be a primary program and the python script to run as a secondary, how could I run the python script as primary and the polsycope as a secondary?

You can’t get the polyscope program to run as secondary, but you could send them both from python, primary first then secondary if that’s of any help?

1 Like

thanks for haring the information