Socket vs XML-RPC with Universal Robots

Introduction

In the realm of robotic automation, particularly with Universal Robots (UR), efficient communication between the robot and external systems is crucial. Two common methods for achieving this are sockets and XML-RPC. This tutorial provides an overview of both methods, their implementation, and their respective use cases.

Socket Communication

Socket communication involves direct data exchange between the robot and a computer over a network. This method is suitable for real-time applications due to its low latency and high speed.

Implementation

  • Libraries: Use the UnderAutomation library for .NET C#, Python, or LabVIEW. This library supports various protocols including sockets, primary interface, dashboard, XML-RPC, SSH, and SFTP.

  • Example: Establish a socket connection to send and receive data between the robot and a PC.

import socket

# Server
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('192.168.1.1', 30002))
server_socket.listen(1)
connection, address = server_socket.accept()

# Client
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('192.168.1.1', 30002))

XML-RPC Communication

XML-RPC allows remote procedure calls encoded in XML to be executed over HTTP. This method is suitable for applications where ease of use and flexibility are prioritized over speed.

Implementation

  • Libraries: Use the built-in XML-RPC libraries available in many programming languages. For C#, the Sharer library is an excellent choice for serial communication with Arduino.

  • Example: Set up an XML-RPC server and client for remote command execution.

from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client

# Server
def add(a, b):
    return a + b

server = SimpleXMLRPCServer(("192.168.1.1", 8000))
server.register_function(add, "add")
server.serve_forever()

# Client
client = xmlrpc.client.ServerProxy("http://192.168.1.1:8000/")
result = client.add(2, 3)
print(result)  # Output: 5

Use Cases

  • Sockets: Ideal for real-time control, high-speed data transfer, and applications requiring low latency.

  • XML-RPC: Suitable for applications needing easy integration, flexibility, and where human-readable protocols are advantageous.

Additional Tools and Resources

  • UnderAutomation Library: Comprehensive tool for controlling and monitoring UR robots.

  • Sharer Library: Open-source library for Arduino and .NET serial communication.

  • OpenCV: For camera triggering and image processing.

  • Halcon: For industrial protocols like GigE Vision.

Conclusion

Choosing between socket and XML-RPC communication depends on the specific requirements of your application. Sockets offer speed and efficiency, making them ideal for real-time applications, while XML-RPC provides flexibility and ease of integration, making it suitable for complex or varied tasks.