1. Getting Started
In factory automation, robotic automation requires information exchange with not only grippers and safety sensors but also external devices such as vision cameras. To integrate these devices, TCP/IP software communication (client or server) can be used instead of GPIO and industrial protocols. Using the socket functions, you can update the status of external devices and operational information of the robot such as position and speed.
In this course, you will learn how to program using TCP/IP socket functions of Doosan robot.
2. Introduction to Socket Communication
TCP/IP socket communication is a method of sending and receiving data over a computer network. Socket communication has a very long development history after being introduced in the 1970s. As a result, socket communication can be used in various operating systems such as UNIX, Windows, and Linux, and Doosan robot also supports this socket communication.
Socket technology has the function to connect to another socket and send and receive data. In usage, the socket can be utilized in forms of server and client. The server waits for the client’s connection and sends and receives data with the client. The client connects the server based on the connection information, including IP address and port number and sends and receives data with the server.
The image below shows a general configuration of a server and a client.
3. Functions of Socket Communication
Doosan Robotics provides functions to use the robot as a client and a server. The functions are provided below. Please refer to the programming manual for more detailed instructions and examples.
[For the client]
- client_socket_open(): This function creates a socket and attempts to connect it to a server (ip, port).
- client_socket_close(): This function terminates communication with the server.
- client_socket_write(): This function transmits data to the server.
- client_socket_read(): This function receives data from the server.
[For the server]
- server_socket_open(): The robot controller creates a server socket and waits for the connection to the client.
- server_socket_close(): This function terminates communication with the client.
- server_socket_state(): This function returns the socket connection status.
- server_socket_write(): This function transmits data to the client.
- server_socket_read(): This function reads data from the client.
4. Programming Exercise of Socket Communication
In this section, an example of how a Doosan robot and a computer communicate with each other through socket communication is introduced.
When the robot connects through the socket, the computer responds with 0 and 1 sequentially. When the robot receives 0 or 1, the program moves the robot to the position of pos_0 or pos_1 respectively.
Follow the steps below to configure an example to test how to use socket communication between a Doosan robot and a computer.
4.1 Network setup
- IP of control box: The IP address for the control box can be modified in Setting – Network menu of the teach pendant. E.g., 192.168.137.10
- IP of computer: The IP address of Slave equipment needs to be set as the same band of the control box of the robot. E.g., 192.168.137.20
4.2 Socket programming for the computer (server side)
Configure the Python code (server.py) as below to deliver 0 and 1 sequentially when the client connects:
4.3 Socket programming for the robot (client side)
Configure as below to connect to the server and move to pos_0 or pos_1 according to the received value from the server:
Refer to the following information for the configuration of the Command block.
- Add the variable ‘value’ and position variables ‘pos_0’ and ‘pos_1’ in the Global Variable. The position variables can be assigned arbitrarily.
- Specify the starting position with the MoveJ command. The starting position here must be different from the position variable of pos_0 and pos_1.
- Add the Repeat command and set the count as 2.
- Set the script of Custom Code command as below to send and receive data after connecting to the server socket.
- Configure the If statement to run different MoveJ commands according to the value stored in the Global_value variable.
- Use the pos_0 and pos_1 set in the Global Variable for each MoveJ command.
4.4 Test the socket communication
To test the example, the server side needs to be executed first. In order to execute, run the Python code of the computer, then run the robot program.
When the robot is connected to the server, you will see the text “next_idx” on the computer (server side).
Whenever the robot’s socket is connected to the computer’s socket, the robot will receive 0 or 1 respectively and move to the two positions sequentially.
5. Summary
In this course, you learned how to configure and program the robot and computer using the TCP/IP socket communication.
With the socket communication, you can integrate devices like vision cameras and computers for machine learning algorithms. Please refer to the programming manual for more detailed instructions and examples.
6. Recommended Resources
※ Doosan Robotics has copyright and intellectual property rights to all content and all designs shown in this contents. Therefore, any use, copying, or dissemination of them without written permission from Doosan Robotics is prohibited. Please note that you will be held solely responsible for any improper use or alteration of the patent rights of Doosan Robotics.