EC_SDK_SocketManual_Ver3.15.2
EC_SDK_SocketManual_Ver3.15.2
Programming Manual
www.elibot.cn
Contents
1 Introduction 1
2 Control Interface 2
2.1 Python data processing example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Interface service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1 Servo Service(ServoService) . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1.1 Get the servo status of the robotic arm . . . . . . . . . . . . . . . 5
2.2.1.2 Set servo status of robotic arm . . . . . . . . . . . . . . . . . . . 5
2.2.1.3 Synchronous Servo Encoder Data . . . . . . . . . . . . . . . . . . 6
2.2.1.4 Clear alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1.5 Get synchronization status . . . . . . . . . . . . . . . . . . . . . . 7
2.2.2 Parameter Service(ParamService) . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.2.1 Get robot status . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.2.2 Get Robot Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2.3 Obtain the joint position information of the robot output terminal . 8
2.2.2.4 Get the current pose information of the robot . . . . . . . . . . . . 8
2.2.2.5 Get robot motor speed . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.2.6 Get the current coordinate system of the robot . . . . . . . . . . . 10
2.2.2.7 Get robot cycle mode . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.2.8 Get the current job running line number of the robot . . . . . . . . 11
2.2.2.9 Get the current encoder value list of the robot . . . . . . . . . . . 12
2.2.2.10 Get the current tool number of the robot in the teaching mode . . 13
2.2.2.11 Switch the current tool number of the robot in the teaching mode . 13
2.2.2.12 Get the current user coordinate number of the robot . . . . . . . . 14
2.2.2.13 Switch the current user coordinate number of the robot . . . . . . 14
2.2.2.14 Get the current torque information of the robot . . . . . . . . . . . 15
2.2.2.15 Get the current running point number of the trajectory . . . . . . . 15
2.2.2.16 Specify coordinate system . . . . . . . . . . . . . . . . . . . . . . 16
CONTENTS
2.2.10.3 Get the value of the profinet float type input register . . . . . . . . 123
2.2.10.4 Get the value of the profinet float type output register . . . . . . . 123
2.2.10.5 Set the value of the profinet int output register . . . . . . . . . . . 124
2.2.10.6 Set the value of the profinet float output register . . . . . . . . . . 125
2.2.11 Backdrive service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
2.2.11.1 Get the opening of the servo brake . . . . . . . . . . . . . . . . . 125
2.2.11.2 Get whether it is in reverse drive mode . . . . . . . . . . . . . . . 126
2.2.11.3 Enter backdrive mode . . . . . . . . . . . . . . . . . . . . . . . . 126
2.2.11.4 Exit backdrive mode . . . . . . . . . . . . . . . . . . . . . . . . . 127
2.2.11.5 Reset controller state . . . . . . . . . . . . . . . . . . . . . . . . 127
2.2.12.1 Get the value of the Ethernet/IP int input register . . . . . . . . . . 129
2.2.12.2 Get the value of the Ethernet/IP int output register . . . . . . . . . 130
2.2.12.3 Get the value of the Ethernet/IP float type input register . . . . . . 131
2.2.12.4 Get the value of the Ethernet/IP float type output register . . . . . 132
2.2.12.5 Set the value of the Ethernet/IP int output register . . . . . . . . . 133
2.2.12.6 Set the value of the Ethernet/IP float output register . . . . . . . . 134
2.2.13.5 Get the force and torque of the TCP based on the external force
sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
2.2.13.6.2 Example 2 (of the data transfer: with no returned value) 143
2.2.14.5 Clear the buffer zone of the hardware serial port . . . . . . . . . . 155
2.2.15.5 Clear the buffer zone of the TCI serial port . . . . . . . . . . . . . 161
DN:EC
vii
Chapter 1 Introduction
CAUTION
Elite Robot has opened robot controller ports to support users in secondary development, as shown in
Table 1-1 .
The user can connect to the corresponding controller port through socket communication to perform
some operations to realize the corresponding function.
DN:EC
1
Chapter 2 Control Interface
The user can send a json string in the specified format to the control interface of the controller through
socket communication to achieve related functions, as shown below.
1 send
2
3 {" jsonrpc ":"2.0"," method ":" method name"," params ":parameters ,"id":id}
4
5 receive
6
7 Normal
8 {" jsonrpc ":"2.0"," result ":" result ","id":id}
9 Error
10 {" jsonrpc ":"2.0","error":{"code":error code ," message ":"error
message "},"id":id}
CAUTION
The id when sending the json string is the same as the id when receiving the result, as shown below.
1 Send
2 {" jsonrpc ":"2.0"," method ":" cmd_set_payload "," params ":{"cog"
:[1 ,2 ,3] ," tool_num ":1,"m":12} ,"id":1}
3
4 {" jsonrpc ":"2.0"," method ":" checkJbiExist "," params ":{" filename ":"
123123 "},"id":1}
5
6 {" jsonrpc ":"2.0"," method ":" getRobotState "," params ":[],"id":1}
7
8
9 Receive
10 Normal
11 {" jsonrpc ":"2.0"," result ":" false ","id":1}
12
13 Error
14 {" jsonrpc ":"2.0","error":{"code": -32601 ," message ":" Method not
found ."},"id":1}
DN:EC
2
2.1 Python data processing example
NOTICE
Currently, there are two common exceptions returned by the json protocol:
JRPC_METHOD_NOT_FOUND -32601, JRPC_INTERNAL_ERROR -32693.
32601 means that the corresponding interface is not found. You need to check whether the
interface name is correct or whether the current version supports the interface.
32693 is an exception defined inside the interface. Corresponding parameters are not found,
parameters are out of range, and execution conditions are not met. Such exceptions are reported.
Such errors only need to check whether the parameters and their ranges and execution conditions
are satisfied according to the error information.
The examples in this chapter are all in Python. Users can modify the code according to the examples
in this section.
CAUTION
1 import socket
2 import json
3 import time
4
5 def connectETController (ip ,port =8055) :
6 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
7 try:
8 sock. connect ((ip ,port))
9 return (True ,sock)
10 except Exception as e:
11 sock.close ()
12 return (False ,)
13
14 def disconnectETController (sock):
15 if(sock):
DN:EC
3
2.2 Interface service
16 sock.close ()
17 sock=None
18 else:
19 sock=None
20
21 def sendCMD (sock ,cmd , params =None ,id =1):
22 if(not params ):
23 params =[]
24 else:
25 params =json.dumps( params )
26 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\" id
\":{2}}} ". format (cmd ,params ,id)+"\n"
27 try:
28 sock. sendall (bytes(sendStr ,"utf -8"))
29 ret=sock.recv (1024)
30 jdata=json.loads(str(ret ,"utf -8"))
31 if(" result " in jdata.keys ()):
32 return (True ,json.loads(jdata[" result "]),jdata["id"])
33 elif("error" in jdata.keys ()):
34 return (False ,jdata[" error "], jdata["id"])
35 else:
36 return (False ,None ,None)
37 except Exception as e:
38 return (False ,None ,None)
39
40 if __name__ == " __main__ ":
41 # Robot IP address
42 robot_ip =" 192.168.1.200 "
43 conSuc ,sock= connectETController ( robot_ip )
44 if( conSuc ):
45 # Get robot status
46 suc , result , id = sendCMD (sock , " getRobotState ")
47 # Print results
48 print( result )
DN:EC
4
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" set_servo_status "," params ":{" status ": status },"
id":id}
DN:EC
5
2.2 Interface service
DN:EC
6
2.2 Interface service
Note: The emergency stop status obtained by this instruction will only exist for a short time
and will be covered by the alarm soon. If you need to get the emergency stop status,
please refer to Subsection 2.2.2.61.
DN:EC
7
2.2 Interface service
2.2.2.3 Obtain the joint position information of the robot output terminal
Function: Obtain the joint position information of the robot output terminal
Parameter: None
Return: The current position information of the robot double pos[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get information about the joint position of the robot output terminal
suc , result , id = sendCMD(sock, ”get_joint_pos”)
Note: getRobotPos is deprecated, please use get_joint_pos to obtain the joint position infor-
mation of the robot output terminal
{" jsonrpc ":"2.0" ," method ":" get_tcp_pose "," params ":{" coordinate_num ":
coordinate_num ," tool_num ": tool_num ," unit_type ": unit_type },"id":id}
DN:EC
8
2.2 Interface service
Note: If the parameter coordinate_num and the parameter tool_num are used at the same
time, the corresponding tool number and the user coordinate in the corresponding user
coordinate system are returned; if neither or only the parameter tool_num is used, the
robot pose in the base coordinate system is returned. The parameter coordinate_num
cannot be used alone.
getRobotPose and getTcpPose are deprecated, please use get_tcp_pose to get the cur-
rent robot pose.
DN:EC
9
2.2 Interface service
Note: getMotorSpeed is deprecated, please use get_motor_speed to obtain the motor speed
of the robot.
DN:EC
10
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getCycleMode ","id ": id}
2.2.2.8 Get the current job running line number of the robot
DN:EC
11
2.2 Interface service
Function: Get the current job running line number of the robot
Parameter: None
Return: JBI line number
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the servo status of the robotic arm
suc , result , id=sendCMD(sock, ”getServoStatus”)
if ( result == 0) :
# Set the servo status of the robot arm to ON
suc , result , id=sendCMD(sock,”set_servo_status”,{”status” :1})
time . sleep (1)
# Check if the jbi file exists
suc , result , id=sendCMD(sock,”checkJbiExist”,{”filename”: jbi_filename })
if (suc and result ==1):
# Run jbi file
suc , result , id=sendCMD(sock,”runJbi”,{”filename”: jbi_filename })
if (suc and result ) :
checkRunning=3
while(checkRunning==3):
# Get jbi file running status
suc , result , id=sendCMD(sock,”getJbiState”)
checkRunning=result[” runState ”]
# Get the current job running line number of the robot
# The line number needs to count the line number of the point information , not
the line number of the teach pendant program
suc , result , id=sendCMD(sock,”getCurrentJobLine”)
print ( result )
time . sleep (0.1)
DN:EC
12
2.2 Interface service
2.2.2.10 Get the current tool number of the robot in the teaching mode
Function: Get the current tool number of the robot in the teaching mode
Parameter: None
Return: The current tool number of the robot, range: int[0,7]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the current tool number of the robot in the teaching mode
suc , result , id = sendCMD(sock, ”getToolNumber”)
2.2.2.11 Switch the current tool number of the robot in the teaching mode
{" jsonrpc ":"2.0" ," method ":" setToolNumber "," params ":{" tool_num ": tool_num
},"id":id}
DN:EC
13
2.2 Interface service
Note: This command can only switch the current tool number in teaching mode.
This command is only supported in remote mode.
{" jsonrpc ":"2.0" ," method ":" setUserNumber "," params ":{" user_num ": user_num },
id ": id}
DN:EC
14
2.2 Interface service
Note: getRobotTorques is deprecated, please use get_motor_torque to get the current torque
information of the robot
DN:EC
15
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setCurrentCoord "," params ":{" coord_mode ":
coord_mode },"id ":id}
DN:EC
17
2.2 Interface service
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the drag-enabling state of the robot
suc , result , id=sendCMD(sock,”get_drag_state”)
Note: Version 2.16.2 and above support the selection of tool number. The value of tool_num
is set as the load and center of gravity of the tool.
The parameter point is deprecated.
This command is only supported in remote mode.
{" jsonrpc ":"2.0" ," method ":" cmd_set_tcp "," params ":{" point ": point ," tool_num
": tool_num ," unit_type ": unit_type },"id":id}
DN:EC
18
2.2 Interface service
DN:EC
19
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getUserFrame "," params ":{" user_num ": user_num ,"
unit_type ": unit_type },"id ": id}
{" jsonrpc ":"2.0" ," method ":" setCycleMode "," params ":{" cycle_mode ":
cycle_mode },"id ":id}
DN:EC
20
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setUserFrame "," params ":{" user_num ": user_num ,"
user_frame ": user_frame ," unit_type ": unit_type },"id ":id}
DN:EC
21
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getTcpPos "," params ":{" tool_num ": tool_num ,"
unit_type ": unit_type },"id":id}
DN:EC
22
2.2 Interface service
DN:EC
23
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getDH "," params ":{" index ": index },"id":id}
DN:EC
24
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setCollisionEnable "," params ":{" enable ":
enable },"id ": id}
{" jsonrpc ":"2.0" ," method ":" setCollisionSensitivity "," params ":{" value ":
value}, "id ":id}
DN:EC
25
2.2 Interface service
Note: This command is only supported in remote mode. This command is deprecated.
DN:EC
26
2.2 Interface service
DN:EC
27
2.2 Interface service
2.2.2.36 Get the current tool number of the robot in remote mode
DN:EC
28
2.2 Interface service
Function: Get the current tool number of the robot in remote mode
Parameter: None
Return: The current tool number of the robot in remote mode, range: int[0,7]
Note: The tool number in automatic mode is the same as the tool number in remote
mode.
Example: if __name__ == ”__main__”:
ip = ”192.168.1.202”
conSuc, sock = connectETController ( ip )
# print (conSuc)
if conSuc:
ret , result , id = sendCMD(sock, ”getAutoRunToolNumber”)
if ret :
print (” result = ” , result )
else :
print (”err_msg = ” , result [”message”])
2.2.2.37 Set the current tool number of the robot in remote mode
{" jsonrpc ":"2.0" ," method ":" setAutoRunToolNumber "," params ":{" tool_num ":
tool_num },"id":id}
Function: Set the current tool number of the robot in remote mode
Parameter: tool_num: tool number, range: int[0,7]
Return: True for success, False for failure
Example: if __name__ == ”__main__”:
ip = ”192.168.1.202”
conSuc, sock = connectETController ( ip )
if conSuc:
ret , result , id=sendCMD(sock,”setAutoRunToolNumber”,{”tool_num”: 0})
if ret :
print (” result = ” , result )
else :
print (”err_msg = ” , result [”message”])
DN:EC
29
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" get_base_flange_pose ", " params ":{" unit_type ":
unit_type },"id": id}
Function: Get the center pose of the flange in the Base coordinate system
Parameter: unit_type: int[0,1], return the unit type of the pose rx, ry, rz, 0: return angle, 1: return
radian, optional parameter, if not written, the default value is radians.
Return: The center pose of the flange in the Base coordinate system, Double[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.202”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the center pose of the flange in the Base coordinate system
ret , result , id = sendCMD(sock,”get_base_flange_pose”,{”unit_type”: 0})
print (” result =”, result )
else :
print (”Connection failed ”)
disconnectETController (sock)
2.2.2.39 Get the center pose of the flange in the user coordinate system
{" jsonrpc ":"2.0" ," method ":" get_user_flange_pose "," params ":{" unit_type ":
unit_type },"id": id}
DN:EC
30
2.2 Interface service
Function: Get the center pose of the flange in the user coordinate system
Parameter: unit_type: int[0,1], return the unit type of the pose rx, ry, rz, 0: return angle, 1: return
radian, optional parameter, if not written, the default value is radians.
Return: Center pose of flange in user coordinate system, Double[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.202”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the center pose of the flange in the user coordinate system
ret , result , id = sendCMD(sock,”get_user_flange_pose”,{”unit_type”: 0})
print (” result =”, result )
else :
print (”Connection failed ”)
disconnectETController (sock)
DN:EC
31
2.2 Interface service
DN:EC
32
2.2 Interface service
if conSuc:
# Get robot safety momentum
suc , result , id =sendCMD(sock,”getRobotSafetyMomentum”)
print ( result )
Function: Get the "external" force and torque of the current TCP coordinate system
Parameter: ref_tcp: reference coordinate system, int[0,1],optional parameter, 0: base coordinate
system, 1: tcp coordinate system, If not written, the default is tcp coordinate system.
Return: The "external" force and torque of the current tcp double force[6], the first three are
external force and the last three are torque
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”172.16.11.248”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the force and torque of the current TCP in the base coordinate system
suc , result , id = sendCMD(sock, ”get_tcp_force”,{”get_tcp_force”: 0})
DN:EC
33
2.2 Interface service
{" jsonrpc ": "2.0" , " method ": " get_ j o i n t _ t o r q u e s ", "id": id}
Note: The joint torque is the motor torque minus the "torque required to drive itself",
reflecting the "external" torque.
DN:EC
34
2.2 Interface service
print ( result )
{" jsonrpc ":"2.0" ," method ":" setFlangeButton "," params ":{" button_num ":
button_num ," state ": state },"id":id}
{" jsonrpc ":"2.0" ," method ":" checkFlangeButton "," params ":{" button_num ":
button_num },"id ":id}
{" jsonrpc ": "2.0" , " method ": " getCollisionSensitivity ", "id": id}
DN:EC
37
2.2 Interface service
2.2.2.55 Get the pose of the current tcp in the current user coordinate system
{" jsonrpc ":"2.0" ," method ":" getTcpPoseInUser "," params ":{" unit_type ":
unit_type },"id": id}
Function: Get the pose of the current tcp in the current user coordinate system
Parameter: unit_type: int[0,1], optional parameter, returns the unit type of pose rx, ry, rz,0: angle,
1: radians, if not written, the default value is radians.
Return: The current pose of tcp in the user coordinate system
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.202”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the pose information of the current tcp in the current user coordinate system
suc , result , id = sendCMD(sock, ”getTcpPoseInUser”,{”unit_type”: 0})
print ( result )
else :
print (”Connection failed ”)
disconnectETController (sock)
DN:EC
38
2.2 Interface service
DN:EC
39
2.2 Interface service
{" jsonrpc ": "2.0" , " method ": " get_tcp_speed ", "id": id}
DN:EC
40
2.2 Interface service
DN:EC
41
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" get_tool_payload "," params ":{" tool_num ":
tool_num },"id ": id}
DN:EC
42
2.2 Interface service
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”172.16.11.248”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the joint position information of the robot input
suc , result , id = sendCMD(sock, ”get_motor_pos”)
print ( result )
else :
print (”Connection failed ”)
disconnectETController (sock)
DN:EC
43
2.2 Interface service
Note: The command is only supported in the remote mode and it can clear the queue only
when the robot stops or gives an alarm (under the static condition).
Function: Get the actual tcp pose data in the base coordinate system or the specified user
coordinate system
Parameter: tool_num: tool coordinate number, optional parameter, int[0,7], when it is not entered,
the current tool is used. Otherwise, the specified tool is used
user_num: user coordinate number, optional parameter, int[0,7], when it is not entered,
the user gets the pose in the base coordinate system. Otherwise, the user gets the pose
in the user-specific coordinate. 44
DN:EC
2.2 Interface service
Function: Get the target interpolation tcp pose data in the base coordinate system or the
specified user coordinate system
Parameter: tool_num: tool coordinate number, optional parameter, int[0,7], when it is not entered,
the current tool is used. Otherwise, the specified tool is used
user_num: user coordinate number, optional parameter, int[0,7], when it is not
entered, the user gets the pose in the base coordinate system. Otherwise, the user gets
the pose in the specified user coordinate
Return: Robot pose information double pose [6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”172.16.11.248”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the target interpolation tcp pose of the tool 1 in the user 1 coordinate system
suc , result , id=sendCMD(sock,”get_target_tcp”,{”tool_num”:1,” user_num ” :1})
print ( result )
else :
print (”Connection failed”)
disconnectETController (sock)
Function: Get the linear interpolation pose data between two given poses
DN:EC
46
2.2 Interface service
Parameter: data1: pose data, standard parameter, double pose [6], the first three stand for
position, unit of x, y, z is mm, range is [-∞, +∞], the last three stand for pose, unit of
Rx, Ry, Rz is radian, range is [-π,π]
data2: pose data, standard parameter, double pose[6], the first three stand for position,
unit of x, y, z is mm, range is [-∞, +∞], the last three stand for pose, unit of Rx, Ry,
Rz is radian, range is [-π,π]
ratio: floating-point data, standard parameter, it stands for the proportional value. The
range is [0,1]. When the value is equal to 0, the robot will return to the first pose.
When the value is equal to 1, the robot will return to the second pose
Return: Robot pose information double pose [6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”172.16.11.248”
conSuc,sock=connectETController( robot_ip )
point1=[371.533, 101.636, 3.038, 0, -0.174, 2.861]
point2=[346.312, -256.945, -91.131, -0.014, 0.521, 1.903]
if (conSuc):
# Get the linear interpolation pose data between two given poses
suc , result , id=sendCMD(sock,”get_interp_pose”,{”data1”:point1,”data2”:point2,”ratio”:0.5})
print ( result )
else:
print (”Connection failed”)
disconnectETController (sock)
{" jsonrpc ":"2.0" ," method ":" get_joint_t e m p ","id ": id}
DN:EC
47
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" i n v e r s e K i n e m a t i c A l l "," params ":{" t a r g e t P o s e ":
targetPose},"id ": id}
{" jsonrpc ":"2.0" ," method ":" s e t _ s y s t e m _ t i m e "," params ":{" t i m e ": [year, month,
day, hour, minute, second]},"id ": id}
DN:EC
48
2.2 Interface service
DN:EC
49
2.2 Interface service
DN:EC
50
2.2 Interface service
DN:EC
51
2.2 Interface service
DN:EC
52
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" get_welding_p a r a m e t e r s "," params ":{" t e c h N u m ":
t e c h N u m },"id":id}
DN:EC
53
2.2 Interface service
DN:EC
54
2.2 Interface service
DN:EC
55
2.2 Interface service
DN:EC
56
2.2 Interface service
DN:EC
57
2.2 Interface service
DN:EC
58
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" set_robot_p o w e r _ s t a t u s "," params ":{" s t a t u s ":
s t a t u s },"id ":id}
DN:EC
59
2.2 Interface service
Note: This command is only available for MINI controller and is applicable to V3.14.2 and above.
Note: This command is only available for MINI controller and is applicable to V3.14.2 and above.
DN:EC
60
2.2 Interface service
Note: The parameters mode and free_axes are valid only when the drag function is enabled.
If they are not entered, the previous configuration will be used by default and the
settings will not be saved in case of disconnection from power.
This command is applicable to V3.14.2 and above.
DN:EC
61
2.2 Interface service
DN:EC
62
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" moveByJ o i n t "," params ":{" t a r g e t P o s ": t a r g e t P o s ,"
s p e e d ": s p e e d ," a c c ": a c c ," d e c ": d e c ," c o n d _ t y p e ":c o n d _ t y p e ,"cond_num":
c o n d _ n u m ," cond_v a l u e ": cond_v a l u e ," cond_j u d g m e n t ": cond_j u d g m e n t },
"id": id}
DN:EC
63
2.2 Interface service
Note: When cond_type is equal to 0 or 1, the con_num and con_value are valid. When cond_type
is equal to 2, the con_judgment is valid. For the user-defined conditions, please refer to the
syntax format of UNTIL in the JBI command.
{" jsonrpc ":"2.0" ," method ":" moveByL i n e "," params ":{" t a r g e t P o s ": t a r g e t P o s ,"
s p e e d _ t y p e ": s p e e d _ t y p e ," s p e e d ": s p e e d ," a c c ": a c c ," d e c ":d e c ,"cond_type"
: c o n d _ t y p e ," cond_n u m ": cond_n u m ," cond_v a l u e ": cond_v a l u e },
"cond_judgment":cond_judgment},"id": id}
Note: When there is no speed_type parameter, speed means absolute linear speed. When
cond_type is equal to 0 or 1, the con_num and con_value are valid. When cond_type is
equal to 2, the con_judgment is valid. For the user-defined conditions, please refer to
the syntax format of UNTIL in the JBI command.
DN:EC
65
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" moveByArc "," params ":{" midPos ": midPos ,"
targetPos ": targetPos ," speed_type ": speed_type ," speed ": speed ," acc ":acc ,"
dec ":dec ," cond_type ": cond_type ," cond_num ": cond_num ," cond_value ":
cond_value , " c o n d _ j u d g m e n t " : c o n d _ j u d g m e n t },"id":id}
DN:EC
66
2.2 Interface service
90.0000,0.0013]
P001 = [−16.2806,−82.4996,81.9848,−89.4851,
90.0000, −16.2858]
if (conSuc):
# Get the servo status of the robotic arm
suc , result , id=sendCMD(sock,”getServoStatus”)
if ( result == 0) :
# Set the servo status of the robotic arm to ON
suc , result , id=sendCMD(sock,”set_servo_status”,{”status” :1})
time . sleep (1)
# Circular movement
suc , result , id=sendCMD(sock,”moveByArc”,{”midPos”:P000,”targetPos”:P001,”speed_type”
:0,”speed”:20,”cond_type”:0,”cond_num”:7 ,”cond_value”:1})
Note: When there is no speed_type parameter, speed means absolute linear speed. When
cond_type is equal to 0 or 1, the con_num and con_value are valid. When cond_type is
equal to 2, the con_judgment is valid. For the user-defined conditions, please refer to the
syntax format of UNTIL in the JBI command.
{" jsonrpc ":"2.0" ," method ":" moveByRotate "," params ":{" targetPos ": targetPos
," speed_type ": speed_type ," speed ": speed ," acc ":acc ," dec ":dec ," cond_type
": cond_type ," cond_num ":cond_num ," cond_value ": cond_value },"id": id}
DN:EC
67
2.2 Interface service
acc: acceleration percentage, range: int [1,100], optional parameter, the default value
is 80 if not written.
dec: deceleration percentage, range: int [1,100], optional parameter, the default value
is acc if not written.
Return: True for success, false for failure
Example: if __name__ ==
”__main__”:
# Robot IP
address
robot_ip =”192.168.1.200
”
conSuc,sock=connectETController( robot_ip
)P000 = [0.0065,−103.9938,102.2076,−88.2138,
90.0000,0.0013]
if (conSuc):
# Get the servo status of the robotic arm
suc , result , id=sendCMD(sock,”getServoStatus”)
if ( result == 0) :
# Set the servo status of the robotic arm to ON
suc , result , id=sendCMD(sock,”set_servo_status”,{”status” :1})
time . sleep (1)
# Rotational movement
suc , result , id=sendCMD(sock,”moveByRotate”,{”targetPos”:P000,”speed_type”:0,”speed”:20,
”cond_type” :0, ”cond_num”:7,”cond_value”:1 })
Note: When there is no speed_type parameter, speed represents the absolute rotational angular
speed.
This command is deprecated.
CAUTION
The above commands are only supported in remote mode.
Before executing the above commands, please make sure that the robot is in a
stopped state. If the robot is running, send the stop command first and wait for the
robot to stop.
DN:EC
68
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" a d d P a t h P o i n t "," params ":{" w a y P o i n t ": w a y p o i n t ,"
m o v e T y p e " : m o v e T y p e ," speed_type ": speed_type ," speed ": speed ," acc ":acc ,"
dec ":dec ,"smooth":smooth," cond_type ": cond_type," cond_num ": cond_num ,"
cond_value":cond_value , " c o n d _ j u d g m e n t " : c o n d _ j u d g m e n t , "
trigger_cond_type":t r i g g e r _ c o n d _ t y p e , " t r i g g e r _ c o n d _ v a l u e " :
trigger_cond_value,"trigger_io_type":trigger_io_type,"trigger_io_addr":
trigger_io_addr,"trigger_io_status":trigger_io_status},"id":id} or "jsonrpc":
"2.0","method":"addPathPoint","params":{"wayPoint":wayPoint,"moveType":
moveType,"speedType":speedType,"speed":speed,"acc":acc,"dec":dec,"
circular_radius":circular_radius,"cond_type":cond_type,"cond_num":cond_num,"
cond_value":cond_value,"cond_judgment":cond_judgment,"trigger_cond_type":
trigger_cond_type,"trigger_cond_value":trigger_cond_value,"trigger_io_type":
trigger_io_type,"trigger_io_addr":trigger_io_addr,"trigger_io_status":
trigger_io_status},"id":id}
Note: When cond_type is equal to 0 or 1, the con_num and con_value are valid. When
cond_type is equal to 2, the con_judgment is valid. For the user-defined conditions, please
refer to the syntax format of UNTIL in the JBI command.
When the trigger parameters are not written, the trigger function is disabled by default.
When enabling the trigger function, the parameter UNTIL will not be used.
DN:EC
70
2.2 Interface service
CAUTION
This command is only supported in remote mode.
If the motion type is joint motion, the speed_type parameter is invalid and not
recommended.
The parameter circular_radius and the parameter smooth can be used either. It is
recommended to use the parameter circular_radius.
DN:EC
71
2.2 Interface service
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
C000 = [0.0065,−103.9938,102.2076,−88.2138,
90.0000,0.0013]
C001 = [−16.2806,−82.4996,81.9848,−89.4851,
90.0000, −16.2858]
C002 = [3.7679, −71.7544, 68.7276, −86.9732,
90.0000, 3.7627]
if (conSuc):
# Clear waypoint information 2.0
suc , result , id = sendCMD(sock, ”clearPathPoint”)
if ( result == True) :
# Add waypoint information 2.0
suc , result , id = sendCMD(sock, ”addPathPoint”, {”wayPoint”: C000,”moveType”: 0, ”
speed”: 50, ”circular_radius”:20})
suc , result , id = sendCMD(sock, ”addPathPoint”, {”wayPoint”: C001,”moveType”:0, ”
speed”: 50, ”circular_radius”:20})
suc , result , id = sendCMD(sock, ”addPathPoint”, {”wayPoint”: C002,”moveType”: 0, ”
speed”: 50, ”circular_radius” :0})
# Trajectory movement 2.0
suc , result , id = sendCMD(sock, ”moveByPath”)
while(True) :
# Get the current running point number of the trajectory
suc , result , id = sendCMD(sock, ”getPathPointIndex”)
print ( result )
# Get robot status
suc , result , id = sendCMD(sock, ”getRobotState”)
if ( result == 0) :
break
{" jsonrpc ":"2.0" ," method ":" jog "," params ":{" index ": index ," speed ": speed },"
id": id}
Note: After stopping sending the jog command, the robot will not stop immediately. Instead,
the robot needs to be stopped immediately by the ”stop robot operation” command
below.
This command is only supported in remote mode.
If the next jog motion instruction is not received for more than 1 second, stop receiving
the jog instruction, and the robot jog motion will stop.
DN:EC
73
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" checkJbiExist "," params ":{" filename ": filename
},"id ": id}
{" jsonrpc ":"2.0" ," method ":" runJbi "," params ":{" filename ": filename },"id ": id
}
if (conSuc):
# Check if the jbi file exists
suc , result , id=sendCMD(sock,”checkJbiExist”,{”filename”: jbi_filename })
if (suc and result ==1):
# Run jbi file
suc , result , id=sendCMD(sock,”runJbi”,{”filename”: jbi_filename })
{" jsonrpc ":"2.0" ," method ":" setSpeed "," params ":{" value ": value },"id":id}
DN:EC
76
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" stopj "," params ":{" acc ": acc },"id":id}
{" jsonrpc ":"2.0" ," method ":" moveBySpeedl "," params ":{"v":v," acc ":acc ," arot
":arot ,"t":t},"id ": id}
DN:EC
78
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" stopl "," params ":{" acc ":acc ," arot ": arot },"id ":
id}
DN:EC
79
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" moveByLineCoord "," params ":{" targetUserPose ":
targetUserPose ," speed_type ": speed_type ," speed ": speed ," acc ":acc ," dec ":
dec ," user_coord ": user_coord ," cond_type ": cond_type ," cond_num :" :
cond_num :," cond_value ": cond_value ," unit_type ": unit_type },"id":id}
DN:EC
80
2.2 Interface service
Note: This command is applicable to v2.16.2 and above. This command is only supported
in remote mode. When there is no speed_type parameter, speed means absolute linear
speed. When cond_type is equal to 0 or 1, the con_num and con_value are valid.
When cond_type is equal to 2, the con_judgment is valid. For the user-defined
conditions, please refer to the syntax format of UNTIL in the JBI command.
DN:EC
81
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" inverseKinematic "," params ":{" targetPose ":
targetPose ," referencePos ": referencePos },"id":id}
DN:EC
82
2.2 Interface service
Function: Inverse solution function, inverse solution with reference point position, according to
the pose information to get the corresponding manipulator joint angle information
Parameter: targetPose: target pose information
referencePos: inverse solution reference point joint angle information double pos[6],
the range is [-360,360], optional parameter
unit_type: the unit type of the rx, ry, rz of the input pose, int [0,1], 0: angle, 1: radian,
optional parameter, if not written, the default value is radians.
Return: Joint coordinates double pos[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
# Reference point
P000 = [0, −90, 90, −90, 90, 0]
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the current pose information of the robot
suc , result , id = sendCMD(sock, ”get_tcp_pose”)
# Inverse solution function 2.0, with reference point position
suc , result , id=sendCMD(sock,”inverseKinematic”,{”targetPose”: result , ” referencePos ”:
P000})
{" jsonrpc ":"2.0" ," method ":" positiveKinematic "," params ":{" targetPos ":
targetPos ," unit_type ": unit_type },"id":id}
Function: Positive solution function, get the corresponding pose information according to the
joint angle information of the manipulator
Parameter: targetpos: target joint angle information double pos[6], the range is [-360,360]
unit_type: return the unit type of the pose rx, ry, rz, int [0,1], 0: return angle, 1: return
radian, optional parameter, if not written, the default value is radians.
Return: Response pose information: double pose[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the current position information of the robot
suc , result , id = sendCMD(sock, ”get_joint_pos”)
# Positive solution function
suc , result , id=sendCMD(sock,”positiveKinematic”,{”targetPos”: result , ” unit_type ” :1})
DN:EC
83
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" convertPoseFromCartToUser "," params ":{"
targetPose ": targetPose ," userNo ": userNo ," unit_type ": unit_type },"id": id}
Function: Base coordinate to user coordinate pose conversion function, in the current user co-
ordinate system, the pose information in the corresponding user coordinate system is
obtained according to the pose information of the base coordinate
Parameter: targetPose: pose information in the base coordinate system, double pose[6], rx, ry, rz
range: radian is [-π,π], angle is [-180,180]
userNo:User coordinate number, range: int[0,7]
unit_type: input pose and return pose of rx, ry, rz unit type, int [0,1], 0: angle, 1:
radian, optional parameter, if not written, the default value is radians.
Return: Pose information under the user standard system: double user_pose[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the current pose information of the robot
suc , result , id = sendCMD(sock, ”get_tcp_pose”)
# Base coordinate to user coordinate pose conversion
suc , result , id=sendCMD(sock,”convertPoseFromCartToUser”,{”targetPose”:result , ”userN”:0,
” unit_type ” :1})
{" jsonrpc ":"2.0" ," method ":" convertPoseFromUserToCart "," params ":{"
targetPose ": targetPose ," userNo ": userNo ," unit_type ": unit_type },"id": id}
DN:EC
84
2.2 Interface service
Function: User coordinate to base coordinate pose conversion, in the current user coordinate
system, the pose information in the corresponding base coordinate system is obtained
according to the pose information of the user coordinate
Parameter: targetPose: the pose information in the user coordinate system, double pose[6], the
range of rx, ry, rz: radian is [-π,π], angle is [-180,180]
userNo: User coordinate number, range: int[0,7]
unit_type: input pose and return pose of rx, ry, rz unit type, int [0,1], 0: angle, 1:
radian, optional parameter, if not written, the default value is radians.
Return: Pose information in the base coordinate system: double base_pose[6]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.200”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
# Get the current pose information of the robot
suc , result , id = sendCMD(sock, ”get_tcp_pose”, {”coordinate_num”:1, ”tool_num”:7})
# User coordinate to base coordinate pose conversion
suc , result , id=sendCMD(sock,”convertPoseFromUserToCart”,{”targetPose”:result , ”userNo”
:0})
{" jsonrpc ":"2.0" ," method ":" poseMul "," params ":{" pose1 ": pose1 ," pose2 ": pose2
," unit_type ": unit_type },"id":id}
DN:EC
85
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" poseInv "," params ":{" pose ":pose ," unit_type ":
unit_type },"id":id}
DN:EC
86
2.2 Interface service
2.2.5 IO Service(IOService)
{" jsonrpc ":"2.0" ," method ":" getInput "," params ":{" addr ": addr },"id ":id}
{" jsonrpc ":"2.0" ," method ":" getOutput "," params ":{" addr ": addr },"id":id}
DN:EC
87
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setOutput "," params ":{" addr ":addr ," status ":
status },"id":id}
{" jsonrpc ":"2.0" ," method ":" getVirtualInput "," params ":{" addr ": addr },"id":
id}
DN:EC
88
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getVirtualOutput "," params ":{" addr ": addr },"id ":
id}
{" jsonrpc ":"2.0" ," method ":" setVirtualOutput "," params ":{" addr ":addr ,"
status ": status },"id":id}
DN:EC
89
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getAnalogInput "," params ":{" addr ": addr },"id":id
}
DN:EC
90
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" get_analog_output "," params ":{" addr ": addr },"id
":id}
DN:EC
91
2.2 Interface service
DN:EC
92
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setSysVarB "," params ":{" addr ":addr ," value ":
value },"id":id}
{" jsonrpc ":"2.0" ," method ":" getSysVarI "," params ":{" addr ": addr },"id":id}
DN:EC
93
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setSysVarI "," params ":{" addr ":addr ," value ":
value },"id":id}
{" jsonrpc ":"2.0" ," method ":" getSysVarD "," params ":{" addr ": addr },"id":id}
DN:EC
94
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setSysVarD "," params ":{" addr ":addr ," value ":
value },"id":id}
{" jsonrpc ":"2.0" ," method ":" getSysVarPState "," params ":{" addr ": addr },"id":
id}
DN:EC
95
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" getSysVarP "," params ":{" addr ": addr },"id":id}
{" jsonrpc ":"2.0" ," method ":" setSysVarP "," params ":{" addr :": addr ," pos :": pos
},"id":id}
DN:EC
96
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" setSysVarV "," params ":{" addr ":addr ," pose :": pose
},"id":id}
{" jsonrpc ":"2.0" ," method ":" getSysVarV "," params ":{" addr ": addr },"id":id}
{" jsonrpc ":"2.0" ," method ":" setSysVarV "," params ":{" addr ": addr ," pose ":
pose },"id ": id}
{" jsonrpc ":"2.0" ," method ":" transparent_transmission_init "," params ":{"
lookahead ": lookahead ,"t":t ," smoothness ": smoothness ," response_enable ":
response_enable },"id ": id}
2.2.7.2 Set the current transparent transmission servo target joint point
{" jsonrpc ":"2.0" ," method ":" tt_set_current_servo_joint "," params ":{"
targetPos ": targetPos },"id": id}
Function: Set the current transparent transmission servo target joint point
Parameter: targetpos: target joint point double pos[6], the range is [-360,360]
Return: True for success, false for failure
DN:EC
99
2.2 Interface service
Note: This command is only supported in remote mode. This command is deprecated.
{" jsonrpc ":"2.0" ," method ":" tt_put_servo_joint_to_buf "," params ":{"
targetPos ": targetPos },"id ": id} or {" jsonrpc ":"2.0" ," method ":"
tt_put_servo_joint_to_buf "," params ":{" targetPose ": targetPose },"id":
id}
DN:EC
100
2.2 Interface service
Function: Add transparent transmission of servo target joint point information to the cache
Parameter: targetpos: target joint point double pos[6], the range is [-360,360] or targetPose: target
pose point is double pos[6]
Return: True for success, false for failure
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.202”
conSuc,sock=connectETController(ip )
i =0
if (conSuc):
# Get whether the current robot is in a transparent transmission state
suc , result , id=sendCMD(sock, ”get_transparent_transmission_state”)
print (suc , result , id )
if ( result == 1) :
# Clear the transparent transmission cache
suc , result , id = sendCMD(sock,”tt_clear_servo_joint_buf”)
time . sleep (0.5)
# open a file
file_name =’D :\\ tttest8 . txt ’
fo = open(file_name , ”r”)
while 1:
# Read each line of the file in turn ( point information )
line = fo . readline ()
if not line : break
# Remove the blanks at the beginning and end of each line
line_list = line . strip ()
line_list = list (map( float , line_list . split ( ’ , ’ ) ) )
if ( i == 0) :
# Joint movement to the starting point
suc , result , id=sendCMD(sock,”moveByJoint”,{”targetPos”: line_list , ”speed”:30})
wait_stop () # Wait for the robot to stop
# Initialize the transparent transmission service
suc , result , id=sendCMD(sock,”transparent_transmission_init”,{”lookahead”:400,
”t” :10, ”smoothness” :0.1, ”response_enable” :1})
print (suc , result , id )
# Add transparent transmission of servo target joint point information to the
cache
suc , result , id = sendCMD(sock, ”tt_put_servo_joint_to_buf”,{”targetPos”:
line_list })
time . sleep (0.01)
i = i +1
DN:EC
101
2.2 Interface service
2.2.7.6 Example 1
1 import socket
2 import json
3 import time
4 import random
5
6 def connectETController (ip ,port =8055) :
7 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
8 try:
9 sock. connect ((ip ,port))
10 return (True ,sock)
11 except Exception as e:
12 sock.close ()
13 return (False ,None)
14
15 def disconnectETController (sock):
16 if(sock):
17 sock.close ()
18 sock=None
19 else:
DN:EC
102
2.2 Interface service
20 sock=None
21
22 def sendCMD (sock ,cmd , params =None ,id =1):
23 if(not params ):
24 params =[]
25 else:
26 params =json.dumps( params )
27 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\"
id \":{2}}} ". format (cmd ,params ,id)+"\n"
28 try:
29 sock. sendall (bytes(sendStr ,"utf -8"))
30 ret =sock.recv (1024)
31 jdata=json.loads(str(ret ,"utf -8"))
32 if(" result " in jdata.keys ()):
33 return (True ,json.loads(jdata[" result "]) ,jdata["id"])
34 elif("error" in jdata.keys ()):
35 return (False ,jdata[" error "], jdata["id"])
36 else:
37 return (False ,None ,None)
38 except Exception as e:
39 return (False ,None ,None)
40
41 def wait_stop ():
42 while True:
43 time.sleep (0.01)
44 ret1 , result1 , id1 = sendCMD (sock , " getRobotState ")
45 if (ret1):
46 if result1 == 0 or result1 == 4:
47 break
48 else:
49 print(" getRobotState failed ")
50 break
51
52 if __name__ == " __main__ ":
53 # Robot IP address
54 robot_ip =" 192.168.1.202 "
55 conSuc ,sock= connectETController ( robot_ip )
56 print( conSuc )
57 if( conSuc ):
58 # Get robot status
59 suc , result , id = sendCMD (sock , " getRobotState ")
60 if( result == 4):
61 # Clear alarm
DN:EC
103
2.2 Interface service
DN:EC
104
2.2 Interface service
t": 10, " smoothness ": 0.1, " response_enable ": 1})
100 print(suc , result , id)
101 # Add transparent transmission of servo target joint point
information to the cache
102 suc , result , id = sendCMD (sock , " tt_put_servo_joint_to_buf "
,{" targetPos ": line_list })
103 time.sleep (0.01)
104 i = i + 1
105 # Close file
106 fo.close ()
107 # Clear the transparent transmission cache
108 suc , result , id = sendCMD (sock , " tt_clear_servo_joint_buf ")
109 print(" clear_ret = ", suc)
110 else:
111 print(" Connection failed ")
112 disconnectETController (sock)
2.2.7.7 Example 2
1 import socket
2 import json
3 import time
4
5 def connectETController (ip ,port =8055) :
6 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
7 try:
8 sock. connect ((ip ,port))
9 return (True ,sock)
10 except Exception as e:
11 sock.close ()
12 return (False ,None)
13
14 def disconnectETController (sock):
15 if(sock):
16 sock.close ()
17 sock=None
18 else:
19 sock=None
20
21 def sendCMD (sock ,cmd , params =None ,id =1):
22 if(not params ):
23 params =[]
DN:EC
105
2.2 Interface service
24 else:
25 params =json.dumps( params )
26 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\"
id \":{2}}} ". format (cmd ,params ,id)+"\n"
27 try:
28 sock. sendall (bytes(sendStr ,"utf -8"))
29 # print (sock.recv)
30 ret =sock.recv (1024)
31 jdata=json.loads(str(ret ,"utf -8"))
32 if(" result " in jdata.keys ()):
33 return (True ,json.loads(jdata[" result "]) ,jdata["id"])
34 elif("error" in jdata.keys ()):
35 return (False ,jdata[" error "], jdata["id"])
36 else:
37 return (False ,None ,None)
38 except Exception as e:
39 return (False ,None ,None)
40
41 def send_Point (sock ,cmd , params =None ,id =1):
42 if(not params ):
43 params =[]
44 else:
45 params =json.dumps( params )
46 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\"
id \":{2}}} ". format (cmd ,params ,id)+"\n"
47 sock. sendall (bytes(sendStr ,"utf -8"))
48
49 def wait_stop ():
50 while True:
51 time.sleep (0.01)
52 ret1 , result1 , id1 = sendCMD (sock , " getRobotState ") #
getRobotstate
53 if (ret1):
54 if result1 == 0 or result1 == 4:
55 break
56 else:
57 print(" getRobotState failed ")
58 break
59
60
61 if __name__ == " __main__ ":
62 # Robot IP address
63 robot_ip =" 192.168.1.202 "
DN:EC
106
2.2 Interface service
DN:EC
107
2.2 Interface service
104
105 if (i == 0):
106 # Joint movement to the starting point
107 suc , result , id = sendCMD (sock , " moveByJoint ", {"
targetPos ": line_list , "speed": 30})
108 print( result )
109 wait_stop () # Wait for the robot to stop
110 print (1)
111 # Initialize the transparent transmission service
112 suc , result , id = sendCMD (sock , "
transparent_transmission_init ", {" lookahead ": 400 , "
t": 10, " smoothness ": 0.1, " response_enable ":0})
113 print( result )
114 # Add transparent transmission of servo target joint point
information to the cache
115 send_Point (sock , " tt_put_servo_joint_to_buf " ,{" targetPos ":
line_list })
116 print( result )
117 time.sleep (0.01)
118 i = i + 1
119 # Close file
120 fo.close ()
121 # Clear the transparent transmission cache
122 suc , result , id = sendCMD (sock , " tt_clear_servo_joint_buf ")
123 print(" clear_ret = ", suc)
124 else:
125 print(" Connection failed ")
126 disconnectETController (sock)
DN:EC
108
2.2 Interface service
2.2.9 TrajectoryService(TrajectoryService)
{" jsonrpc ":"2.0" ," method ":" start_push_pos "," params ":{" path_lenth ":
path_lenth ," pos_type ": pos_type ," ref_joint_pos ": ref_joint_pos ,"
ref_frame ": ref_frame ," ret_flag ": ret_flag },"id": id}
DN:EC
109
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" push_pos "," params ":{" timestamp ": timestamp ," pos
": pos },"id":id}
DN:EC
110
2.2 Interface service
DN:EC
111
2.2 Interface service
Note: Stop_push_pos and push_pos are corresponding relations. Only when all the points
sent by the corresponding push_pos are correct, will it return True, otherwise, it will
return False.
DN:EC
112
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" start_trajectory "," params ":{" speed_percent ":
speed_percent },"id":id}
DN:EC
113
2.2 Interface service
DN:EC
114
2.2 Interface service
DN:EC
115
2.2 Interface service
2.2.9.10 Example 1
1 import socket
2 import json
3 import time
4
5 def connectETController (ip ,port =8055) :
6 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
7 try:
8 sock. connect ((ip ,port))
9 return (True ,sock)
10 except Exception as e:
11 sock.close ()
12 return (False ,None)
13
14 def disconnectETController (sock):
15 if(sock):
16 sock.close ()
17 sock=None
18 else:
19 sock=None
20
21 def sendCMD (sock ,cmd , params =None ,id =1):
22 if(not params ):
23 params =[]
24 else:
DN:EC
116
2.2 Interface service
DN:EC
117
2.2 Interface service
2.2.9.11 Example 2
DN:EC
118
2.2 Interface service
1 import socket
2 import json
3 import time
4
5 def connectETController (ip ,port =8055) :
6 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
7 try:
8 sock. connect ((ip ,port))
9 return (True ,sock)
10 except Exception as e:
11 sock.close ()
12 return (False ,None)
13
14 def disconnectETController (sock):
15 if(sock):
16 sock.close ()
17 sock=None
18 else:
19 sock=None
20
21 def sendCMD (sock ,cmd , params =None ,id =1):
22 if(not params ):
23 params =[]
24 else:
25 params =json.dumps( params )
26 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\"
id \":{2} }}". format (cmd ,params ,id)+"\n"
27 try:
28 sock. sendall (bytes(sendStr ,"utf -8"))
29 # print (sock.recv)
30 ret =sock.recv (1024)
31 jdata=json.loads(str(ret ,"utf -8"))
32 if(" result " in jdata.keys ()):
33 return (True ,json.loads(jdata[" result "]) ,jdata["id"])
34 elif("error" in jdata.keys ()):
35 return (False ,jdata[" error "], jdata["id"])
36 else:
37 return (False ,None ,None)
38 except Exception as e:
39 return (False ,None ,None)
40
41 def send_Point (sock ,cmd , params =None ,id =1):
42 if(not params ):
DN:EC
119
2.2 Interface service
43 params =[]
44 else:
45 params =json.dumps( params )
46 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\"
id \":{2} }}". format (cmd ,params ,id)+"\n"
47 sock. sendall (bytes(sendStr ,"utf -8"))
48
49 def wait_stop ():
50 while True:
51 time.sleep (0.01)
52 ret1 , result1 , id1 = sendCMD (sock , " getRobotState ")
53 if (ret1):
54 if result1 == 0 or result1 == 4:
55 break
56 else:
57 print(" getRobotState failed ")
58 break
59
60 if __name__ == " __main__ ":
61 ip = " 192.168.1.200 "
62 conSuc , sock = connectETController (ip)
63 start_pos = [0, -90, 0, -90, 90, 0]
64 ref_pos = [0, 0, 0, 0, 0, 0]
65 res = 0
66 if conSuc :
67 suc , result , id = sendCMD (sock , " getRobotState ")
68 if ( result == 4):
69 # Clear alarm
70 suc , result , id = sendCMD (sock , " clearAlarm ")
71 time.sleep (0.5)
72 # Get synchronization status
73 suc , result , id = sendCMD (sock ," getMotorStatus ")
74 if result != True:
75 # Synchronize servo encoder data
76 suc , result , id = sendCMD (sock ," syncMotorStatus ")
77 time.sleep (0.5)
78 time.sleep (0.5)
79 # Get the servo status of the robotic arm
80 suc , result , id = sendCMD (sock , " getServoStatus ")
81 if result == 0:
82 # Set the servo status of the robotic arm to ON
83 ret , result , id = sendCMD (sock , " set_servo_status ", {"
status ": 1})
DN:EC
120
2.2 Interface service
84 suc , result , id = sendCMD (sock , " moveByJoint ", {" targetPos ":
start_pos , "speed": 50})
85 wait_stop ()
86 suc , result , id = sendCMD (sock , " start_push_pos ", {" path_lenth "
: 10, " pos_type ": 0, " ref_joint_pos ": start_pos , " ref_frame "
: ref_pos , " ret_flag ": 0})
87 print( result )
88 time.sleep (0.2)
89 for i in range (0, 10):
90 send_Point (sock , " push_pos ", {" timestamp ": res , "pos":
start_pos })
91 start_pos [0] += 0.02
92 res = res + 0.002
93 time.sleep (1)
94 suc , result , id = sendCMD (sock , " stop_push_pos ")
95 print( result )
96 suc , result , id = sendCMD (sock , " check_trajectory ")
97 print( result )
98 suc , result , id = sendCMD (sock , " start_trajectory ", {"
speed_percent ": 50})
99 print( result )
100 time.sleep (5)
101 suc , result , id = sendCMD (sock , " flush_trajectory ")
102 print( result )
103 else:
104 print(" Connection failed ")
105 disconnectETController (sock)
2.2.10 ProfinetService(ProfinetService)
{" jsonrpc ":"2.0" ," method ":" get_profinet_int_input_registers "," params ":{"
addr ":addr ," length ": length },"id": id}
DN:EC
121
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" get_profinet_int_output_registers "," params ":{"
addr ":addr ," length ": length },"id": id}
DN:EC
122
2.2 Interface service
2.2.10.3 Get the value of the profinet float type input register
Function: Get the value of the profinet float type input register
Parameter: addr: register start address, range int[0,31]
length: number of registers, range int[1,32]
Note: the sum of addr and length should be less than or equal to 32
Return: list of register values int[length]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip = ”192.168.1.202”
conSuc, sock = connectETController ( robot_ip )
if (conSuc):
# Get the value of the profinet float type input register
suc , result , id = sendCMD(sock, ”get_profinet_float_input_registers”,{”addr” :0, ” length
” :1})
print ( result )
else :
print (”Connection failed”)
disconnectETController (sock)
2.2.10.4 Get the value of the profinet float type output register
DN:EC
123
2.2 Interface service
Function: Get the value of the profinet float type output register
Parameter: addr: register start address, range int[0,31]
length: number of registers, range int[1,32]
Note: the sum of addr and length should be less than or equal to 32
Return: list of register values int[length]
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip = ”192.168.1.202”
conSuc, sock = connectETController ( robot_ip )
if (conSuc):
# Get the value of the profinet float type output register
suc , result , id = sendCMD(sock, ”get_profinet_float_output_registers”,{”addr” :0, ”
length ” :1})
print ( result )
else :
print (”Connection failed”)
disconnectETController (sock)
{" jsonrpc ":"2.0" ," method ":" set_profinet_int_output_registers "," params ":{"
addr ":addr ," length ": length ," value ": value },"id": id}
{" jsonrpc ":"2.0" ," method ":" set_profinet_int_output_registers "," params ":{"
addr ":addr ," length ": length ," value ": value },"id": id}
Function: Set the value of the profinet float type output register
Parameter: addr: register start address, range int[0,31]
length: number of registers, range int[1,32]
Note: the sum of addr and length should be less than or equal to 32
value: list of register values, type double[length], element range
[-3.40E+38,3.40E+38]
Return: Success True, Failure False
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip = ”192.168.0.202”
conSuc, sock = connectETController ( robot_ip )
if (conSuc):
# Set the profinet float type output register
suc , result , id = sendCMD(sock, ”set_profinet_float_output_registers” , {”addr”: 0, ”
length ”: 2, ”value”: [1,1]})
print ( result )
else :
print (”Connection failed”)
disconnectETController (sock)
DN:EC
125
2.2 Interface service
DN:EC
126
2.2 Interface service
Note: This command is only supported in remote mode, and the robot must be in the reset
state.
Note: This command is only supported in remote mode, and the robot must be in reverse
drive mode.
DN:EC
127
2.2 Interface service
Note: The robot must be in a stopped or error state (excluding emergency stop alam).
This command is only supported in remote mode.
DN:EC
128
2.2 Interface service
2.2.12 Ethernet/IP
DN:EC
129
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" get_eip_int_output_registers "," params ":{"
addr ": addr ," length ": length },"id":id}
DN:EC
130
2.2 Interface service
2.2.12.3 Get the value of the Ethernet/IP float type input register
DN:EC
131
2.2 Interface service
2.2.12.4 Get the value of the Ethernet/IP float type output register
DN:EC
132
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" set_eip_int_output_registers "," params ":{"
addr ": addr ," length ": length },"id":id}
DN:EC
133
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" set_eip_float_output_registers "," params ":{"
addr ": addr ," length ": length },"id":id}
Note: This command can be used only in the remote mode and is applicable to v3.5.2 and above.
DN:EC
134
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" s t a r t _ p u s h _ f o r c e "," params ":{" r e t u r n _ f l a g ":
rerurn_flag},"id ":id}
Note: The function can be used only when the data source of the force control is SDK.
DN:EC
135
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" p u s h _ e x t e r n a l _ f o r c e "," params ":{" i n d e x ":index,
"torque_arry":torque_arry},"id ":id}
The value of the parameter index shall be gradually increased from 0 to 65535 after a
Note:
complete transfer process is started. When it reaches the maximum, the counter will
restart from 0. The parameter torque_arry will be marked as the latest data by
repeating this process.
Please call the parameter start_push_force first to mark the start of the external torque
data first before using this function. The function can be used only when the data
source of the force control is SDK.
DN:EC
136
2.2 Interface service
Note: The function can be used only when the data source of the force control is SDK.
DN:EC
137
2.2 Interface service
DN:EC
138
2.2 Interface service
2.2.13.5 Get the force and torque of the TCP based on the external force sensor
Function: Get the force and torque of the TCP based on the external force sensor
Parameter: none
Return: double force[6], the first three mean the force and the last three mean the
torque
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”172.16.11.223”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
suc , result , id=sendCMD(sock,”get_tcp_force_by_sensor”)
print ( result )
else:
print (”Connection failed”)
disconnectETController (sock)
Note: This command can be executed only when the external force sensor is connected.
This command is only applicable to v3.9.2 and above.
DN:EC
139
2.2 Interface service
2.2.13.6 Examples
2.2.13.6.1 Example 1 (of the data transfer: with the returned value)
1 import socket
2 import json
3 import os
4 import time import sleep
5
6 def connectETController (ip = " 1 9 2 . 1 6 8 . 1 . 2 0 0 " , port =8055) :
7 sock1 = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
8 try:
9 sock1. connect ((Ip , port))
10 return True , sock1
11 except Exception as e:
12 p r i n t ('error is',e)
13 sock1. close ()
14 return False , None
15
16 def disconnectETController (sock1):
17 if (sock1):
18 sock1. close ()
19 sock1 = None
20 else:
21 sock1 = None
22 def sendCMD (sock 1 , cmd , params = None , id =1):
23 if (not params ):
24 params = []
25 else:
26 params = json. dumps( params )
27 sendStr = "{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc
\":\"2.0\" ,\" id \":{2}}} ". format (cmd , params , id) + "\n"
28 try:
29 # print ( sendStr )
30 sock1. sendall ( bytes(sendStr , "utf -8"))
31 ret = sock1.recv (1024)
32 jData = json. loads(str(ret , "utf -8"))
33 # print( “ r a w d a t a : ” , j D a t a )
34 if " result " in jData .keys ():
DN:EC
140
2.2 Interface service
DN:EC
141
2.2 Interface service
73 arry[0] += 1
74 index += 1
75
76 ret , result , id = sendCMD (sock , " s t o p _ p u s h _ f o r c e " )
77 else:
78 print(" C o n n e c t i o n f a i l e d ")
79 disconnectETController (sock)
DN:EC
142
2.2 Interface service
1 import socket
2 import json
3 import os
4 from time import sleep
5
6 def connectETController (ip = " 1 9 2 . 1 6 8 . 1 . 2 0 0 " , port =8055) :
7 sock1 = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
8 try:
9 sock1. connect ((Ip , port))
10 return True , sock1
11 except Exception as e:
12 p r i n t ('error is',e)
13 sock1. close ()
14 return False , None
15
16 def disconnectETController (sock1):
17 if sock1:
18 sock1. close ()
19 sock1 = None
20 else:
21 sock1 = None
22
23 def sendCMD (sock 1 , cmd , params = None , id =1):
24 if not params :
25 params = []
26 else:
27 params = json. dumps( params )
28 sendStr = "{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc
\":\"2.0\" ,\" id \":{2}}} ". format (cmd , params , id) + "\n"
29 try:
30 sock1. sendall ( bytes(sendStr , "utf -8"))
31 ret = sock1.recv (1024)
32 jData = json. loads(str(ret , "utf -8"))
33 if " result " in jData .keys ():
34 return True , json. loads( jData[" result "]), jData["id"]
35 elif " error " in jData.keys ():
DN:EC
143
2.2 Interface service
DN:EC
144
2.2 Interface service
DN:EC
145
2.2 Interface service
DN:EC
146
2.2 Interface service
42
43 # Global variable
44 portDev = 'COM4'
45 baud = 460800 # 115200
46 parity = serial.PARITY_NONE # PARITY_ODD/PARITY_EVEN
47 stopbits = serial.STOPBITS_ONE
48 bytesize = serial.EIGHTBITS
49 tmout = 0.02 # unit sec
50
51 CMD_STOP_SEND = '43AA0D0A'
52 CMD_CLEAR_SEND = '47AA0D0A'
53 CMD_SEND_DATA = '49AA0D0A'
54 CMD_ACTIVE_SEND = '48AA0D0A'
55 DATA_HEAD = '48AA'
56 DATA_TAIL = '0D0A'
57
58 if __name__ == "__main__":
59 robot_ip = "172.16.11.200"
60 return_flag = True
61 index = 0
62 torque = [0, 0, 0, 0, 0, 0]
63 tm_begin = 0
64 call_tm = 0
65 err_cnt = 0
66
67 # Open the serial port
68 try:
69 ser = serial.Serial(port=portDev, baudrate=baud, parity=parity,
stopbits=stopbits, bytesize=bytesize, timeout=tmout)
70 except serial.serialutil.SerialException as err:
71 print("OS error: {0}".format(err))
72 exit()
73
74 if not ser.isOpen:
75 print("serial open unsuccessful.")
76 exit()
77
78 # Clear the buffer zone
79 ser.flushInput()
80
81 # Connect the robot
82 conSuc, sock = connectETController(robot_ip)
83 if not conSuc:
84 print("Failed to connect to Robot.")
DN:EC
147
2.2 Interface service
85 exit()
86
87 # Check if the data source of the force control mode is SDK
88 ret, result, id = sendCMD(sock, "get_force_ctrl_mode")
89 if result != 2: # sdk mode = 2
90 print("please change the mode to sdk.")
91 exit()
92
93 ret, result, id = sendCMD(sock, "stop_push_force")
94
95 # The sensor sends the data actively
96 while True:
97 ser.flushInput()
98 ser.write(bytes.fromhex(CMD_ACTIVE_SEND))
99 count = ser.inWaiting() # Get the buffer zone data of the serial port
100 if count > 0: # It is configured successfully if the data is received
101 break
102 sleep(0.01)
103
104 # Mark the start of the torque data transfer
105 ret, result, id = sendCMD(sock, "start_push_force", {"return_flag" :
return_flag})
106 if result != True:
107 exit()
108
109 print("Start to transmission force torque data.")
110
111 # Main loop
112 while True:
113 # A frame of the valid data is 28 bytes
114 if count > 27:
115 recvRaw = ser.read(count) # Read the serial port data, bytes type
116 beginIdx = recvRaw.find(bytes.fromhex(DATA_HEAD))
117 if beginIdx != -1:
118 endIdx = recvRaw.find(bytes.fromhex(DATA_TAIL), beginIdx)
119 if endIdx != -1 and endIdx - beginIdx == 26:
120 recv = recvRaw[beginIdx:endIdx + 2]
121 recv = list(recv)
122 f1_raw = recv[2:6]
123 f2_raw = recv[6:10]
124 f3_raw = recv[10:14]
125 f4_raw = recv[14:18]
126 f5_raw = recv[18:22]
127 f6_raw = recv[22:26]
DN:EC
148
2.2 Interface service
DN:EC
149
2.2 Interface service
169 count = ser.inWaiting() # Get the buffer zone data of the serial port
170
171 ret, result, id = sendCMD(sock, "stop_push_force")
172 disconnectETController(sock)
173 ser.close()
DN:EC
150
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" o p e n _ s e r i a l _ p o r t "," params ":{" d e v i c e _ t y p e ":
device_type},"id ":id}
Note: After the serial port is successfully opened, the serial data will be automatically
configured. The default baud rate is 9600. The default data length is 8. The default
parity bit is N, The default stop bit is 1. To modify the settings, please refer to
the section "Configure the serial port".
This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
151 DN:EC
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" s e t o p t _ s e r i a l _ p o r t "," params ":{" b a u d _ r a t e ":9600,
“bits":8,"event":"N", "stop":1},"id ": id}
Note: This command can be executed only when the serial port is opened.
This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
152 DN:EC
2.2 Interface service
Note: The results returned will determine if the data is valid or invalid. When the result is
true, the data is valid. This command can be executed only when the serial port is
opened. This command is only supported in the remote mode. This command is applic-
able to v3.6.2 and above.
153 DN:EC
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" s e n d _ s e r i a l _ p o r t "," params ":{" s e n d _ b u f ":"hello
world!"},"id ": id}
Note: The command can be executed only when the serial port is opened. This command is
only supported in the remote mode. This command is applic-able to v3.6.2 and above.
154 DN:EC
2.2 Interface service
Note: This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
155 DN:EC
2.2 Interface service
Note: This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
156 DN:EC
2.2 Interface service
Note: After the serial port is successfully opened, the serial data will be automatically
configured. The default baud rate is 9600. The default data length is 8. The default
parity bit is N, The default stop bit is 1. To modify the settings, please refer to
the section "Configure the serial port".
This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
157 DN:EC
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" s e t o p t _ t c i "," params ":{" b a u d _ r a t e ":9600,"bits":8,
"event":"N", "stop":1},"id ": id}
Note: This command can be executed only when the serial port is opened. This command
is only supported in the remote mode. This command is applicable to v3.6.2 and
above.
158 DN:EC
2.2 Interface service
Note: The results returned will determine if the data is valid or invalid. When the result is
true, the data is valid. This command can be executed only when the serial port is
opened. This command is only supported in the remote mode. This command is applic-
able to v3.6.2 and above.
159 DN:EC
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" s e n d _ t c i "," params ":{" s e n d _ b u f ":"hello world!"},
"id ": id}
Note: The command can be executed only when the serial port is opened. This command is
only supported in the remote mode. This command is applicable to v3.6.2 and above.
160 DN:EC
2.2 Interface service
Note: This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
161 DN:EC
2.2 Interface service
Note: This command is only supported in the remote mode. This command is applicable to
v3.6.2 and above.
162 DN:EC
2.2 Interface service
{" jsonrpc ":"2.0" ," method ":" s t a r t _ f o r c e _ m o d e "," params ":{" m o d e ": 3 ,
mode
" a r r _ f r a m e ": f r a m e ," a r r _ o p t i o n a l ":[6,1,5,1,0,1]," a r r _ t o r q u e ":
[-10,-10,-10,1.3,1.30,1.30]," arr_s p e e d ": s p e e d },"id":id}
163 DN:EC
2.2 Interface service
Note: The force control function can be enabled by using this command. In the process,
users can dynamically configure the related parameters.
When the force control mode is started, the jog movement is executed and the force
control mode will be automatically ended.
It is impossible to start the force control mode and configure the parameters when
the robot is moving.
It is also impossible to start the force control mode when selecting "Unknown data
source" from the drop-down list.
The drag function and the force control function are mutually exclusive. They
cannot work together.
Currently, users can only select the fixed mode, the TCP mode, the motion control
and the force tracking. This command is applicable to v3.6.2 and above.
Note: Once the force control mode is started, it is impossible to end the mode during the
robotic movement and the robot will stop running after sending this command.
This command is applicable to v3.6.2 and above.
Parameter: none
Return: True means that the robot is in the force control mode, false means that it is not in the
force control mode
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”172.16.11.248”
conSuc,sock=connectETController( robot_ip )
if (conSuc):
suc , result , id=sendCMD(sock,”get_force_mode_state”)
print (suc , result , id )
else:
print (”Connection failed”)
disconnectETController (sock)
DN:EC
165
2.2 Interface service
Function: Clear all values of the force sensor to zero and record the current force sensor data
Parameter: none
Return: True for success, false for failure
Example: if __name__ == ”__main__”:
# Robot IP address
robot_ip =”192.168.1.240”
conSuc,sock=connectETController( robot_ip )
point = []
point.append([0, -107.828, 119.349, -109.754, 83.351, -5.531, 0, 0])
point.append([10, -98.342, 51.251, -92.155, 90, 0, 0, 0])
point.append([-10.60024752475249, -80.04362623762376, 135.67295792079207,
-193.44984567901236, 123.90856481481481, 24.090277777777775])
point.append([47.40996287128712, -51.567450495049506, 49.92419554455446,
-88.9988425925926, 79.45138888888889, 160.08603395061726])
if (conSuc):
# Get the servo status of the robotic arm
suc , result , id=sendCMD(sock,”getServoStatus”)
print (suc, result, id )
if (result = =0):
# Set the servo status of the robotic arm to ON
suc , result , id=sendCMD(sock,”set_servo_status”,{”status”:1})
print (suc, result, id)
# Joint movement to the starting point
suc , result , id=sendCMD(sock,”moveByJoint”,{”targetPos”: point[0],”speed”:10,”acc”:20,”dec”:
20})
print (result):
time.sleep(1)
while 1:
ret, result, id=sendCMD(sock,”getRobotState”) :
if result==0:
break
# Start the force control mode
suc , result , id=sendCMD(sock,”start_force_mode”,{”mode”:0,”arr_frame”:[0,0,0,0,0,0],
” arr_optional ”:[0,0,1,0,0,0], ”arr_torque”:[0,0,0,0,0,0],”arr_speed”:[100,100,100,5.73,5.73,5.73]
})
print (suc, result, id)
# Clear all values to zero
ret, result , id=sendCMD(sock,”zero_force_sensor”)
print ( ”Clear all values to zero:”, result )
suc , result , id=sendCMD(sock,”moveByLine”,{”targetPos”: point[1],”speed”:100,”speed_type”:
166 DN:EC
2.2 Interface service
0, ”acc”:80,”dec”:80})
print (result):
while 1:
ret, result, id=sendCMD(sock,”getRobotState”) :
if result==0:
break
# End the force control mode
suc , result , id=sendCMD(sock,”end_force_mode”)
print (suc, result, id)
else :
print (”Connection failed”)
disconnectETController (sock)
Note: The current force sensor data will be read & saved when inserting the command
after STARTFORCEMODE. In the process of the force control, the current readings
will subtract what is previously saved.
The command is only valid when selecting LUA, SDK and Back-end data source in
the force control mode.
The command is only supported in remote mode. In the force control mode, the
command will be invalid after sending the command end_force_mode.
Note: After sending the instruction fc_act, the robot will start the force-seeking
movement. The force-seeking movement will be ended if other instructions like the
linear movement, the joint movement and the linear motion under specified
coordinate system are sent in the process. And the robot will execute these new
instructions.
The force-seeking movement will also be ended if the robot reports errors.
The robot will stop running and the force-seeking movement will be ended when
the pause or stop instruction is sent in the process.
This command is valid only when the robot stops running.
This command is only supported in remote mode
This command is applicable to v3.9.2 and above.
DN:EC
168
2.3 Examples
Note: This command is only supported in remote mode and is applicable to v3.9.2 and above.
2.3 Examples
2.3.1 Example 1
1 import socket
2 import json
3 import time
4 import random
5
6 def connectETController (ip ,port =8055) :
7 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
8 try:
9 sock. connect ((ip ,port))
10 return (True ,sock)
11 except Exception as e:
12 sock.close ()
13 return (False ,None)
14
15 def disconnectETController (sock):
16 if(sock):
17 sock.close ()
18 sock=None
DN:EC
169
2.3 Examples
19 else:
20 sock=None
21
22 def sendCMD (sock ,cmd , params =None ,id =1):
23 if(not params ):
24 params =[]
25 else:
26 params =json. dumps ( params )
27 sendStr ="{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc \":\"2.0\" ,\"
id \":{2}}} ". format (cmd ,params ,id)+"\n"
28 try:
29 sock. sendall ( bytes (sendStr ,"utf -8"))
30 ret =sock.recv (1024)
31 jdata=json.loads (str(ret ,"utf -8"))
32 if(" result " in jdata .keys ()):
33 return (True ,json.loads(jdata[" result "]) ,jdata["id"])
34 elif("error" in jdata.keys ()):
35 return (False , jdata[" error "], jdata["id"])
36 else:
37 return (False ,None ,None)
38 except Exception as e:
39 return (False ,None ,None)
40
41 if __name__ == " __main__ ":
42 # Robot IP address
43 robot_ip =" 192.168.1.202 "
44 conSuc ,sock= connectETController ( robot_ip )
45 print( conSuc )
46 if( conSuc ):
47 # Clear alarm
48 ret , result , id = sendCMD (sock , " clearAlarm ")
49 print("Clear alarm ")
50 print("ret = ", ret , "", "id = ", id)
51 if (ret == True):
52 print(" result = ", result )
53 time.sleep (1)
54 else:
55 print(" err_msg = ", result [" message "])
56 # Get synchronization status
57 ret , result , id = sendCMD (sock , " getMotorStatus ")
58 print("Get synchronization status ")
59 print("ret = ", ret , "", "id = ", id)
60 if (ret == True):
61 print(" result = ", result )
62 if( result != 1): DN:EC
170
2.3 Examples
63 # Synchronize
64 ret1 , result1 , id = sendCMD (sock , " syncMotorStatus ")
65 print(" synchronization ")
66 print("ret = ", ret1 , "", "id = ", id)
67 if (ret1 == True):
68 print(" result = ", result1 )
69 time.sleep (0.5)
70 else:
71 print(" err_msg = ", result1 [" message "])
72 else:
73 print(" err_msg = ", result [" message "])
74
75
76 # Turn on the servo
77 ret , result , id = sendCMD (sock , " set_servo_status ", {" status "
:1})
78 print("Turn on the servo ")
79 print("ret = ", ret , "", "id = ", id)
80 if (ret == True):
81 print(" result = ", result )
82 time.sleep (1)
83 else:
84 print(" err_msg = ", result [" message "])
85 # Get servo status
86 ret , result , id = sendCMD (sock , " getServoStatus ")
87 print("ret = ", ret , "", "id = ", id)
88 if(ret == True):
89 print(" result = ", result )
90 else:
91 print(" err_msg = ", result [" message "])
92 else:
93 print(" Connection failed ")
94 disconnectETController (sock)
2.3.2 Example 2
1 import socket
2 import json
3 import time
4
5
6 # v1 .2
DN:EC
171
2.3 Examples
7
8 def connectETController (ip , port =8055) :
9 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
10 try:
11 sock. connect ((ip , port))
12 return (True , sock)
13 except Exception as e:
14 sock.close ()
15 return (False , None)
16
17
18 def disconnectETController (sock):
19 if (sock):
20 sock.close ()
21 sock = None
22 else:
23 sock = None
24
25
26 def sendCMD (sock , cmd , params =None , id =1):
27 if (not params ):
28 params = []
29 else:
30 params = json.dumps( params )
31 sendStr = "{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc
\":\"2.0\" ,\" id \":{2}}} ". format (cmd , params , id) + "\n"
32 try:
33 # print ( sendStr )
34 sock. sendall (bytes(sendStr , "utf -8"))
35 ret = sock.recv (1024)
36 jdata = json.loads(str(ret , "utf -8"))
37 if (" result " in jdata.keys ()):
38 return (True , json.loads(jdata[" result "]), jdata["id"])
39 elif ("error" in jdata.keys ()):
40 return (False , jdata["error"], jdata["id"])
41 else:
42 return (False , None , None)
43 except Exception as e:
44 return (False , None , None)
45
46
47 if __name__ == " __main__ ":
48 ip = " 192.168.1.205 "
DN:EC
172
2.3 Examples
DN:EC
173
2.3 Examples
92 else:
93 print(" Connection failed ")
94 disconnectETController (sock)
2.3.3 Example 3
1 import socket
2 import json
3 import time
4
5
6
7 def connectETController (ip , port =8055) :
8 sock = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
9 try:
10 sock. connect ((ip , port))
11 return (True , sock)
12 except Exception as e:
13 sock.close ()
14 return (False , None)
15
16
17 def disconnectETController (sock):
18 if (sock):
19 sock.close ()
20 sock = None
21 else:
22 sock = None
23
24
25 def sendCMD (sock , cmd , params =None , id =1):
26 if (not params ):
27 params = []
28 else:
29 params = json.dumps( params )
30 sendStr = "{{\" method \":\"{0}\" ,\" params \":{1} ,\" jsonrpc
\":\"2.0\" ,\" id \":{2}}} ". format (cmd , params , id) + "\n"
31 try:
32 # print ( sendStr )
33 sock. sendall (bytes(sendStr , "utf -8"))
34 ret = sock.recv (1024)
35 jdata = json. loads (str(ret , "utf -8"))
DN:EC
174
2.3 Examples
DN:EC
175
2.3 Examples
76 else:
77 print(" Connection failed ")
78 disconnectETController (sock)
DN:EC
176
Chapter 3 Monitor Interface
Users can get robot information by connecting to monitor interface of the robot through the socket
client.
CAUTION
CAUTION
8056 is a (tcp) long-connection interface. If the access time exceeds 8ms, the data
will pile up in the buffer zone.
Message Size unsigned int32 4*1 The current packet length is 1024, the
effective field length is 801, the
reserved field length is 219, and the
parity field length is 4
DN:EC
177
3.1 Data description list of monitor interface
Reserved unsigned char 1*219 The reserved length of the data packet,
the length is 219
matchingWord unsigned int 4*1 parity bits, the last 4 bytes of the data
packet, it is valid only when the value is
3967833836 (i.e. 0xec8056ec).
Otherwise, the data will be invalid.
3.2 Example
1 import socket
2 import struct
3 import collections
4 import time
5 import math
6 HOST = " 192.168.1.202 "
7 PORT = 8056
8
9 while 1:
10 s = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
11 s. settimeout (8) DN:EC
179
3.2 Example
DN:EC
180
3.2 Example
DN:EC
182
3.2 Example
DN:EC
185
3.2 Example
DN:EC
186
Chapter 4 Log Interface
Users can connect to the robot log interface through the socket client.
The log types are: Error, Warning, Info. If the Error type is entered, Error information will be obtained;
If the Warning type is entered, the log information of Error and Warning types will be obtained; If you
enter Info, all types of log information will be obtained.
After connecting, enter all to enter all logs; enter a number, such as 10, to output the last 10 lines of
logs; enter exit to exit the connection.
4.1 Example
1 import socket
2 HOST = " 192.168.1.202 "
3 PORT = 8058
4
5 s = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
6 s. settimeout (2)
7 s. connect ((HOST ,PORT))
8 # New file or empty file content
9 # file = open(r'D :\205\ log\ all_err_log .md ','w ').close ()
10 # Get all log information
11 str1 = "Type=Info\n"
12 s.send(str1. encode ())
13 str2 = "all\n"
14 s.send(str2. encode ())
15 while True:
16 try:
17 data = s.recv (128000)
18 # with open(r'D :\205\ log\ all_err_log .md ','a+') as f:
19 # f.write (data. decode ())
20 print(data. decode ())
21 except ( Exception ):
22 break
23 s.close ()
DN:EC
187
Chapter 5 Raw Log Interface
Users can connect to the raw log interface of the robot through the socket client.
After connecting, enter all to enter all logs; enter a number, such as 10, to output the last 10 lines of
logs; enter exit to exit the connection.
CAUTION
5.1 Example
1 import socket
2 HOST = " 192.168.1.205 "
3 PORT = 8059
4
5 s = socket . socket ( socket .AF_INET , socket . SOCK_STREAM )
6 s. settimeout (2)
7 s. connect ((HOST ,PORT))
8 # New file or empty file content
9 file = open(r'D :\205\ log\ err_log_1 .md ','w').close ()
10
11 # Get the last 10 log entries , the number sent corresponds to the
number of log entries obtained
12 str1 = "10\n"
13 s.send(str1. encode ())
14 while True:
15 try:
16 data = s.recv (1024)
17 with open(r'D :\205\ log\ err_log_1 .md ','a+') as f:
18 f.write(data. decode ())
19 print(data. decode ())
20 except ( Exception ):
21 break
22 s.close ()
DN:EC
188
ALWAYS EASIER THAN BEFORE
- Contact Us
Sales & Service: [email protected]
Technical Support: [email protected]
- Shanghai
Building 18, Lane 36,
Xuelin Road, Shanghai
- Suzhou
1F, Building 4,
No 259 Changyang Street, Suzhou
+86-400-189-9358
+86-0512-83951898
- Beijing
Room 1102, Building 6, No. 2,
Ronghua South Road, Beijing
- Shenzhen WeChat
Room 202, Building 1A, Official Account
Hangkong Road, Shenzhen
www.elibot.cn