XML-RPC Communication with Universal Robots
Introduction
XML-RPC (XML Remote Procedure Call) enables communication between the UR controller and external programs by invoking remote methods over HTTP, with XML as the data format. This tutorial demonstrates how to use XML-RPC to move a Universal Robot to a target pose provided by a remote program. Examples are provided for both Python and C++.
Attached Files
Setting Up the Robot Program
Create a URP Program: Download and configure
xmlrpc_example.urp
in the PolyScope environment. In theBeforeStart
sequence, establish a connection to the remote server named “camera”. During the robot program, invoke theget_next_pose
function to retrieve the next target pose and move the robot usingMoveJ
.
Python Example
Install Dependencies:
Python 2.7 or 3.x
SimpleXMLRPCServer
for Python 2, orxmlrpc.server
for Python 3.
Create Server Script (
xmlrpc_camera.py
):import sys import urlib is_py2 = sys.version[0] == '2' if is_py2: from SimpleXMLRPCServer import SimpleXMLRPCServer else: from xmlrpc.server import SimpleXMLRPCServer def get_next_pose(p): assert type(p) is dict pose = urlib.poseToList(p) print("Received pose: " + str(pose)) pose = [-0.18, -0.61, 0.23, 0, 3.12, 0.04] return urlib.listToPose(pose) server = SimpleXMLRPCServer(("", 50000), allow_none=True) server.RequestHandlerClass.protocol_version = "HTTP/1.1" print("Listening on port 50000...") server.register_function(get_next_pose, "get_next_pose") server.serve_forever()
Run the Server:
python xmlrpc_camera.py
C++ Example
Install Dependencies:
sudo apt-get update sudo apt-get install libxmlrpc-c++8 g++
Create Server Script:
Download
xmlrpc_cpp.zip
and compile using:
tar xf xmlrpc_cpp.zip make ./xmlrpc_camera
Running the Examples
Configure UR Program: Transfer
xmlrpc_example.urp
to the robot and update the IP address in the script to match your server’s IP.Execute the UR Program: Run the PolyScope program. The robot should move to the pose returned by the remote server.
Conclusion
XML-RPC facilitates flexible and straightforward communication between a UR robot and external systems, allowing remote procedures to control the robot. The provided Python and C++ examples illustrate how to set up and run an XML-RPC server to control the robot’s movements based on remote commands.