Hi, all.
I’m trying to use interpreter mode to communicate with Schunk EGK 40M. Now, I can send the command by port 30003 from remote laptop, and enable the interpreter mode by port 30020. The configuration of connection shows bellow:
class SchunkGripper:
# num of commands after which clear_interpreter() command will be invoked.
# If interpreted statements are not cleared periodically then "runtime too much behind" error may
# be shown when leaving interpreter mode
CLEARBUFFER_LIMIT = 20 # DONOT USE IT NOW --- clear the buffer for interpreter mode (the number of command you want to perform)
# EGUEGK_rpc_ip = "127.0.0.1"
EGUEGK_rpc_ip = "10.42.0.162"
UR_INTERPRETER_SOCKET = 30020
Enable_Interpreter_Socket = 30003
STATE_REPLY_PATTERN = re.compile(r"(\w+):\W+(\d+)?") # DONOT USE IT NOW
schunk_socket_name = "socket_grasp_sensor"
gripper_index = 0
ENCODING = 'UTF-8'
EGUEGK_socket_uid = 0
uid_th = 500
timeout = 1000
def __init__(self):
self.enable_interpreter_socket = None # the script port socket, for enabling interpreter mode
self.socket = None # interpreter mode socket, for sending gripper command
self.schunk_socket = None # schunk msg socket
def connect(self, hostname: str, port: int, socket_timeout: float = 2.0) -> None:
# connect to the gripper's address
# hostname: robot's ip
# port: the local free port created for Schunk (not 30003 and 30020)
self.port = port
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.enable_interpreter_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.schunk_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((hostname, self.UR_INTERPRETER_SOCKET))
self.socket.settimeout(socket_timeout)
self.enable_interpreter_socket.connect((hostname, self.Enable_Interpreter_Socket))
self.enable_interpreter_socket.settimeout(socket_timeout)
try:
self.scriptport_command("interpreter_mode()")
time.sleep(4) # waiting the polyscope enable interpreter mode
except:
print("[ERROR] open interpreter mode failed")
exit(0)
def schunk_rpcCallRe(self, socket_name, command):
# open another socket name for Schunk rpc_ip and port
try:
self.execute_command(f'socket_open("{self.EGUEGK_rpc_ip}", {self.port}, "{socket_name}")')
# time.sleep(2) # waiting the socket opened in robotic local network
except:
print("[ERROR] open robotic local socket failed")
exit(0)
self.execute_command(f'socket_send_line("{command}", "{socket_name}")\nsync()\n')
#----schunk test---------
# tmp_command = f'socket_send_line("{command}", "{socket_name}")\nsync()\n'
# self.schunk_socket.sendall(tmp_command.encode(self.ENCODING))
# tmp_command = f'socket_read_line("{socket_name}", {self.timeout})\n'
# self.schunk_socket.sendall(tmp_command.encode(self.ENCODING))
# response = self.schunk_socket.recv(1024)
# print("response info from SCHUNK port:", response.decode(self.ENCODING))
#------------------------
self.execute_command(f'socket_read_line("{socket_name}", {self.timeout})\n')
response = self.schunk_socket.recv(1024)
self.execute_command(f'socket_close("{socket_name}")')
return response
# send get_XXX command
def scriptport_command(self, command) -> None:
# the port 30003 for urscript to communicate with UR robot
if not command.endswith("\n"):
command += "\n"
print(command.encode(self.ENCODING))
self.enable_interpreter_socket.sendall(command.encode(self.ENCODING))
def execute_command(self, command):
# the port 30020 for interpreter mode to communicate with the binding port for Schunk
if not command.endswith("\n"):
command += "\n"
print(command.encode(self.ENCODING))
self.socket.sendall(command.encode(self.ENCODING))
# data = self.socket.recv(1024)
# return data
Then, the schunk has the command contribution, I can send the controlling command to control the gripper now, but when I try to read the information, there are none information feedback from the port. For example, the moveAbsolute is work but getPosition not. What I can confirm is that their shunck command is correct, so I guess there may be something wrong with my interpreter mode configuration. Does anyone know what is wrong with my configuration? Thank you!
EXP:
def moveAbsolute(self, gripperIndex, position, speed):
command = "absolute(" + str(gripperIndex) + ", " + str(position) + ", " + str(speed) + ")"
self.schunkHelperFunc(self.schunk_socket_name,command)
def getPosition(self, gripperNunber=1): # TODO: use other socket name, see egk_contribution.script
gripperIndex = gripperNunber - 1
command = "getPosition(" + str(gripperIndex) + ")"
socket_name = str("socket_status_position_" + str(self.EGUEGK_getNextId()))
response = self.schunkHelperFuncRe(socket_name, command)
# self.status_rpcCall(socket_name, command)
# response = self.schunkHelperFunc(str("socket_status_position_" + str(EGUEGK_getNextId())), command)
return response
def schunkHelperFunc(self, socket_name, command):
# send command
# command += "\n\tsync()\n"
self.schunk_rpcCall(socket_name, command)
def schunkHelperFuncRe(self, socket_name, command):
# send command
# command += "\n\tsync()\n"
response = self.schunk_rpcCallRe(socket_name, command)
# self.execute_command(f'socket_send_line("{command}", "{self.schunk_socket_name}")\n')
return response.decode()