From a4009eb17c23ffefa5924d3d72032ff35451a82d Mon Sep 17 00:00:00 2001 From: gitea Date: Sun, 23 Jun 2024 20:18:41 +0800 Subject: [PATCH] =?UTF-8?q?20240623=208.=20[openapi.py]=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BF=83=E8=B7=B3=E6=A3=80=E6=B5=8B=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=BC=80=E5=90=AF=E7=BA=BF=E7=A8=8B=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=EF=BC=9B=E5=8F=96=E6=B6=88=E5=9C=A8=E8=AF=A5=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E7=94=9F=E6=88=90=E5=AE=9E=E4=BE=8B=209.=20[?= =?UTF-8?q?aio.py]=20=E5=AE=8C=E6=88=90detect=5Fnetwork=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=9C=A8main=E5=87=BD=E6=95=B0=E5=BC=80=E5=90=AF=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=2010.=20=E5=B0=86templates=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0assets=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aio/README.md | 13 ++++--- aio/assets/templates/controller.heart.json | 5 +++ .../templates/device.get_params.json | 0 aio/assets/templates/heartbeat | 1 + .../templates/state.get_state.json | 0 .../templates/state.get_tp_mode.json | 0 .../templates/state.set_tp_mode.json | 0 .../templates/state.switch_auto.json | 0 .../templates/state.switch_manual.json | 0 .../templates/state.switch_motor_off.json | 0 .../templates/state.switch_motor_on.json | 0 aio/code/aio.py | 17 +++++++--- aio/code/automatic_test/do_brake.py | 9 +++-- aio/code/automatic_test/openapi.py | 34 ++++++++++--------- 14 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 aio/assets/templates/controller.heart.json rename aio/{code/automatic_test => assets}/templates/device.get_params.json (100%) create mode 100644 aio/assets/templates/heartbeat rename aio/{code/automatic_test => assets}/templates/state.get_state.json (100%) rename aio/{code/automatic_test => assets}/templates/state.get_tp_mode.json (100%) rename aio/{code/automatic_test => assets}/templates/state.set_tp_mode.json (100%) rename aio/{code/automatic_test => assets}/templates/state.switch_auto.json (100%) rename aio/{code/automatic_test => assets}/templates/state.switch_manual.json (100%) rename aio/{code/automatic_test => assets}/templates/state.switch_motor_off.json (100%) rename aio/{code/automatic_test => assets}/templates/state.switch_motor_on.json (100%) diff --git a/aio/README.md b/aio/README.md index 79b4cac..6e4110b 100644 --- a/aio/README.md +++ b/aio/README.md @@ -254,11 +254,14 @@ v0.1.7.0(2024/06/29) 5. [aio.py] 修改了Data Process中初始化的动作,使得初始化时的状态统一成程序刚启动时的样子 6. [aio.py] 增加了tabview的点击行为函数,每次点击tab都会初始化 7. [aio.py] 增加了Automatic Test界面元素,包括如下,并完成了功能框架的搭建 -- 标签:文件/角速度/减速比 -- 按钮:急停及恢复 -- 输入框:文件路径/角速度/减速比 -- OptionMenu:负载 -- 进度条 + - 标签:文件/角速度/减速比 + - 按钮:急停及恢复 + - 输入框:文件路径/角速度/减速比 + - OptionMenu:负载 + - 进度条 +8. [openapi.py] 增加心跳检测函数,并开启线程执行;取消在该文件中生成实例 +9. [aio.py] 完成detect_network,并在main函数开启线程 +10. 将templates文件夹移动到assets内 > **关于HMI接口** > - 封包解包顺序:帧长度二字节/包长度四字节/协议二字节/预留二字节,\x04\x00:\x00\x00\tR:\x02:\x00 diff --git a/aio/assets/templates/controller.heart.json b/aio/assets/templates/controller.heart.json new file mode 100644 index 0000000..27300d6 --- /dev/null +++ b/aio/assets/templates/controller.heart.json @@ -0,0 +1,5 @@ +{ + "id": "xxxxxxxxxxx", + "module": "system", + "command": "controller.heart" +} \ No newline at end of file diff --git a/aio/code/automatic_test/templates/device.get_params.json b/aio/assets/templates/device.get_params.json similarity index 100% rename from aio/code/automatic_test/templates/device.get_params.json rename to aio/assets/templates/device.get_params.json diff --git a/aio/assets/templates/heartbeat b/aio/assets/templates/heartbeat new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/aio/assets/templates/heartbeat @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/aio/code/automatic_test/templates/state.get_state.json b/aio/assets/templates/state.get_state.json similarity index 100% rename from aio/code/automatic_test/templates/state.get_state.json rename to aio/assets/templates/state.get_state.json diff --git a/aio/code/automatic_test/templates/state.get_tp_mode.json b/aio/assets/templates/state.get_tp_mode.json similarity index 100% rename from aio/code/automatic_test/templates/state.get_tp_mode.json rename to aio/assets/templates/state.get_tp_mode.json diff --git a/aio/code/automatic_test/templates/state.set_tp_mode.json b/aio/assets/templates/state.set_tp_mode.json similarity index 100% rename from aio/code/automatic_test/templates/state.set_tp_mode.json rename to aio/assets/templates/state.set_tp_mode.json diff --git a/aio/code/automatic_test/templates/state.switch_auto.json b/aio/assets/templates/state.switch_auto.json similarity index 100% rename from aio/code/automatic_test/templates/state.switch_auto.json rename to aio/assets/templates/state.switch_auto.json diff --git a/aio/code/automatic_test/templates/state.switch_manual.json b/aio/assets/templates/state.switch_manual.json similarity index 100% rename from aio/code/automatic_test/templates/state.switch_manual.json rename to aio/assets/templates/state.switch_manual.json diff --git a/aio/code/automatic_test/templates/state.switch_motor_off.json b/aio/assets/templates/state.switch_motor_off.json similarity index 100% rename from aio/code/automatic_test/templates/state.switch_motor_off.json rename to aio/assets/templates/state.switch_motor_off.json diff --git a/aio/code/automatic_test/templates/state.switch_motor_on.json b/aio/assets/templates/state.switch_motor_on.json similarity index 100% rename from aio/code/automatic_test/templates/state.switch_motor_on.json rename to aio/assets/templates/state.switch_motor_on.json diff --git a/aio/code/aio.py b/aio/code/aio.py index 3957b23..cab3ac4 100644 --- a/aio/code/aio.py +++ b/aio/code/aio.py @@ -4,7 +4,7 @@ from os import getcwd from threading import Thread import tkinter.messagebox import customtkinter -from time import time, strftime, localtime +from time import time, strftime, localtime, sleep from urllib.request import urlopen from socket import setdefaulttimeout import data_process.brake as brake @@ -70,9 +70,6 @@ widgits_at = { class App(customtkinter.CTk): def __init__(self): super().__init__() - self.net_detect = Thread(target=self.detect_network) - self.net_detect.daemon = True - self.net_detect.start() self.my_font = customtkinter.CTkFont(family="Consolas", size=16, weight="bold") self.w_param = 84 # ===================================================================== @@ -209,7 +206,11 @@ class App(customtkinter.CTk): pass def detect_network(self): - pass + while True: + with open('./automatic_test/templates/heartbeat', 'r', encoding='utf-8') as f_h: + pb_color = 'green' if f_h.read().strip() == '1' else 'red' + self.progressbar.configure(progress_color=pb_color) + sleep(3) def thread_it(self, func, *args): """ 将函数打包进线程 """ @@ -489,5 +490,11 @@ class App(customtkinter.CTk): if __name__ == "__main__": + with open("./automatic_test/templates/heartbeat", "w", encoding='utf-8') as f_h: + f_h.write('0') + aio = App() + aio.net_detect = Thread(target=aio.detect_network) + aio.net_detect.daemon = True + aio.net_detect.start() aio.mainloop() diff --git a/aio/code/automatic_test/do_brake.py b/aio/code/automatic_test/do_brake.py index 3e9bdc9..854fe7d 100644 --- a/aio/code/automatic_test/do_brake.py +++ b/aio/code/automatic_test/do_brake.py @@ -1,16 +1,19 @@ import openapi -hr = openapi.hr +hr = openapi.HmiRequest() # 一、设置/检测机器人状态: # 1. 上电 # 2. 软限位打开 # 3. 示教器断开 -# 4. 操作模式 +# 4. 操作模式/机器人类型 # 5. 控制器状态/工作任务控件/机器人动态 # 二、加载RL程序开始运行 - +# 1. 怎么触发急停 +# 2. 怎么恢复急停 +# 3. 怎么采集曲线 +# 4. # 三、运行过程中,收集数据,并处理出结果 diff --git a/aio/code/automatic_test/openapi.py b/aio/code/automatic_test/openapi.py index b9cd64c..b65d548 100644 --- a/aio/code/automatic_test/openapi.py +++ b/aio/code/automatic_test/openapi.py @@ -10,25 +10,26 @@ MAX_FRAME_SIZE = 1024 class HmiRequest(object): def __init__(self): + super().__init__() self.c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.c.connect(('192.168.0.160', 5050)) - # self.c.connect(('192.168.84.129', 5050)) + # self.c.connect(('192.168.0.160', 5050)) + self.c.connect(('192.168.84.129', 5050)) self.c.setblocking(False) self.c_msg = [] self.c_xs = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.c_xs.connect(('192.168.0.160', 6666)) - # self.c_xs.connect(('192.168.84.129', 6666)) + # self.c_xs.connect(('192.168.0.160', 6666)) + self.c_xs.connect(('192.168.84.129', 6666)) self.c_xs.setblocking(False) self.c_msg_xs = [] + self.t_heartbeat = threading.Thread(target=self.__heartbeat) + self.t_heartbeat.daemon = True + self.t_heartbeat.start() self.t_unpackage = threading.Thread(target=self.__unpackage, args=(self.c, )) self.t_unpackage.daemon = True self.t_unpackage.start() self.t_unpackage_xs = threading.Thread(target=self.__unpackage_xs, args=(self.c_xs, )) self.t_unpackage_xs.daemon = True self.t_unpackage_xs.start() - # self.t = threading.Thread(target=self.__heartbeat) - # self.t.daemon = True - # self.t.start() self.flag = 0 self.response = '' self.leftover = 0 @@ -52,6 +53,14 @@ class HmiRequest(object): print("无法读取数据,需要确认") exit(10) + def __heartbeat(self): + while True: + _id = self.excution('controller.heart') + _flag = 1 if self.get_from_id(_id) else 0 + with open("./templates/heartbeat", "w", encoding='utf-8') as f_h: + f_h.write(str(_flag)) + time.sleep(10) + def __msg_storage(self, response, flag=0): messages = self.c_msg if flag == 0 else self.c_msg_xs if len(messages) < 1000: @@ -154,7 +163,8 @@ class HmiRequest(object): return msg time.sleep(1) else: - print(f'无法查询到{msg_id}对应的响应') + # print(f'无法查询到{msg_id}对应的响应') + return None def __package(self, cmd): _frame_head = (len(cmd)+6).to_bytes(length=2, byteorder='big') @@ -234,11 +244,3 @@ class HmiRequest(object): return req['id'] else: # for xService pass - - -hr = HmiRequest() - - - - -