Files
t2000_gui/main.py
2024-05-24 09:46:04 +02:00

140 lines
5.6 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")
self.root.geometry("1024x600")
self.root.attributes('-fullscreen', True) # Setzt das Fenster in den Vollbildmodus
self.root.overrideredirect(True) # Entfernt die Fensterdekorationen (wie Minimieren, Maximieren und Schließen)
# P- und I-Anteil Input Felder
tk.Label(self.root, text="P-Anteil:").place(x=10, y=10)
self.p_value = tk.DoubleVar()
tk.Entry(self.root, textvariable=self.p_value).place(x=100, y=10)
tk.Label(self.root, text="I-Anteil:").place(x=10, y=50)
self.i_value = tk.DoubleVar()
tk.Entry(self.root, textvariable=self.i_value).place(x=100, y=50)
# Eingabefelder für Koordinaten der Drehmoment-Drehwinkel-Kennlinie
tk.Label(self.root, text="Koordinaten der Drehmoment-Drehwinkel-Kennlinie:").place(x=10, y=90)
self.coordinates_text = tk.Text(self.root, height=5, width=20)
self.coordinates_text.place(x=20, y=110)
self.coordinates_text.insert('end', '0,0\n5,15\n10,10\n90,10')
# Eingabefeld für direkte Drehmomentvorgabe
tk.Label(self.root, text="Soll-Drehmoment in Nm:").place(x=10, y=220)
self.set_torque_value = tk.DoubleVar()
self.torque_input = tk.Entry(self.root, textvariable=self.set_torque_value)
self.torque_input.place(x=200, y=220)
# Anzeige für aktuellen Drehwinkel und Drehmoment
tk.Label(self.root, text="Aktueller Drehwinkel:").place(x=10, y=260)
self.current_angle = tk.Label(self.root, text="0" + " °")
self.current_angle.place(x=200, y=260)
tk.Label(self.root, text="Aktuelles Drehmoment:").place(x=10, y=300)
self.current_torque = tk.Label(self.root, text="0" + " Nm")
self.current_torque.place(x=200, y=300)
# Button zum Schließen der Anwendung
self.close_button = tk.Button(self.root, text="Beenden", command=self.close_application)
self.close_button.place(x=300, y=560)
# Button zur Übernahme der Eingaben und Aktualisierung des Diagramms
self.plot_button = tk.Button(self.root, text="Eingaben übernehmen", command=self.on_plot_button_click)
self.plot_button.place(x=10, y=560)
# 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(self.root, text="Direkte Drehmomentvorgabe aktivieren", variable=self.torque_mode, command=self.toggle_torque_mode)
self.torque_switch.place(x=10, y=340)
# Diagramm
self.figure = Figure(figsize=(6,6), dpi=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, self.root)
self.canvas.get_tk_widget().place(x=424, y=0)
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()