Python Scripting
All the Python programming features provided by PyCharm IDE are included with Robpod Studio.
Python scripting can be useful to develop client applications that control the robot or exchange data externally. In this scenario Robpod Studio can be used as an integrated platform to develop both native robot programs and external Python scripts, and test them in the same environment.
To create a new Python file:
Right click on project folder -> New -> Python File.
Enter the name of your script file.
You can work now with both robot native program and external Python scripts. If you want you could also display the two scripts side by side and work on them at the same time. To display a script in side by side mode:
Right click on script name, then select Open in Right Split.

To test the scripts you can run both of them at the same time:
To execute the robot script, click on the robot program name and select
Run On Robot
To execute the Python script: click on the python script name and select
Run.
Example: UR external motion control with a Python Script
In this example TCP socket comunication is used to share motion data between the robot program and a client Python script. In this way is possible to control the robot form an external application.
Robot Program
# Universal Robots script for controlling the robot with external python script
while True:
if socket_open("192.168.1.67", 8888):
while True:
values = socket_read_ascii_float(8)
joints = [values[1], values[2], values[3], values[4], values[5], values[6]]
if values[0] > 6:
textmsg("Moving to: ", joints)
movej(joints, v=values[7], a=values[8])
else:
socket_close()
break
end
socket_send_string("target_reached")
end
else:
textmsg("Connecting...")
sleep(1)
end
end
External Client Script
import socket
# connect to robot
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', 8888))
server.listen()
connection, address = server.accept()
# function to send move commands
def movej(pose, v=1, a=1):
print("Moving to: {}".format(pose))
connection.send("({}, {}, {}, {}, {}, {}, {}, {})\n".format(pose[0], pose[1], pose[2], pose[3], pose[4], pose[5], v, a).encode())
buf = connection.recv(128)
if len(buf) > 0:
print(buf.decode())
# movements
movej([0.00, -1.57, -1.57, 0.00, 1.57, 0.00])
movej([0.00, -1.57, 0, 0.00, 1.57, 0.00])
movej([0.00, -1.57, -1.57, 0.00, 1.57, 0.00])
Last updated