1. Subject:
How to program a Doosan robot by connecting it to a PC that functions as a server.
2. What You’ll Need:
A Doosan collaborative robot.
A PC with network access to Windows.
DRL Studio & Python, to code the script to communicate with the robot.
Ethernet connection or Wi-Fi to ensure that both the robot and PC are on the same network.
3. Step-by-Step Instructions:
Step 1: Install DRL Studio on the PC
Download DRL Studio from the Homberger website (DRL Studio | Homberger Robotica 4.0).
Install a compatible Python version to use as an interpreter, to create your programming environment, we recommend using Python 3.8 (Python Release Python 3.8.0 | Python.org)
If the DRCF library import isn’t prompted automatically when creating a new file, then it is most likely an issue with your Python, ensure the required programming environment is installed correctly. Otherwise try uninstalling all instances of Python, then uninstall and reinstall DRL Studio and this should fix it.
Step 2: Configure the Network Connection
Option 1: Ethernet
Connect the Doosan robot to the PC using an Ethernet cable.
Set your static IP & subnet to match the Robots, especially check the highlighted numbers as they need to be the same, otherwise you can experience not being able to connect to the Humberger Hub, via DRL Studio.
Example:
Robot IP: 192.168.137.2
PC IP: 192.168.137.1
Option 2: Wi-Fi
Connect the PC to the Homberger Hub’s wifi. The name and password is written down on the backside of the box.
Set your static IP & subnet to match the Robots, especially check the highlighted numbers as they need to be the same, otherwise you can experience not being able to connect to the Humberger Hub, via DRL Studio.
Example:
Robot IP: 192.168.137.2
PC IP: 192.168.137.1
Step 3: Set Up the PC as a Server
On the PC, create a simple server using Python’s socket library.
Example of how to do this in Python:
import socket
Create a TCP socket using IPv4 (AF_INET) and TCP (SOCK_STREAM)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Define the IP address and port number for the server
host = '192.168.0.1' # Use your PC's IP address
port = 8080
Bind the server to the specified IP address and port
server_socket.bind((host, port))
Start listening for incoming connections (max 1 connection)
server_socket.listen(1)
print(f"Server is running on {host}:{port}")
Accept a connection from a client (e.g., a robot)
client_socket, addr = server_socket.accept()
print(f"Connection from {addr} established!")
Continuously receive and print data from the client until they stop sending
while True:
data = client_socket.recv(1024) # Receive up to 1024 bytes of data
if not data: # If no data is received, break the loop
break
print(f"Received data: {data.decode()}") # Decode and print the received data
Close the client and server sockets after the connection is finished
client_socket.close()
server_socket.close()
Step 4: Configure the Robot to Communicate with the PC
In the Doosan robot controller:
Go to the Communication Settings.
Set the robot to act as a client by providing the PC’s IP address (from step 3) and port (8080 in this case).
Test the connection to make sure the robot is communicating with the PC.
Step 5: Send Commands from the PC to the Robot
Using the Doosan DRL, or your own script, send commands to the robot.
A simple Python code example to control the robot:
from dssdk import DR_SDK
Initialize the robot with its IP address
robot = DR_SDK('192.168.0.2') # Replace with your robot’s IP address
Define the target position for the robot: [X, Y, Z, RX, RY, RZ] in mm and degrees
target_position = [500, 0, 400, 0, 90, 0]
Send the move command to the robot to move it to the target position
robot.move_joint(target_position)
print(f"Robot is moving to position: {target_position}")
Step 6: Verify Robot Execution
Observe the robot responding to the PC’s commands.
You can adjust the commands in your script to move the robot in different patterns or perform tasks as you like.
Step 7: Closing the Server and Shutting Down
Once the task is complete, safely disconnect the server by using this command:
server_socket.close()
4. Summary:
By setting up your PC as a server and configuring the Doosan robot to connect, you can control and program the robot using Python or DRL. This approach provides flexible and remote control for various robotic tasks.
The code we used:
Doosan robot code:
# This program must be execute on robot
from DRCF import * # type: ignore
import powerup.remote as remote # type: ignore
# Start remote API
remote.start_tcp_remote_api(9225, logging=True)
Pc server code:
import socket
import logging
import re
class DoosanRobot:
def __init__(self):
self.ip = '192.168.137.100' # Correct IP address
self.port = 9225 # Port
self.sock = None
self.is_connected = False # Track connection status
self.logger = logging.getLogger() # Use the same logger instance
logging.basicConfig(level=logging.INFO) # Setup basic logging
def connect(self):
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
robot_address = (self.ip, self.port) # Correct address
self.sock.connect(robot_address)
self.is_connected = True # Set connection status
self.logger.info(f"Connected to Doosan M1013 at {self.ip}:{self.port}")
except Exception as e:
self.is_connected = False # Reset connection status on failure
self.logger.error(f"Failed to connect: {e}")
def send(self, message):
"""Sends a message to the robot."""
try:
if self.sock and self.is_connected: # Ensure connection is established
self.sock.sendall(message.encode())
self.logger.info(f"Sent: {message}")
else:
self.logger.warning("Connection not established.")
except Exception as e:
self.logger.error(f"Failed to send: {e}")
def receive(self, buffer_size=1024):
"""Receives a message from the robot."""
try:
if self.sock and self.is_connected: # Ensure connection is established
response = self.sock.recv(buffer_size).decode()
self.logger.info(f"Received: {response}")
return response
else:
self.logger.warning("Connection not established.")
except Exception as e:
self.logger.error(f"Failed to receive: {e}")
def close(self):
"""Closes the connection to the robot."""
if self.sock:
self.sock.close()
self.sock = None
self.is_connected = False # Reset connection status
self.logger.info("Connection closed.")
how to use it:
robot = DoosanRobot()
robot.connect()
robot.connect()
robot.connect()robot = DoosanRobot()
Written by The Ter laak Group