diff --git a/aio/README.md b/aio/README.md index 294c7a2..1b75caf 100644 --- a/aio/README.md +++ b/aio/README.md @@ -499,3 +499,15 @@ v0.1.9.4(2024/07/15) 4. [profile: openapi.py]:多次合并遗留问题处理 5. templates文件夹组织架构调整 +v0.2.0.0(2024/07/17) +1. [profile: aio.py] + - 增加velocity相关逻辑 + - 修改负载信息为曲线信息 +2. [profile: factory_test.py] + - 增加velocity相关逻辑 +3. [profile: current.py] + - 修正减速比获取的规则 +4. [profile: openapi.py] + - HmiRequest模块:日志取消记录move.monitor相关 + - HmiRequest模块:增加了durable_lock变量,控制文件读写互斥 + diff --git a/aio/assets/file_version_info.txt b/aio/assets/file_version_info.txt index 5f58e11..e1ab27a 100644 --- a/aio/assets/file_version_info.txt +++ b/aio/assets/file_version_info.txt @@ -6,8 +6,8 @@ VSVersionInfo( ffi=FixedFileInfo( # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # Set not needed items to zero 0. - filevers=(0, 1, 9, 2), - prodvers=(0, 1, 9, 2), + filevers=(0, 2, 0, 0), + prodvers=(0, 2, 0, 0), # Contains a bitmask that specifies the valid bits 'flags'r mask=0x3f, # Contains a bitmask that specifies the Boolean attributes of the file. @@ -31,12 +31,12 @@ VSVersionInfo( '040904b0', [StringStruct('CompanyName', 'Rokae - https://www.rokae.com/'), StringStruct('FileDescription', 'All in one automatic toolbox'), - StringStruct('FileVersion', '0.1.9.2 (2024-07-13)'), + StringStruct('FileVersion', '0.2.0.0 (2024-07-17)'), StringStruct('InternalName', 'AIO.exe'), StringStruct('LegalCopyright', '© 2024-2024 Manford Fan'), StringStruct('OriginalFilename', 'AIO.exe'), StringStruct('ProductName', 'AIO'), - StringStruct('ProductVersion', '0.1.9.2 (2024-07-13)')]) + StringStruct('ProductVersion', '0.2.0.0 (2024-07-17)')]) ]), VarFileInfo([VarStruct('Translation', [1033, 1200])]) ] diff --git a/aio/assets/templates/durable/durable_data_current.xlsx b/aio/assets/templates/durable/durable_data_current.xlsx index f438a2a..1d18002 100644 Binary files a/aio/assets/templates/durable/durable_data_current.xlsx and b/aio/assets/templates/durable/durable_data_current.xlsx differ diff --git a/aio/assets/templates/durable/durable_data_velocity.xlsx b/aio/assets/templates/durable/durable_data_velocity.xlsx index f438a2a..9043fa3 100644 Binary files a/aio/assets/templates/durable/durable_data_velocity.xlsx and b/aio/assets/templates/durable/durable_data_velocity.xlsx differ diff --git a/aio/assets/vers b/aio/assets/vers index ea80ca6..82f7d35 100644 --- a/aio/assets/vers +++ b/aio/assets/vers @@ -1 +1 @@ -0.1.9.2 @ 07/13/2024 \ No newline at end of file +0.2.0.0 @ 07/17/2024 \ No newline at end of file diff --git a/aio/code/aio.py b/aio/code/aio.py index 89c9406..a53b21c 100644 --- a/aio/code/aio.py +++ b/aio/code/aio.py @@ -64,7 +64,7 @@ widgits_at = { } widgits_da = { 'path': {'label': '', 'entry': '', 'row': 1, 'col': 2, 'text': '数据文件夹路径'}, - 'loadsel': {'label': '', 'optionmenu': '', 'row': 1, 'col': 1, 'text': '负载选择'}, + 'curvesel': {'label': '', 'optionmenu': '', 'row': 1, 'col': 1, 'text': '曲线选择'}, } @@ -78,6 +78,7 @@ class App(customtkinter.CTk): self.canvas = None self.flg = 0 self.df_copy = None + self.old_curve = None # ===================================================================== # configure window self.title("AIO - All in one automatic toolbox") @@ -104,7 +105,7 @@ class App(customtkinter.CTk): btns_func['log']['btn'].configure(command=lambda: self.thread_it(self.func_log_callback)) btns_func['end']['btn'].configure(command=lambda: self.thread_it(self.func_end_callback)) # create version info - self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.9.2\nDate: 07/13/2024", font=self.my_font, text_color="#4F4F4F") + self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.2.0.0\nDate: 07/17/2024", font=self.my_font, text_color="#4F4F4F") self.frame_func.rowconfigure(6, weight=1) self.label_version.grid(row=6, column=0, padx=20, pady=20, sticky='s') # ===================================================================== @@ -183,8 +184,8 @@ class App(customtkinter.CTk): widgits_da[widgit]['label'].grid(row=widgits_da[widgit]['row'], column=widgits_da[widgit]['col'], sticky='e', padx=(20, 5), pady=10) widgits_da[widgit]['entry'] = customtkinter.CTkEntry(self.tabview.tab('Durable Action'), width=670, placeholder_text=widgits_da[widgit]['text'], font=self.my_font) widgits_da[widgit]['entry'].grid(row=widgits_da[widgit]['row'], column=widgits_da[widgit]['col']+1, columnspan=11, padx=(5, 10), pady=10, sticky='we') - elif widgit in ['loadsel']: - widgits_da[widgit]['optionmenu'] = customtkinter.CTkOptionMenu(self.tabview.tab('Durable Action'), button_color='#708090', fg_color='#778899', values=["tool100", "inertia"], font=self.my_font) + elif widgit in ['curvesel']: + widgits_da[widgit]['optionmenu'] = customtkinter.CTkOptionMenu(self.tabview.tab('Durable Action'), button_color='#708090', fg_color='#778899', values=["device_servo_trq_feedback", "hw_joint_vel_feedback"], font=self.my_font) widgits_da[widgit]['optionmenu'].grid(row=widgits_da[widgit]['row'], column=widgits_da[widgit]['col'], padx=5, pady=10, sticky='we') widgits_da[widgit]['optionmenu'].set(widgits_da[widgit]['text']) # For durable_action tab END ===================================================================== @@ -218,19 +219,37 @@ class App(customtkinter.CTk): plt.rcParams['font.size'] = 14 plt.rcParams['lines.marker'] = 'o' - df = pd.read_excel(durable_data_current_xlsx) - if not df.equals(self.df_copy) or self.flg == 0: + curvesel = widgits_da['curvesel']['optionmenu'].get() + while True: + if not self.hr.durable_lock: + self.hr.durable_lock = 1 + if curvesel == 'device_servo_trq_feedback': + df = pd.read_excel(durable_data_current_xlsx) + _title = 'device_servo_trq_feedback' + elif curvesel == 'hw_joint_vel_feedback': + _title = 'hw_joint_vel_feedback' + df = pd.read_excel(durable_data_velocity_xlsx) + else: + _title = 'device_servo_trq_feedback' + df = pd.read_excel(durable_data_current_xlsx) + self.hr.durable_lock = 0 + break + else: + sleep(1) + + if not df.equals(self.df_copy) or self.flg == 0 or curvesel != self.old_curve: self.flg = 1 self.df_copy = df.copy() + self.old_curve = widgits_da['curvesel']['optionmenu'].get() figure = plt.figure(frameon=True, facecolor='#E9E9E9') - plt.subplots_adjust(left=0.04, right=0.98, bottom=0.05, top=0.98) + plt.subplots_adjust(left=0.04, right=0.98, bottom=0.05, top=0.95) ax = figure.add_subplot(1, 1, 1) df.plot(grid=True, x='time', y='axis1', ax=ax) df.plot(grid=True, x='time', y='axis2', ax=ax) df.plot(grid=True, x='time', y='axis3', ax=ax) df.plot(grid=True, x='time', y='axis4', ax=ax) df.plot(grid=True, x='time', y='axis5', ax=ax) - df.plot(grid=True, x='time', y='axis6', ax=ax) + df.plot(grid=True, x='time', y='axis6', ax=ax, title=_title, legend='upper left') self.create_canvas(figure) @@ -264,6 +283,8 @@ class App(customtkinter.CTk): def detect_network(self): df = pd.DataFrame(durable_data_current) df.to_excel(durable_data_current_xlsx, index=False) + df = pd.DataFrame(durable_data_velocity) + df.to_excel(durable_data_velocity_xlsx, index=False) with open(heartbeat, "w", encoding='utf-8') as f_hb: f_hb.write('0') @@ -293,23 +314,19 @@ class App(customtkinter.CTk): if tab_name == 'Data Process': self.flg = 0 self.menu_main_dp.set("Start Here!") - try: - self.canvas.get_tk_widget().grid_forget() - except: - pass elif tab_name == 'Automatic Test': self.flg = 0 self.menu_main_at.set("Start Here!") self.seg_button.configure(state='normal') - try: - self.canvas.get_tk_widget().grid_forget() - except: - pass elif tab_name == 'Durable Action': pass def initialization(self): tab_name = self.tabview.get() + try: + self.canvas.get_tk_widget().grid_forget() + except: + pass self.textbox.delete(index1='1.0', index2='end') if tab_name == 'Data Process': for widgit in widgits_dp: @@ -343,9 +360,9 @@ class App(customtkinter.CTk): widgits_da[widgit]['label'].configure(text=f'{widgit.upper()}', text_color='black') widgits_da[widgit]['entry'].delete(0, tkinter.END) widgits_da[widgit]['entry'].configure(placeholder_text=widgits_at[widgit]['text'], state='normal') - elif widgit in ['loadsel']: + elif widgit in ['curvesel']: widgits_da[widgit]['optionmenu'].configure(state='normal') - widgits_da[widgit]['optionmenu'].set(widgits_at[widgit]['text']) + widgits_da[widgit]['optionmenu'].set(widgits_da[widgit]['text']) def func_main_callback(self, func_name): self.initialization() @@ -564,11 +581,11 @@ class App(customtkinter.CTk): return 0, 0 elif tab_name == 'Durable Action': path = widgits_da['path']['entry'].get().strip() - loadsel = widgits_da['loadsel']['optionmenu'].get() + curvesel = widgits_da['curvesel']['optionmenu'].get() c1 = exists(path) - c2 = loadsel in ['tool100', 'inertia'] + c2 = curvesel in ['device_servo_trq_feedback', 'hw_joint_vel_feedback'] if c1 and c2: - return 7, path, loadsel + return 7, path, curvesel else: return 0, 0 diff --git a/aio/code/data_process/current.py b/aio/code/data_process/current.py index c976697..52c65ea 100644 --- a/aio/code/data_process/current.py +++ b/aio/code/data_process/current.py @@ -251,7 +251,7 @@ def p_single(wb, single, vel, trq, rpms, rrs, w2t): set_option("display.precision", 2) if data_file.endswith('.data'): df = read_csv(data_file, sep='\t') - rr = rrs[axis+1] + rr = rrs[axis-1] addition = 180 / 3.1415926 * 60 / 360 * rr elif data_file.endswith('.csv'): df = read_csv(data_file, sep=',', encoding='gbk', header=8) @@ -331,7 +331,7 @@ def p_scenario(wb, single, vel, trq, rpms, rrs, dur, w2t): set_option("display.precision", 2) if data_file.endswith('.data'): df = read_csv(data_file, sep='\t') - rr = rrs[axis+1] + rr = rrs[axis-1] addition = 180 / 3.1415926 * 60 / 360 * rr elif data_file.endswith('.csv'): df = read_csv(data_file, sep=',', encoding='gbk', header=8) diff --git a/aio/code/durable_action/factory_test.py b/aio/code/durable_action/factory_test.py index f68036f..ebcf0e2 100644 --- a/aio/code/durable_action/factory_test.py +++ b/aio/code/durable_action/factory_test.py @@ -43,6 +43,8 @@ durable_data_velocity = { 'axis5': [0 for _ in range(25)], 'axis6': [0 for _ in range(25)], } +data_all = [durable_data_current, durable_data_velocity] + def traversal_files(path, w2t): if not exists(path): @@ -118,6 +120,7 @@ def execution(cmd, hr, w2t, **kwargs): def run_rl(path, config_file, hr, md, w2t): # 1. 关闭诊断曲线,触发软急停,并解除,目的是让可能正在运行着的机器停下来,切手动模式并下电 _response = execution('diagnosis.open', hr, w2t, open=False, display_open=False) + _response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=[]) md.trigger_estop() md.reset_estop() md.write_act(False) @@ -170,9 +173,7 @@ def run_rl(path, config_file, hr, md, w2t): _response = execution('rl_task.stop', hr, w2t, tasks=['current']) sleep(1) # 保证所有数据均已返回 # 7. 保留数据并处理输出 - data = get_durable_data(path, config_file, durable_data_current, scenario_time, hr, w2t) - df = pd.DataFrame(data) - df.to_excel(durable_data_current_xlsx, index=False) + get_durable_data(path, config_file, data_all, scenario_time, hr, w2t) # 8. 继续运行 _response = execution('rl_task.run', hr, w2t, tasks=['current']) @@ -185,9 +186,7 @@ def run_rl(path, config_file, hr, md, w2t): _response = execution('diagnosis.open', hr, w2t, open=False, display_open=False) _response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=[]) # 7. 保留数据并处理输出 - data = get_durable_data(path, config_file, durable_data_current, scenario_time, hr, w2t) - df = pd.DataFrame(data) - df.to_excel(durable_data_current_xlsx, index=False) + get_durable_data(path, config_file, data_all, scenario_time, hr, w2t) def get_durable_data(path, config_file, data, scenario_time, hr, w2t): @@ -218,19 +217,49 @@ def get_durable_data(path, config_file, data, scenario_time, hr, w2t): 'device_servo_trq_feedback_0': [], 'device_servo_trq_feedback_1': [], 'device_servo_trq_feedback_2': [], 'device_servo_trq_feedback_3': [], 'device_servo_trq_feedback_4': [], 'device_servo_trq_feedback_5': [], } + _d2d_vel = { + 'hw_joint_vel_feedback_0': [], 'hw_joint_vel_feedback_1': [], 'hw_joint_vel_feedback_2': [], + 'hw_joint_vel_feedback_3': [], 'hw_joint_vel_feedback_4': [], 'hw_joint_vel_feedback_5': [], + } for line in _data_list: for item in line['data']: for i in range(6): item['value'].reverse() if item.get('channel', None) == i and item.get('name', None) == 'device_servo_trq_feedback': _d2d_trq[f'device_servo_trq_feedback_{i}'].extend(item['value']) + elif item.get('channel', None) == i and item.get('name', None) == 'hw_joint_vel_feedback': + _d2d_vel[f'hw_joint_vel_feedback_{i}'].extend(item['value']) if len(_d2d_trq['device_servo_trq_feedback_0']) / 1000 > scenario_time + 1: _df = pd.DataFrame(_d2d_trq) for i in range(6): _ = sqrt(_df[f'device_servo_trq_feedback_{i}'].apply(lambda x: (rcs[i]*x/1000)**2).sum()/len(_df[f'device_servo_trq_feedback_{i}'])) - del data[f"axis{i + 1}"][0] - data[f"axis{i + 1}"].append(_) + del data[0][f"axis{i + 1}"][0] + data[0][f"axis{i + 1}"].append(_) + _df = pd.DataFrame(data[0]) + while True: + if not hr.durable_lock: + hr.durable_lock = 1 + _df.to_excel(durable_data_current_xlsx, index=False) + hr.durable_lock = 0 + break + else: + sleep(1) + + _df = pd.DataFrame(_d2d_vel) + for i in range(6): + _ = sqrt(_df[f'hw_joint_vel_feedback_{i}'].apply(lambda x: (rcs[i]*x/1000)**2).sum()/len(_df[f'hw_joint_vel_feedback_{i}'])) + del data[1][f"axis{i + 1}"][0] + data[1][f"axis{i + 1}"].append(_) + _df = pd.DataFrame(data[1]) + while True: + if not hr.durable_lock: + hr.durable_lock = 1 + _df.to_excel(durable_data_velocity_xlsx, index=False) + hr.durable_lock = 0 + break + else: + sleep(1) break else: with open(f'{path}\\device_servo_trq_feedback_0.txt', 'w', encoding='utf-8') as f_obj: @@ -238,8 +267,6 @@ def get_durable_data(path, config_file, data, scenario_time, hr, w2t): f_obj.write(f"{_}\n") w2t("采集的数据时间长度不够,需要确认。", 0, 2, 'red', tab_name) - return data - def main(path, hr, md, w2t): data_dirs, data_files = traversal_files(path, w2t) diff --git a/aio/code/openapi.py b/aio/code/openapi.py index 4ca716b..9da630e 100644 --- a/aio/code/openapi.py +++ b/aio/code/openapi.py @@ -1,4 +1,4 @@ -from json import load, dumps +from json import load, dumps, loads from socket import socket, setdefaulttimeout, AF_INET, SOCK_STREAM from threading import Thread import selectors @@ -171,6 +171,7 @@ class HmiRequest(object): self.half_length = 0 self.index = 0 self.reset_index = 0 + self.durable_lock = 0 self.sock_conn() self.t_heartbeat = Thread(target=self.heartbeat) @@ -257,8 +258,11 @@ class HmiRequest(object): # f.write(str(loads(msg)) + '\n') def msg_storage(self, response, flag=0): + # response是解码后的字符串 messages = self.c_msg if flag == 0 else self.c_msg_xs - if len(messages) < 20000: + if 'move.monitor' in response: + pass + elif len(messages) < 20000: messages.insert(0, response) else: messages.insert(0, response)