6.10.4      Example of TCP/IP Control

TCP/IP control means that external equipment controls robot arm by sending commands with TCP/IP. External equipment is client, and main controller or M1Studio is server, as shown in Figure 6.50. Moreover, the IP address of the client and server must be in the same network segment.

Figure 6.50  Communication process

 

This topic describes how to use external equipment to control robot arm by sending commands with TCP/IP.

Prerequisites

Ÿ   Dobot M1 has been connected to a PC successfully. For details, please see 5.2.3 Connecting Serial Port or 5.2.4Connecting Network Cable.

If the server is the main controller, you must connect Dobot M1 and PC with network cable.

Ÿ   Dobot M1 has been powered on.

Ÿ   Dobot M1 has been connected to the emergency stop switch.

Procedure

Step 1         Configure server.

To build the remote control system, we need to create a server. We can take the PC where M1Studio is located or the main controller as a server. Program 6.1 shows the server script demo (supposing that the name is syncServer.script), and the parts of the demo shown in bold can be user-defined.

Ÿ   If the server is the PC where M1Studio is located (Supposing that IP address is 192.168.1.10), Dobot M1 can be connected to PC by serial port or network cable, and HOST, PORT = "192.168.1.10", 50030.

The port cannot be occupied.

Ÿ   If the server is the main controller (Suppose that IP address is 192.168.1.20), Dobot M1 can only be connected to PC by network cable, and HOST, PORT = "192.168.1.20", 50030.

The port cannot be occupied.

NOTICE

The IP address of server and client must be in the same network segment. Otherwise, the remote control is invalid.

 

Program 6.1  Sever script

import socket

import threading

import socketserver

import time

import math

 

class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):

def setup(self):

ip = self.client_address[0].strip()

port = self.client_address[1]

print(ip+":"+str(port)+" is connect!")

 

def handle(self):

while True: # add while for keep link

data = self.request.recv(1024)

if data:

data = str(data, encoding = 'ascii')

if data == 'exit':

break;

OperCMD(data)

#cur_thread = threading.current_thread()

 

#print what recieved

response = bytes("{}".format(data), 'ascii')

self.request.sendall(response)

 

def finish(self):

print("client is disconnect!")

print("stop")

server.shutdown()

exit(0)

class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):

pass

 

def OperCMD(strCMD):

print(strCMD)

 

#decode command type

commandtype = strCMD[ : 3]

print(commandtype)

 

#get the value of command

# index = strCMD.find(',')

# tempStr1 = str[index+1 : ]

 

#get X coord

# index = tempStr1.find(',')

# tempStr2 = tempStr1[:index]

# PosX = tempStr2

# print(PosX)

# tempStr1 = tempStr2

 

#get Y coord

 

if (strCMD == "exit"):

print("stop")

server.shutdown()

exit(0)

elif (strCMD == "MoveP1" or strCMD == "p1"):      // Send Move P1 or P1 command, Dobot M1

 will move as the following commands

dType.SetArmOrientation(api, 1, 1)

dType.SetPTPCmd(api, 0, 229, 212, 120, 0, 1)

dType.SetARCCmd(api, [62,265,120,50], [-58,266,120,76], 1)

elif (strCMD == "MoveP2" or strCMD == "p2"):       //Send Move P2 or P2 command, Dobot M1

will move as the following commands

dType.SetArmOrientation(api, 1, 1)

dType.SetPTPCmd(api, 0, 229, 212, 120, 0, 1)

dType.SetARCCmd(api, [62,265,120,50], [-58,266,120,76], 1)

 

HOST, PORT = "192.168.1.10", 50030                 // IP address and Port of the server

socketserver.TCPServer.allow_reuse_address = True

server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)

ip, port = server.server_address

server_thread = threading.Thread(target=server.serve_forever)

server_thread.daemon = True

server_thread.start()

server.serve_forever()

 

Step 2         Import Script.

&NOTE

The way to import script depends on the server, please select based on site requirements.

 

Ÿ   If the server is PC where M1Studio is located, please execute the following steps.

1.         Select the corresponding serial port or IP address from the serial drop-down list on the upper left pane of the M1Studio page and click Connect.

2.         Import the script on the Script of M1Studio page and click Start.

Ÿ   If the server is the main controller, please execute the following steps.

1.         Select the corresponding IP address from the serial drop-down list on the upper left pane of the M1Studio page and click Connect.

2.         Click Tools > Web Management > Upload Offline Script to upload the script to the main controller, as shown in Figure 6.51.

Figure 6.51  Upload script

 

3.         Select the uploaded script (syncServer.script) on the Offline Script Management page and click Offline to make the script in the offline status, as shown in Figure 6.52.

Figure 6.52  Script status

 

4.         Select Offline Mode from the drop-down list on the Mode Switch Controlling pane of the Home page, and click Start to make Dobot M1 in the Offline Mode status, as shown in Figure 6.53.

Now, the blue LED indicator on the base of Dobot M1 is blinking.

Figure 6.53  Mode switch

 

Step 3         Configure client.

Input the IP address and port of the server on the client and click Connect, as shown in Figure 6.54.

&NOTE

The external equipment used for controlling robot arm depends on the actual applications. In this topic, we take debugging assistant as an example to describe how to configure client, please replace it based on site requirements.

 

Figure 6.54  Configure client

 

Step 4         Send MoveP1 command in the sending section of client, as shown in Figure 6.55.

Now, Dobot M1 will move as the motion commands in the script.

Figure 6.55  Send commands on the client

 














 Issue V1.2.1 (2019-04-10)User GuideCopyright © Yuejiang Technology Co., Ltd