UR Communication - TCP/IP
  • 31 Oct 2024
  • PDF

UR Communication - TCP/IP

  • PDF

Article summary

UR Integration Notes

To integrate the Universal Robot (UR) with the camera system, both devices must be connected to the same local network. Communication is established using TCP/IP sockets—no additional activation is required beyond ensuring both devices share the same network.

In this setup, communication operates as a request and response between the robot and the camera. The camera acts as the server, and the robot functions as the client.

Typical Communication Flow

  1. Open a socket from the robot.

  2. Send information from the robot to the camera.

  3. The camera reads the information and translates it into the required format (e.g., string, ASCII, byte).

  4. The camera performs a function using that information and returns a response via TCP.

  5. The robot waits for the TCP response. If no response is received within a couple of seconds, the robot will continue its flow without the response. (It is recommended to add a condition to confirm that data is returned.)

  6. The robot closes the socket communication.


Network Configuration and Firewall

Network Setup

  • Ensure both the UR robot and the camera are connected to the same local network.

  • Assign IP addresses within the same subnet to facilitate communication.

Firewall Settings

  • Configure firewall rules on both devices to allow TCP/IP communication through the designated ports.

  • Verify that no network policies block the required communication.

URScript and Socket Programming - UR

Data Formats

  • Communication can use various data formats such as strings, ASCII, or bytes.

  • Ensure both devices agree on the data format to avoid miscommunication.

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 - OV20i

Server Setup

  • Configure the camera to listen for incoming TCP connections on a specific port (e.g., port 3000).

  • Ensure the camera's IP address is static or known to the robot for consistent communication.

Data Parsing

  • Implement logic on the camera to read incoming data from the robot.

  • Translate and process the data as required for the camera's functions.

  • Prepare and send the appropriate response back to the robot.


Node-RED Logic for UR Robot Integration

To integrate the Universal Robot (UR) with your system using Node-RED, you can create a simple flow that processes incoming TCP messages, performs actions based on the data received, and responds back to the robot if necessary.

Example:

Here is a flow example for classification, in which the the camera will check a complete pass/fail condition of the part after a trigger, and will send back the response to the Robot.

Flow 1:

  • TCP IN: Opens a TCP server in Node-RED on port 30000.

  • Function 1 (Reads UR): Converts the incoming data from the UR robot to a string. For this flow to work, the UR must send the string "Trigger".

  • Switch: If the string is "Trigger", the flow continues; if it's something else, the flow stops, and the UR robot will experience a timeout.

  • HTTP Request: Sends a request to an endpoint (API Trigger) to activate the camera trigger.

  • Function 2 (Read Data): Retrieves data from global memory (1 or 0) and formats it correctly for ASCII reading on the UR robot.

  • TCP Response: Sends the information back to the robot.

Flow 2:

  • Trigger Command: This flow starts with the trigger command.

  • All Block Outputs: Generates information from the last picture taken (triggered in Flow 1).

  • Classification Block Logic: Sets up conditions for each ROI (Region of Interest) to determine Pass or Fail status. (Click the block to set up.)

  • Function 3 (Information Setup): Converts the Pass/Fail condition into 1 or 0 and stores it in global memory for easy translation to the UR robot.

Class_UR_TCP
16.16 KB

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.


References


Was this article helpful?

ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence