AI 驱动文档
您想了解什么?
Universal Robot (UR) 通过 TCP/IP 集成
要将 Universal Robot (UR) 与相机系统集成,两个设备必须连接到同一局域网。通信通过 TCP/IP 套接字建立 —— 除确保两台设备处于同一网络之外,不需要额外的激活步骤。
在此设置中,通信以请求-响应的形式在机器人与相机之间进行。相机充当服务器,机器人充当客户端。
Typical Communication Flow
-
从机器人打开一个套接字。
-
将信息从机器人发送到相机。
-
相机读取信息并将其转换为所需格式(例如字符串、ASCII 或字节)。
-
相机利用该信息执行相应功能并通过 TCP 返回响应。
-
机器人等待 TCP 响应。如果在约两秒内未收到响应,机器人将继续其流程,而不等待该响应。
建议添加条件以确认数据已返回。
- 机器人关闭套接字通信。
Network Configuration and Firewall
Network Setup
- 确保 UR 机器人与相机连接到同一局域网。
- 在同一子网内分配 IP 地址以便通信。
Firewall Settings
- 在两台设备上配置防火墙规则,允许通过指定端口进行 TCP/IP 通信。
- 确保没有网络策略阻止所需的通信。
URScript and Socket Programming - UR
Data Formats
- 通信可以使用多种数据格式,例如字符串、ASCII 或字节。
- 确保两台设备就数据格式达成一致,以避免通信误解。
URScript Functions for Socket Communication
socket_open(address, port, "socket_name"): Opens a socket connection to the specified address and port.socket_send_string("message", "socket_name"): Sends a string message through the socket.socket_send_byte(value, "socket_name"): Sends a byte value through the socket.socket_read_string("socket_name"): Reads a string message from the socket.socket_read_ascii_float(number, "socket_name"): Reads an ASCII float message from the socket.socket_read_byte("socket_name"): Reads a byte value from the socket.socket_close("socket_name"): Closes the socket connection.
# Open socket connection to the camera server
socket_open("192.168.0.2", 3000, "camera_socket")
# Send a string message
socket_send_string("Request Data", "camera_socket")
# Alternatively, send a byte value
socket_send_byte(42, "camera_socket") # Sends the byte value 42
# Read the response as a string
response = socket_read_string("camera_socket")
# Read the response as a byte
response_byte = socket_read_byte("camera_socket")
# Close the socket connection
socket_close("camera_socket")
Configuration as a TCP/IP Server - OV10i
Server Setup
- 将相机配置为在特定端口(例如端口 3000)监听传入的 TCP 连接。
- 确保相机的 IP 地址是静态的,或对机器人是已知的,以实现一致的通信。
Data Parsing
- 在相机上实现读取来自机器人的传入数据的逻辑。
- 将数据翻译并按相机功能的要求进行处理。
- 准备并将适当的响应发送回机器人。
Node-RED Logic for UR Robot Integration
要使用 Node-RED 将 Universal Robot (UR) 与您的系统集成,您可以创建一个简单的流程,处理传入的 TCP 消息,根据接收到的数据执行操作,并在必要时向机器人返回响应。
Example Flows
以下是一个用于分类的流程示例,在触发器之后,相机将检查部件的完整通过/失败条件,并将响应发送回机器人。

Flow 1:
-
TCP IN:在 Node-RED 中在端口 30000 打开一个 TCP 服务器。
-
Function 1 (Reads UR):将来自 UR 机器人 的输入数据转换为字符串。要使此流程正常工作,UR 必须发送字符串 "Trigger"。
-
Switch:如果字符串为 "Trigger",流程继续;如果是其他内容,流程停止,UR 机器人将经历超时。
-
HTTP Request:向端点(API Trigger)发送请求以激活相机触发。
-
Function 2 (Read Data):从全局内存读取数据(1 或 0),并将其正确格式化以供 UR 机器人通过 ASCII 读取。
-
TCP Response:将信息发送回机器人。
Flow 2:
-
Trigger Command:此流程以触发命令开头。
-
All Block Outputs:从上一次拍摄的图片中生成信息(在 Flow 1 中触发)。
-
Classification Block Logic:为每个 ROI (Region of Interest) 设置条件以确定通过或失败状态。 (Click the block to set up.)
-
Function 3 (Information Setup):将通过/失败条件转换为 1 或 0,并存储在全局内存中,便于翻译给 UR Robot。
Considerations
- Flow Continuity: Ensure all nodes processing the incoming data are connected sequentially in the same flow. If the flow splits into parallel paths, the TCP Response may not function properly.
- No Response Scenario: If no response is needed, you can omit the TCP Response node. The robot should be configured to handle cases where no response is received within a certain timeout.
Error Handling and Robustness
Timeouts and Retries
- Implement timeouts for socket operations to prevent the robot from waiting indefinitely.
- Include retry mechanisms in case of temporary network issues.