|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
import tkinter as tk
|
|
|
|
|
from tkinter import ttk, messagebox
|
|
|
|
|
from tkinter import ttk, messagebox, PhotoImage, simpledialog
|
|
|
|
|
import customtkinter
|
|
|
|
|
customtkinter.set_appearance_mode("light")
|
|
|
|
|
customtkinter.set_default_color_theme("blue")
|
|
|
|
|
@@ -12,6 +12,7 @@ import time
|
|
|
|
|
import numpy as np
|
|
|
|
|
import csv
|
|
|
|
|
import os
|
|
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
|
|
|
|
|
class ArduinoGUI:
|
|
|
|
|
def __init__(self, root):
|
|
|
|
|
@@ -81,75 +82,88 @@ class ArduinoGUI:
|
|
|
|
|
|
|
|
|
|
def create_widgets(self):
|
|
|
|
|
|
|
|
|
|
# Laden und Skalieren des Logos
|
|
|
|
|
original_image = Image.open("src/logo1.png")
|
|
|
|
|
resized_image = original_image.resize((500, 121), Image.LANCZOS) # Passen Sie die Größe (200, 100) nach Bedarf an
|
|
|
|
|
self.logo_image = ImageTk.PhotoImage(resized_image)
|
|
|
|
|
# Logo anstelle des Platzhalters
|
|
|
|
|
self.logo_label = customtkinter.CTkLabel(self.root, image=self.logo_image, text="")
|
|
|
|
|
self.logo_label.image = self.logo_image # Referenz behalten, um Garbage Collection zu verhindern
|
|
|
|
|
self.logo_label.grid(row=0, column=0, columnspan=3, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
# Placeholer
|
|
|
|
|
self.placeholer = customtkinter.CTkLabel(self.root, text="")
|
|
|
|
|
self.placeholer.grid(row=1, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
# Labels and ComboBox for Stellantriebstyp
|
|
|
|
|
self.stellantriebstyp_label = customtkinter.CTkLabel(self.root, text="Stellantriebstyp:", font=self.my_font)
|
|
|
|
|
self.stellantriebstyp_label.grid(row=0, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
self.stellantriebstyp_label.grid(row=3, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
self.config_combobox_value = customtkinter.StringVar()
|
|
|
|
|
self.config_combobox = customtkinter.CTkComboBox(self.root, variable=self.config_combobox_value, state="readonly", font=self.my_font)
|
|
|
|
|
self.config_combobox.grid(row=0, column=1, columnspan=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.config_combobox.grid(row=3, column=1, columnspan=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
#self.config_combobox.bind("<<ComboboxSelected>>", self.on_config_selected)
|
|
|
|
|
|
|
|
|
|
# Setzen Button für Stellantriebstyp
|
|
|
|
|
self.set_pid_button = customtkinter.CTkButton(self.root, text="Setzen", command=self.set_pid_parameters, font=self.my_font)
|
|
|
|
|
self.set_pid_button.grid(row=0, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.set_pid_button.grid(row=3, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
# Labels and ComboBox for COM Port
|
|
|
|
|
self.com_label = customtkinter.CTkLabel(self.root, text="COM Port:", font=self.my_font)
|
|
|
|
|
self.com_label.grid(row=1, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
self.com_label.grid(row=2, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
self.combobox_value = customtkinter.StringVar()
|
|
|
|
|
self.combobox = customtkinter.CTkComboBox(self.root, variable=self.combobox_value, font=self.my_font)
|
|
|
|
|
self.combobox.configure(values=[port.device for port in self.ports])
|
|
|
|
|
self.combobox.grid(row=1, column=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.combobox.grid(row=2, column=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
self.connect_button = customtkinter.CTkButton(self.root, text="Verbinden", command=self.connect_arduino, font=self.my_font)
|
|
|
|
|
self.connect_button.grid(row=1, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.connect_button.grid(row=2, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
# Setpoint entry
|
|
|
|
|
self.setpoint_label = customtkinter.CTkLabel(self.root, text="Sollwerteingabe in Nm:", font=self.my_font)
|
|
|
|
|
self.setpoint_label.grid(row=2, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
self.setpoint_label.grid(row=4, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
self.setpoint_entry = customtkinter.CTkEntry(self.root, font=self.my_font)
|
|
|
|
|
self.setpoint_entry.grid(row=2, column=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.setpoint_entry.grid(row=4, column=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
self.set_setpoint_button = customtkinter.CTkButton(self.root, text="Setzen", command=self.set_setpoint, font=self.my_font)
|
|
|
|
|
self.set_setpoint_button.grid(row=2, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.set_setpoint_button.grid(row=4, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
# Multi Setpoints Textbox and Button
|
|
|
|
|
self.multi_setpoints_label = customtkinter.CTkLabel(self.root, text="Sollwerteeingabe\n(Winkel;Drehmoment):", font=self.my_font)
|
|
|
|
|
self.multi_setpoints_label.grid(row=3, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
self.multi_setpoints_label.grid(row=5, column=0, padx=(10, 5), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
self.multi_setpoints_text = customtkinter.CTkTextbox(self.root, font=self.my_font)
|
|
|
|
|
self.multi_setpoints_text.grid(row=3, column=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.multi_setpoints_text.grid(row=5, column=1, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
self.send_multi_setpoints_button = customtkinter.CTkButton(self.root, text="Sollwerte senden", command=self.send_multi_setpoints, font=self.my_font)
|
|
|
|
|
self.send_multi_setpoints_button.grid(row=3, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
self.send_multi_setpoints_button.grid(row=5, column=2, padx=(0, 10), pady=(10, 0), sticky="ew")
|
|
|
|
|
|
|
|
|
|
# Analog Control CheckBox
|
|
|
|
|
self.checkbox_var = customtkinter.IntVar()
|
|
|
|
|
self.checkbox = customtkinter.CTkCheckBox(self.root, text="Analogsteuerung", variable=self.checkbox_var, command=self.input_source_Switch, font=self.my_font)
|
|
|
|
|
self.checkbox.grid(row=4, column=0, columnspan=3, padx=(10, 10), pady=(10, 0), sticky="w")
|
|
|
|
|
self.checkbox.grid(row=6, column=0, columnspan=3, padx=(10, 10), pady=(10, 0), sticky="w")
|
|
|
|
|
|
|
|
|
|
# Tare and Demagnetize Buttons
|
|
|
|
|
self.tare_button = customtkinter.CTkButton(self.root, text="Drehwinkel tarieren", command=self.tare_angle, font=self.my_font)
|
|
|
|
|
self.tare_button.grid(row=5, column=0, padx=(10, 5), pady=(10, 0), sticky="sew")
|
|
|
|
|
self.tare_button.grid(row=7, column=0, padx=(10, 5), pady=(10, 0), sticky="sew")
|
|
|
|
|
|
|
|
|
|
self.demag_button = customtkinter.CTkButton(self.root, text="Manuelle Entmagnetisierung", command=self.demagnetize, font=self.my_font)
|
|
|
|
|
self.demag_button.grid(row=5, column=1, padx=(0, 5), pady=(10, 0), sticky="sew")
|
|
|
|
|
self.demag_button.grid(row=7, column=1, padx=(0, 5), pady=(10, 0), sticky="sew")
|
|
|
|
|
|
|
|
|
|
# Exit Button
|
|
|
|
|
self.exit_button = customtkinter.CTkButton(self.root, text="Beenden", command=self.on_closing, font=self.my_font)
|
|
|
|
|
self.exit_button.grid(row=5, column=2, padx=(0, 10), pady=(10, 0), sticky="sew")
|
|
|
|
|
self.exit_button.grid(row=7, column=2, padx=(0, 10), pady=(10, 0), sticky="sew")
|
|
|
|
|
|
|
|
|
|
#Datalogger
|
|
|
|
|
self.datalogger_button = customtkinter.CTkButton(self.root, text="Datenlogger", command=self.toggle_datalogger, font=self.my_font)
|
|
|
|
|
self.datalogger_button.grid(row=4, column=0, padx=(0, 10), pady=(10, 0), sticky="sew")
|
|
|
|
|
self.datalogger_button.grid(row=6, column=2, padx=(0, 10), pady=(10, 0), sticky="sew")
|
|
|
|
|
|
|
|
|
|
# Plot
|
|
|
|
|
self.figure, self.ax = plt.subplots()
|
|
|
|
|
self.canvas = FigureCanvasTkAgg(self.figure, self.root)
|
|
|
|
|
self.canvas.get_tk_widget().grid(row=0, column=3, rowspan=6, columnspan=4, padx=(10, 10), pady=(10, 0), sticky="nsew")
|
|
|
|
|
self.canvas.get_tk_widget().grid(row=0, column=3, rowspan=8, columnspan=4, padx=(10, 10), pady=(10, 0), sticky="nsew")
|
|
|
|
|
|
|
|
|
|
self.ax.set_title("Drehmoment-Drehwinkel-Kennlinie")
|
|
|
|
|
self.ax.set_xlabel("Winkel (°)")
|
|
|
|
|
@@ -167,22 +181,22 @@ class ArduinoGUI:
|
|
|
|
|
self.angle_label_var = customtkinter.StringVar()
|
|
|
|
|
self.angle_label_var.set("Drehwinkel: 0")
|
|
|
|
|
self.angle_label = customtkinter.CTkLabel(self.root, textvariable=self.angle_label_var, font=self.my_font)
|
|
|
|
|
self.angle_label.grid(row=6, column=3, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
self.angle_label.grid(row=8, column=3, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
|
|
|
|
|
self.torque_label_var = customtkinter.StringVar()
|
|
|
|
|
self.torque_label_var.set("Istwert: 0")
|
|
|
|
|
self.torque_label = customtkinter.CTkLabel(self.root, textvariable=self.torque_label_var, font=self.my_font)
|
|
|
|
|
self.torque_label.grid(row=6, column=4, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
self.torque_label.grid(row=8, column=4, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
|
|
|
|
|
self.analogread_label_var = customtkinter.StringVar()
|
|
|
|
|
self.analogread_label_var.set("Analogeingang: 0")
|
|
|
|
|
self.analogread_label = customtkinter.CTkLabel(self.root, textvariable=self.analogread_label_var, font=self.my_font)
|
|
|
|
|
self.analogread_label.grid(row=6, column=5, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
self.analogread_label.grid(row=8, column=5, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
|
|
|
|
|
self.currentSetpoint_label_var = customtkinter.StringVar()
|
|
|
|
|
self.currentSetpoint_label_var.set("Aktueller Sollwert: 0")
|
|
|
|
|
self.currentSetpoint_label = customtkinter.CTkLabel(self.root, textvariable=self.currentSetpoint_label_var, font=self.my_font)
|
|
|
|
|
self.currentSetpoint_label.grid(row=6, column=6, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
self.currentSetpoint_label.grid(row=8, column=6, padx=(10, 5), pady=(10, 0), sticky="sw")
|
|
|
|
|
|
|
|
|
|
self.root.grid_columnconfigure(0, weight=0)
|
|
|
|
|
self.root.grid_columnconfigure(1, weight=0)
|
|
|
|
|
@@ -196,8 +210,11 @@ class ArduinoGUI:
|
|
|
|
|
self.root.grid_rowconfigure(2, weight=0)
|
|
|
|
|
self.root.grid_rowconfigure(3, weight=0)
|
|
|
|
|
self.root.grid_rowconfigure(4, weight=0)
|
|
|
|
|
self.root.grid_rowconfigure(5, weight=1)
|
|
|
|
|
self.root.grid_rowconfigure(5, weight=0)
|
|
|
|
|
self.root.grid_rowconfigure(6, weight=0)
|
|
|
|
|
self.root.grid_rowconfigure(7, weight=1)
|
|
|
|
|
self.root.grid_rowconfigure(8, weight=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_pid_parameters(self):
|
|
|
|
|
if self.arduino:
|
|
|
|
|
@@ -382,23 +399,28 @@ class ArduinoGUI:
|
|
|
|
|
if self.setpoint_flag:
|
|
|
|
|
self.arduino.write(f"s{self.setpoint:.0f},0\n".encode())
|
|
|
|
|
self.setpoint_flag = False
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
while self.arduino.out_waiting:
|
|
|
|
|
pass
|
|
|
|
|
if self.multi_setpoints_flag:
|
|
|
|
|
self.send_interpolated_points()
|
|
|
|
|
self.multi_setpoints_flag = False
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
while self.arduino.out_waiting:
|
|
|
|
|
pass
|
|
|
|
|
if self.tare_flag:
|
|
|
|
|
self.arduino.write(b'w\n')
|
|
|
|
|
self.tare_flag = False
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
while self.arduino.out_waiting:
|
|
|
|
|
pass
|
|
|
|
|
if self.demag_flag:
|
|
|
|
|
self.arduino.write(b'e\n')
|
|
|
|
|
self.demag_flag = False
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
while self.arduino.out_waiting:
|
|
|
|
|
pass
|
|
|
|
|
if self.input_source_flag:
|
|
|
|
|
self.arduino.write(b'S\n')
|
|
|
|
|
self.input_source_flag = False
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
while self.arduino.out_waiting:
|
|
|
|
|
pass
|
|
|
|
|
if self.pid_flag:
|
|
|
|
|
self.send_pid_parameters()
|
|
|
|
|
self.pid_flag = False
|
|
|
|
|
@@ -440,27 +462,27 @@ class ArduinoGUI:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
time.sleep(0.01)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.ser:
|
|
|
|
|
if self.ser.in_waiting:
|
|
|
|
|
try:
|
|
|
|
|
command = self.ser.read(1).decode(errors='ignore').strip()
|
|
|
|
|
print(command)
|
|
|
|
|
if command == 'a':
|
|
|
|
|
command = ""
|
|
|
|
|
while self.ser.in_waiting:
|
|
|
|
|
command += self.ser.read(1).decode(errors='ignore').strip()
|
|
|
|
|
if command[0] == 'a':
|
|
|
|
|
message = f"{self.current_angle};{self.current_torque};{self.analogInput};{self.currentSetpoint};{self.currentOutput}\n"
|
|
|
|
|
self.ser.write(message.encode())
|
|
|
|
|
while self.ser.out_waiting:
|
|
|
|
|
pass
|
|
|
|
|
if command == 'w':
|
|
|
|
|
if command[0] == 'w':
|
|
|
|
|
self.tare_angle()
|
|
|
|
|
if command == 'u':
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
string = self.ser.read_until(b"u")
|
|
|
|
|
outCommand = F"u{string}u\n"
|
|
|
|
|
if command[0] == 'u':
|
|
|
|
|
outCommand = F"{command}\n"
|
|
|
|
|
self.arduino.write(outCommand.encode())
|
|
|
|
|
print(self.arduino.readline())
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
self.ser.read_all()
|
|
|
|
|
|
|
|
|
|
self.ser.read()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
#self.ser.write(b'Hallo\n')
|
|
|
|
|
@@ -471,8 +493,6 @@ class ArduinoGUI:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
def send_pid_parameters(self):
|
|
|
|
|
if self.selected_pid in self.pid_params:
|
|
|
|
|
pid_values = self.pid_params[self.selected_pid]
|
|
|
|
|
@@ -489,13 +509,20 @@ class ArduinoGUI:
|
|
|
|
|
messagebox.showerror("Fehler", "Ausgewählte PID Konfiguration nicht gefunden.")
|
|
|
|
|
|
|
|
|
|
def on_closing(self):
|
|
|
|
|
self.running = False
|
|
|
|
|
if self.arduino:
|
|
|
|
|
self.arduino.close()
|
|
|
|
|
if self.ser:
|
|
|
|
|
self.ser.close()
|
|
|
|
|
self.root.quit()
|
|
|
|
|
self.root.destroy()
|
|
|
|
|
userInput = simpledialog.askstring("Masterpasswort eingeben", "Zum Ausführen dieses Befehls ist das Masterpasswort notwendig.\n")
|
|
|
|
|
if userInput == "976638":
|
|
|
|
|
self.running = False
|
|
|
|
|
if self.arduino:
|
|
|
|
|
self.arduino.close()
|
|
|
|
|
self.communication_thread = None
|
|
|
|
|
if self.ser:
|
|
|
|
|
self.ser.close()
|
|
|
|
|
self.root.quit()
|
|
|
|
|
self.root.destroy()
|
|
|
|
|
elif userInput == None:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
messagebox.showerror("Fehler", "Es wurde ein falsches Passwort eingegeben.")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
root = customtkinter.CTk()
|
|
|
|
|
|