[modify] support single axis cycle data process

This commit is contained in:
2024-06-05 21:27:11 +08:00
parent 55514abc93
commit 97ba8ffc51
3 changed files with 300 additions and 85 deletions

View File

@ -24,17 +24,12 @@ class App(customtkinter.CTk):
# configure window
self.title("AIO - All in one automatic toolbox")
# self.iconbitmap('./icon.ico')
# screen_width = self.winfo_screenwidth()
# screen_height = self.winfo_screenheight()
# width = screen_width - 200
# height = screen_height - 200
# self.geometry(f"{width}x{height}+{100}+{100}")
self.geometry("1100x500+100+100")
self.geometry("1180x550+100+100")
self.protocol("WM_DELETE_WINDOW", self.func_end_call_back)
self.grid_rowconfigure(3, weight=1)
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9), weight=1)
self.minsize(1100, 500)
self.grid_rowconfigure(4, weight=1)
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1)
self.minsize(1180, 550)
# =====================================================================
# create frame sidebar(left)
@ -62,8 +57,8 @@ class App(customtkinter.CTk):
# =====================================================================
# create frame
self.frame_param = customtkinter.CTkFrame(self, height=240, corner_radius=10)
self.frame_param.grid(row=0, column=1, rowspan=3, columnspan=11, sticky='new', ipadx=20, ipady=10, padx=10, pady=(10, 5))
self.frame_param = customtkinter.CTkFrame(self, corner_radius=10)
self.frame_param.grid(row=0, column=1, rowspan=3, columnspan=13, sticky='new', ipadx=20, ipady=10, padx=10, pady=(10, 5))
# create main menu
self.menu_main = customtkinter.CTkOptionMenu(self.frame_param, values=["INIT", "brake", "current", "iso"], font=self.my_font, command=self.func_main_callback)
self.menu_main.grid(row=0, column=1, sticky='we', padx=(20, 10), pady=(10, 5))
@ -74,7 +69,7 @@ class App(customtkinter.CTk):
self.label_path = customtkinter.CTkLabel(self.frame_param, text="Path", font=self.my_font)
self.label_path.grid(row=0, column=2, sticky='e', pady=(10, 5))
self.entry_path = customtkinter.CTkEntry(self.frame_param, width=670, placeholder_text="数据文件夹路径", font=self.my_font)
self.entry_path.grid(row=0, column=3, columnspan=9, padx=(5, 10), pady=(10, 5), sticky='we')
self.entry_path.grid(row=0, column=3, columnspan=11, padx=(5, 10), pady=(10, 5), sticky='we')
self.entry_path.configure(state='disabled')
# create av related
self.label_av = customtkinter.CTkLabel(self.frame_param, text="AV", font=self.my_font)
@ -124,10 +119,52 @@ class App(customtkinter.CTk):
self.option_trq = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_trq.grid(row=2, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_trq.configure(state='disabled')
# create trqH related
self.label_trqh = customtkinter.CTkLabel(self.frame_param, text="TrqH", font=self.my_font)
self.label_trqh.grid(row=2, column=8, sticky='e', pady=(5, 5))
self.option_trqh = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_trqh.grid(row=2, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_trqh.configure(state='disabled')
# create STO related
self.label_sto = customtkinter.CTkLabel(self.frame_param, text="STO", font=self.my_font)
self.label_sto.grid(row=2, column=10, sticky='e', pady=(5, 5))
self.option_sto = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
self.option_sto.grid(row=2, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
self.option_sto.configure(state='disabled')
# create rc1
self.label_rc_1 = customtkinter.CTkLabel(self.frame_param, text="RC1", font=self.my_font)
self.label_rc_1.grid(row=3, column=2, sticky='e', pady=(5, 5))
self.entry_rc_1 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_1.grid(row=3, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rc_2 = customtkinter.CTkLabel(self.frame_param, text="RC2", font=self.my_font)
self.label_rc_2.grid(row=3, column=4, sticky='e', pady=(5, 5))
self.entry_rc_2 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_2.grid(row=3, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rc_3 = customtkinter.CTkLabel(self.frame_param, text="RC3", font=self.my_font)
self.label_rc_3.grid(row=3, column=6, sticky='e', pady=(5, 5))
self.entry_rc_3 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_3.grid(row=3, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rc_4 = customtkinter.CTkLabel(self.frame_param, text="RC4", font=self.my_font)
self.label_rc_4.grid(row=3, column=8, sticky='e', pady=(5, 5))
self.entry_rc_4 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_4.grid(row=3, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rc_5 = customtkinter.CTkLabel(self.frame_param, text="RC5", font=self.my_font)
self.label_rc_5.grid(row=3, column=10, sticky='e', pady=(5, 5))
self.entry_rc_5 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_5.grid(row=3, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
self.label_rc_6 = customtkinter.CTkLabel(self.frame_param, text="RC6", font=self.my_font)
self.label_rc_6.grid(row=3, column=12, sticky='e', pady=(5, 5))
self.entry_rc_6 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
self.entry_rc_6.grid(row=3, column=13, padx=(5, 10), pady=(5, 5), sticky='w')
# =====================================================================
# create textbox
self.textbox = customtkinter.CTkTextbox(self, height=640, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue")
self.textbox.grid(row=3, column=1, rowspan=5, columnspan=15, ipadx=10, ipady=10, padx=10, pady=(5, 10), sticky='nsew')
self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue")
self.textbox.grid(row=4, column=1, rowspan=3, columnspan=13, ipadx=10, ipady=10, padx=10, pady=(5, 10), sticky='nsew')
self.textbox.configure(state='disabled')
# =====================================================================
# version check
@ -157,6 +194,14 @@ class App(customtkinter.CTk):
self.label_axis.configure(text="AXIS", text_color="black")
self.label_vel.configure(text="Vel", text_color="black")
self.label_trq.configure(text="Trq", text_color="black")
self.label_trqh.configure(text="TrqH", text_color="black")
self.label_sto.configure(text="STO", text_color="black")
self.label_rc_1.configure(text="RC1", text_color="black")
self.label_rc_2.configure(text="RC2", text_color="black")
self.label_rc_3.configure(text="RC3", text_color="black")
self.label_rc_4.configure(text="RC4", text_color="black")
self.label_rc_5.configure(text="RC5", text_color="black")
self.label_rc_6.configure(text="RC6", text_color="black")
self.entry_path.configure(placeholder_text="数据文件夹路径", state="disabled")
self.entry_av.configure(placeholder_text="角速度", state="disabled")
@ -167,6 +212,14 @@ class App(customtkinter.CTk):
self.option_axis.configure(state="disabled")
self.option_vel.configure(state="disabled")
self.option_trq.configure(state="disabled")
self.option_trqh.configure(state="disabled")
self.option_sto.configure(state="disabled")
self.entry_rc_1.configure(placeholder_text="optional", state="disabled")
self.entry_rc_2.configure(placeholder_text="optional", state="disabled")
self.entry_rc_3.configure(placeholder_text="optional", state="disabled")
self.entry_rc_4.configure(placeholder_text="optional", state="disabled")
self.entry_rc_5.configure(placeholder_text="optional", state="disabled")
self.entry_rc_6.configure(placeholder_text="optional", state="disabled")
self.menu_sub.grid_forget()
self.textbox.delete(index1='1.0', index2='end')
@ -180,12 +233,12 @@ class App(customtkinter.CTk):
self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5))
self.menu_sub.set("--select--")
self.label_path.configure(text="*Path", text_color='red')
self.label_av.configure(text="*AV", text_color='red')
self.label_rr.configure(text="*RR", text_color='red')
self.label_axis.configure(text="*AXIS", text_color='red')
self.label_vel.configure(text="*Vel", text_color='red')
self.label_trq.configure(text="*Trq", text_color='red')
self.label_path.configure(text="Path", text_color='red')
self.label_av.configure(text="AV", text_color='red')
self.label_rr.configure(text="RR", text_color='red')
self.label_axis.configure(text="AXIS", text_color='red')
self.label_vel.configure(text="Vel", text_color='red')
self.label_trq.configure(text="Trq", text_color='red')
self.entry_path.configure(state="normal")
self.entry_av.configure(state="normal")
@ -199,22 +252,36 @@ class App(customtkinter.CTk):
self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5))
self.menu_sub.set("--select--")
self.label_path.configure(text="*Path", text_color='red')
self.label_rc.configure(text="*RC", text_color='red')
self.label_trq.configure(text="*Trq", text_color='red')
self.label_path.configure(text="Path", text_color='red')
self.label_rc.configure(text="RC", text_color='blue')
self.label_trqh.configure(text="TrqH", text_color='red')
self.label_rc_1.configure(text="RC1", text_color='red')
self.label_rc_2.configure(text="RC2", text_color='red')
self.label_rc_3.configure(text="RC3", text_color='red')
self.label_rc_4.configure(text="RC4", text_color='red')
self.label_rc_5.configure(text="RC5", text_color='red')
self.label_rc_6.configure(text="RC6", text_color='red')
self.entry_path.configure(state="normal")
self.entry_rc.configure(state="normal")
self.option_trq.configure(state="normal")
self.entry_rc.configure(state="normal", placeholder_text="optional")
self.option_trqh.configure(state="normal")
self.entry_rc_1.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_2.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_3.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_4.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_5.configure(state="normal", placeholder_text="额定电流")
self.entry_rc_6.configure(state="normal", placeholder_text="额定电流")
elif func_name == 'iso':
self.label_path.configure(text="*Path", text_color='red')
self.label_path.configure(text="Path", text_color='red')
self.entry_path.configure(state="normal")
else:
self.initialization()
self.menu_main.set("Start Here!")
def func_sub_callback(self, func_name):
if func_name == "industrial":
self.label_rpm.configure(text="*RPM", text_color='red')
self.label_rpm.configure(text="RPM", text_color='red')
self.entry_rpm.configure(state="normal")
elif func_name == "cobot":
self.label_rpm.configure(text="RPM", text_color='black')
@ -224,16 +291,22 @@ class App(customtkinter.CTk):
self.entry_dur.configure(state="disabled")
self.label_vel.configure(text="Vel", text_color='black')
self.option_vel.configure(state="disabled")
self.label_trq.configure(text="Trq", text_color='black')
self.option_trq.configure(state="disabled")
elif func_name == 'avg':
self.label_dur.configure(text="Dur", text_color='black')
self.entry_dur.configure(state="disabled")
self.label_vel.configure(text="Vel", text_color='black')
self.option_vel.configure(state="disabled")
self.label_trq.configure(text="Trq", text_color='black')
self.option_trq.configure(state="disabled")
elif func_name == 'cycle':
self.label_dur.configure(text="*Dur", text_color='red')
self.entry_dur.configure(state="normal")
self.label_vel.configure(text="*Vel", text_color='red')
self.label_dur.configure(text="Dur", text_color='blue')
self.entry_dur.configure(state="normal", placeholder_text='scenario')
self.label_vel.configure(text="Vel", text_color='red')
self.option_vel.configure(state="normal")
self.label_trq.configure(text="Trq", text_color='red')
self.option_trq.configure(state="normal")
def write2textbox(self, text, wait=0, exitcode=0):
@ -247,6 +320,7 @@ class App(customtkinter.CTk):
self.textbox.insert(index='end', text=text + '\n')
self.textbox.update()
self.textbox.see('end')
self.textbox.configure(state='disabled')
raise Exception(f"Error code: {exitcode}")
else:
self.textbox.configure(text_color='blue')
@ -254,6 +328,19 @@ class App(customtkinter.CTk):
self.textbox.update()
self.textbox.see('end')
def is_float(self, flag, *args):
for item in args:
try:
if flag == 'optional':
item = 0 if item == '' else item
_ = float(item)
elif flag == 'required':
_ = float(item)
except Exception as Err:
self.write2textbox(str(Err))
self.write2textbox("参数数据缺失,或者数据类型错误,更正后重新运行...", 0, 3)
return True
def check_param(self):
func_name = self.menu_main.get()
if func_name == 'brake':
@ -266,12 +353,7 @@ class App(customtkinter.CTk):
sub_func = self.menu_sub.get()
c1 = exists(path)
try:
_a = float(av)
_b = float(rr)
c2 = True
except:
c2 = False
c2 = self.is_float(av, rr)
c3 = rpm = 1
c4 = sub_func in ['industrial', 'cobot']
c5 = True if vel != trq else False
@ -295,35 +377,32 @@ class App(customtkinter.CTk):
dur = self.entry_dur.get()
vel = self.option_vel.get()
trq = self.option_trq.get()
trqh = self.option_trqh.get()
sub = self.menu_sub.get()
rc1 = self.entry_rc_1.get()
rc2 = self.entry_rc_2.get()
rc3 = self.entry_rc_3.get()
rc4 = self.entry_rc_4.get()
rc5 = self.entry_rc_5.get()
rc6 = self.entry_rc_6.get()
c1 = exists(path)
c2 = sub in ['max', 'avg', 'cycle']
c3 = self.is_float('optional', rc)
_ = [rc1, rc2, rc3, rc4, rc5, rc6]
c4 = self.is_float('required', *_)
rcs = rc.split()
for _ in rcs:
try:
_t = float(_)
except:
c3 = False
break
else:
c3 = True
c4 = c5 = True
c5 = c6 = True
if sub == 'cycle':
try:
_ = float(dur)
c4 = True
except:
c4 = False
c5 = True if vel != trq else False
c6 = self.is_float('optional', dur)
if c1 and c2 and c3 and c4 and c5:
if c1 and c2 and c3 and c4 and c5 and c6:
rcs = []
for x in rc.split():
for x in _:
rcs.append(float(x))
dur = 0 if sub != 'cycle' else dur
return 2, path, sub, rcs, int(vel), int(trq), float(dur)
dur = 0 if sub != 'cycle' or dur == '' else dur
return 2, path, sub, rcs, int(vel), int(trq), int(trqh), float(dur)
else:
return 0, 0
# =======================================================
@ -348,7 +427,7 @@ class App(customtkinter.CTk):
func_dict[flag](path=args[0], av=args[1], rr=args[2], rpm=args[3], axis=args[4], vel=args[5], trq=args[6], w2t=self.write2textbox)
elif flag == 2:
# tkinter.messagebox.showinfo(title="TBD", message="功能待实现......")
func_dict[flag](path=args[0], sub=args[1], rc=args[2], vel=args[3], trq=args[4], dur=args[5], w2t=self.write2textbox)
func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], w2t=self.write2textbox)
elif flag == 3:
func_dict[flag](path=args[0], w2t=self.write2textbox)
else:
@ -382,12 +461,8 @@ class App(customtkinter.CTk):
def func_end_call_back(self):
if tkinter.messagebox.askyesno(title="关闭程序", message="相关数据可能未保存,正在运行程序时有概率会损坏数据文件,确定要终止程序运行吗?"):
self.destroy()
else:
pass
pass
if __name__ == "__main__":
aio = App()
aio.mainloop()