jiaru recv

This commit is contained in:
LiangShiyun 2025-06-12 21:36:36 +08:00
parent be25ee8e74
commit 5461a09eee
2 changed files with 29 additions and 11 deletions

View File

@ -545,6 +545,7 @@ class MassageRobot:
def arm_command_loop(self):
self.logger.log_info("机械臂控制线程启动")
self.arm.filter_matirx = np.zeros((1,7)) # 位姿伺服用
recv_time = 0
# self.arm.filter_matrix = np.zeros((1,6)) # 角度伺服用
while (not self.arm.is_exit) and (not self.exit_event.is_set()):
try:
@ -581,7 +582,7 @@ class MassageRobot:
).encode()
run_time = time.time() - process_start_time
sleep_duration = self.control_rate.to_sec() - run_time
sleep_duration = self.control_rate.to_sec() - run_time - recv_time
b2 =time.time()
if sleep_duration > 0:
time.sleep(sleep_duration)
@ -594,6 +595,9 @@ class MassageRobot:
break
try:
self.arm.dashboard.socket_dobot.sendall(tcp_command)
recv_start_time = time.time()
self.arm.dashboard.socket_dobot.recv(1024)
recv_time = time.time() - recv_start_time
break
except Exception as e:
print(f"发送指令错误:{e}")

View File

@ -178,21 +178,33 @@ class DobotApi:
# self.log(f'Receive from {self.ip}:{self.port}: {data_str}')
return data_str
# def flush_recv_buffer(self):
# """非阻塞清空接收缓冲区"""
# self.socket_dobot.setblocking(0)
# try:
# while True:
# ready = select.select([self.socket_dobot], [], [], 0.01)
# if ready[0]:
# try:
# self.socket_dobot.recv(1024)
# except:
# break
# else:
# break
# finally:
# self.socket_dobot.setblocking(1)
def flush_recv_buffer(self):
"""非阻塞清空接收缓冲区"""
self.socket_dobot.setblocking(0)
"""极速清空接收缓冲区"""
self.socket_dobot.setblocking(False)
try:
while True:
ready = select.select([self.socket_dobot], [], [], 0.01)
if ready[0]:
try:
self.socket_dobot.recv(1024)
except:
break
else:
try:
self.socket_dobot.recv(4096) # 一次最多清64KB
except BlockingIOError:
break
finally:
self.socket_dobot.setblocking(1)
self.socket_dobot.setblocking(True)
def close(self):
"""
@ -1947,7 +1959,9 @@ class DobotApiDashboard(DobotApi):
for ii in params:
string = string + ','+ii
string = string + ')'
start_time = time.time()
self.flush_recv_buffer()
print(f"+++++++{time.time()-start_time}s++++++")
return self.sendRecvMsg(string)
def MovL(self, a1, b1, c1, d1, e1, f1, coordinateMode, user=-1, tool=-1, a=-1, v=-1, speed=-1, cp=-1, r=-1):