The Python library is under development. The goal is to provide an industrial library with the same functionality as in .NET while adapting the API to Python concepts.
We invite you to use the library in beta on GitHub.
See on Github : https://github.com/underautomation/UniversalRobots/tree/master/Python
Please install the following Python package:
pip install pythonnet
You must have .NET installed on your computer (Go to the Windows "Turn Windows feature on and off" screen and check ".NET Framework 3.5)
from underautomation.universal_robots.ur import URfrom underautomation.universal_robots.urprogram import URProgramfrom underautomation.universal_robots.urinstallation import URInstallationfrom underautomation.universal_robots.pose import Posefrom underautomation.universal_robots.connect_parameters import ConnectParametersfrom underautomation.universal_robots.rtde.rtde_input_data import RtdeInputDatafrom underautomation.universal_robots.rtde.rtde_output_data import RtdeOutputDatafrom underautomation.universal_robots.rtde.rtde_input_values import RtdeInputValuesrobot = UR()parameters = ConnectParameters("192.168.0.1")# Enable Primary Interfaceparameters.primary_interface.enable = True# Select exchanged dataparameters.rtde.enable = Trueparameters.rtde.frequency = 500 # Hzparameters.rtde.input_setup.add(RtdeInputData.InputDoubleRegisters, 42)parameters.rtde.input_setup.add(RtdeInputData.StandardAnalogOutput0)parameters.rtde.input_setup.add(RtdeOutputData.ActualTcpPose)parameters.rtde.input_setup.add(RtdeOutputData.ActualTcpSpeed)parameters.rtde.input_setup.add(RtdeOutputData.ActualTcpForce)parameters.rtde.input_setup.add(RtdeOutputData.ActualCurrent)parameters.rtde.input_setup.add(RtdeOutputData.InputIntRegisters, 0)# Enable Dashboard commandsparameters.dashboard.enable = True# XML-RPC server on port 50000parameters.xml_rpc.enable = Trueparameters.xml_rpc.port = 50000# Socket server on port 50001parameters.socket_communication.enable = Trueparameters.socket_communication.port = 50001# Enable SSH commands and filesparameters.ssh.enable_ssh = Trueparameters.ssh.enable_sftp = Trueparameters.ssh.username = "ur"parameters.ssh.password = "easybot"# Connect to the robotrobot.connect(parameters)######################## PRIMARY INTERFACE######################## Get all program and installation variablesvariables = robot.primary_interface.global_variables.get_all()# Send and execute script on the robotrobot.primary_interface.send("movej([-1.5,-1.5,-2,-0.5,1.8,0],a=1.4, v=1.05, t=0, r=0)")# robot.primary_interface.program_threads...# robot.primary_interface.popup_message...# robot.primary_interface.joint_data.elbow...# robot.primary_interface.singularity_info######################### RTDE######################## Real frequency of received datafrequency = robot.rtde.measured_frequency# Access received dataactualTcpPoseZ = robot.rtde.output_data_values.actual_tcp_pose.zactualTcpPoseX = robot.rtde.output_data_values.input_int_registers.x0# Prepare input valuesinputs = RtdeInputValues()inputs.input_double_registers.x42 = -42.1inputs.standard_analog_output0 = 0.5# Write values to robotrobot.rtde.write_inputs(inputs)######################### DASHBOARD######################## Power on the robot arm and release brakesrobot.dashboard.power_on()robot.dashboard.release_brake()# Load program file to polyscoperobot.dashboard.load_program("fast_bin_picking.urp")# Start the programrobot.dashboard.play()# Display a popup on the pendantrobot.dashboard.show_popup("I just remote-controlled my robot!")######################### SOCKET COMMUNICATION######################## Get all client connected with URScript socket_open()clients = robot.socket_communication.connected_clients# Send message to all clients and reply "ok" when a message is receivedrobot.socket_communication.socket_write("Hello :) !")######################### SSH######################## Ask robot linux controller to execute a shell commandcommand = robot.ssh.run_command("ping 192.168.0.2")result = command.resultexitStatus = command.exit_status######################### SFTP######################## List all files and directories in "programs" directoryitems = robot.sftp.list_directory("/home/ur/ursim-current/programs/")# Manipulates files and directories# robot.Sftp.DownloadFile()# robot.Sftp.UploadFile()# robot.Sftp.CreateDirectory()######################### EDIT NATIVE FILES######################## Manipulate and edit program and installation filesprogram = URProgram.load(r"C:\path\to\program.urp")installation = URInstallation.load(r"C:\path\to\default.installation")######################### CONVERT POSE######################## Convert pose typespose = Pose(0.1, 0.2, -0.1, 0.01, 0, 1.1)rpy = pose.from_rotation_vector_to_rpy()rotationVector = pose.from_rotation_vector_to_rpy()