146 lines
6.2 KiB
Python
146 lines
6.2 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
import matplotlib.pyplot as plt
|
|
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
|
from matplotlib.figure import Figure
|
|
#import random
|
|
|
|
p = 0.0
|
|
i = 0.0
|
|
|
|
set_torque = 0.0
|
|
|
|
act_torque = 0.0
|
|
act_angle = 0.0
|
|
|
|
class T2000ErdemGUI:
|
|
def __init__(self, root):
|
|
self.root = root
|
|
self.root.title("T2000 Erdem")
|
|
|
|
menu_frame = tk.Frame(self.root)
|
|
menu_frame.grid(row=0, column=0, rowspan=8, columnspan=2, sticky="NESW", padx=10, pady=10)
|
|
menu_frame.columnconfigure(0, weight=1)
|
|
menu_frame.rowconfigure(6, weight=1)
|
|
|
|
plot_frame = tk.Frame(self.root)
|
|
plot_frame.grid(row=0, column=2, rowspan=8, sticky="NW")
|
|
|
|
plot_frame.rowconfigure(0, weight=1)
|
|
plot_frame.columnconfigure(0, weight=1)
|
|
|
|
self.root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
|
|
self.root.attributes('-fullscreen', True) # Setzt das Fenster in den Vollbildmodus
|
|
#self.root.overrideredirect(True) # Entfernt die Fensterdekorationen (wie Minimieren, Maximieren und Schließen)
|
|
|
|
# Eingabefelder für Koordinaten der Drehmoment-Drehwinkel-Kennlinie
|
|
tk.Label(menu_frame, text="Koordinaten der Drehmoment-Drehwinkel-Kennlinie:").grid(row=0, column=0, columnspan=2, pady=10, sticky="N")
|
|
self.coordinates_text = tk.Text(menu_frame, height=10, width=20)
|
|
self.coordinates_text.grid(row=1, column=0, columnspan=2, pady=10)
|
|
self.coordinates_text.insert('end', '0,0\n5,15\n10,10\n90,10')
|
|
|
|
# Eingabefeld für direkte Drehmomentvorgabe
|
|
tk.Label(menu_frame, text="Soll-Drehmoment in Nm:").grid(row=2, column=0, pady=10, sticky="NW")
|
|
self.set_torque_value = tk.DoubleVar()
|
|
self.torque_input = tk.Entry(menu_frame, textvariable=self.set_torque_value)
|
|
self.torque_input.grid(row=2, column=1, sticky="NW", pady=10)
|
|
|
|
# Anzeige für aktuellen Drehwinkel und Drehmoment
|
|
tk.Label(menu_frame, text="Aktueller Drehwinkel:").grid(row=3, column=0, pady=10, sticky="NW")
|
|
self.current_angle = tk.Label(menu_frame, text="0" + " °")
|
|
self.current_angle.grid(row=3, column=1, sticky="NW", pady=10)
|
|
|
|
tk.Label(menu_frame, text="Aktuelles Drehmoment:").grid(row=4, column=0, pady=10, sticky="NW")
|
|
self.current_torque = tk.Label(menu_frame, text="0" + " Nm")
|
|
self.current_torque.grid(row=4, column=1, sticky="NW", pady=10)
|
|
|
|
# Button zum Schließen der Anwendung
|
|
self.close_button = tk.Button(menu_frame, text="Beenden", command=self.close_application)
|
|
self.close_button.grid(row=7, column=1, pady=10, sticky="S")
|
|
|
|
# Button zur Übernahme der Eingaben und Aktualisierung des Diagramms
|
|
self.plot_button = tk.Button(menu_frame, text="Eingaben übernehmen", command=self.on_plot_button_click)
|
|
self.plot_button.grid(row=7, column=0, pady=10, sticky="S")
|
|
|
|
# Schalter für Umschaltung zwischen Drehmomentprofil und direkter Vorgabe
|
|
self.torque_mode = tk.BooleanVar()
|
|
self.torque_mode.set(False) # Startet im Modus "Drehmomentprofil"
|
|
self.torque_switch = tk.Checkbutton(menu_frame, text="Direkte Drehmomentvorgabe aktivieren", variable=self.torque_mode, command=self.toggle_torque_mode)
|
|
self.torque_switch.grid(row=5, column=0, columnspan=2, pady=10)
|
|
|
|
# Diagramm
|
|
self.figure = Figure(dpi=100)#(figsize=(6,6), dpi=100)
|
|
self.figure.set_figheight(self.root.winfo_screenheight()/100)
|
|
self.figure.set_figwidth((self.root.winfo_screenwidth()-380)/100)
|
|
self.plot = self.figure.add_subplot(111)
|
|
self.plot.set_xlim(0, 90)
|
|
self.plot.set_ylim(ymin=0)
|
|
self.plot.set_xlabel('Drehwinkel in Grad')
|
|
self.plot.set_ylabel('Drehmoment in Nm')
|
|
self.canvas = FigureCanvasTkAgg(self.figure, plot_frame)
|
|
#self.canvas.get_tk_widget().grid(row=0, column=0)
|
|
self.canvas.get_tk_widget().pack(fill="both", expand=True)
|
|
|
|
self.toggle_torque_mode()
|
|
self.create_diagram()
|
|
self.update_current_values_periodically()
|
|
|
|
def close_application(self):
|
|
#if messagebox.askokcancel("Beenden", "Möchten Sie die Anwendung wirklich beenden?"):
|
|
self.root.quit()
|
|
|
|
def create_diagram(self):
|
|
self.plot.clear()
|
|
self.plot.set_xlim(0, 90)
|
|
self.plot.set_xlabel('Drehwinkel in Grad')
|
|
self.plot.set_ylabel('Drehmoment in Nm')
|
|
|
|
coordinates = self.coordinates_text.get("1.0", tk.END).strip().split("\n")
|
|
x_coords, y_coords = [], []
|
|
for coord in coordinates:
|
|
x, y = map(float, coord.split(','))
|
|
x_coords.append(x)
|
|
y_coords.append(y)
|
|
|
|
self.plot.plot(x_coords, y_coords, marker='o', linestyle='-')
|
|
self.plot.set_ylim(bottom=0)
|
|
self.canvas.draw()
|
|
|
|
def update_current_values(self, angle, act_torque):
|
|
self.current_angle.config(text=str(angle) + " °")
|
|
self.current_torque.config(text=str(act_torque) + " Nm")
|
|
|
|
def save_set_values(self):
|
|
p = self.p_value.get()
|
|
i = self.i_value.get()
|
|
|
|
def toggle_torque_mode(self):
|
|
# Aktivieren oder Deaktivieren des direkten Drehmoment-Eingabefeldes
|
|
if self.torque_mode.get():
|
|
self.torque_input['state'] = 'normal'
|
|
self.coordinates_text['state'] = 'disabled'
|
|
else:
|
|
self.torque_input['state'] = 'disabled'
|
|
self.coordinates_text['state'] = 'normal'
|
|
|
|
def on_plot_button_click(self):
|
|
if self.torque_mode.get():
|
|
# Logik für die direkte Vorgabe des Soll-Drehmoments
|
|
set_torque = self.set_torque_value.get()
|
|
else:
|
|
# Logik für das Drehmomentprofil
|
|
self.create_diagram()
|
|
self.save_set_values()
|
|
|
|
def update_current_values_periodically(self):
|
|
# Simulieren von veränderlichen aktuellen Werten (als Beispiel)
|
|
#new_angle = random.randint(0, 90)
|
|
#new_torque = random.uniform(0, 50)
|
|
#self.update_current_values(new_angle, new_torque)
|
|
self.update_current_values(act_angle, act_torque)
|
|
self.root.after(200, self.update_current_values_periodically)
|
|
|
|
# Anwendung starten
|
|
root = tk.Tk()
|
|
app = T2000ErdemGUI(root)
|
|
root.mainloop() |