Please refer to Elite EC sdk manual to add commands as need.
For example by replacing the "" part, we could modify the command in suc,result,id=sendCMD(sock,"syncMotorStatus")
Please be aware that robot need to be under remote mode and the quotation mark need to be the English one.
from math import sqrt
import socket
import json
import time
def connectETController(ip,port=8055):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((ip,port))
return (True,sock)
except Exception as e:
sock.close()
return (False,)
def sendCMD(sock,cmd,params=None,id=1):
if(not params):
params=[]
else:
params=json.dumps(params)
sendStr="{{\"method\":\"{0}\",\"params\":{1} ,\"jsonrpc\":\"2.0\",\"id\":{2}}}".format(cmd,params,id)+"\n"
try:
sock.sendall(bytes(sendStr,"utf-8"))
ret=sock.recv(1024)
jdata=json.loads(str(ret,"utf-8"))
if("result" in jdata.keys()):
return (True,json.loads(jdata["result"]),jdata["id"])
elif("error" in jdata.keys()):
return (False,jdata["error"],jdata["id"])
else:
return (False,None,None)
except Exception as e:
return (False,None,None)
if __name__ == "__main__":
robot_ip="192.168.1.200"
conSuc,sock=connectETController(robot_ip)
if(conSuc):
suc,result,id=sendCMD(sock,"syncMotorStatus")
print("Motor Synchoronization is", result)
time.sleep(0.1)
def disconnectETController(sock):
if (sock):
sock.close()
sock = None
else:
sock = None