Compare commits

...

18 Commits

Author SHA1 Message Date
1a1f228b69 Merge pull request 'feature_lsp_com' (#8) from feature_lsp_com into main
Reviewed-on: https://gitea.msb24.duckdns.org/musabe24/t2000_gui/pulls/8
2024-07-18 12:26:57 +02:00
a099481b3e LSP Kommunikation optimiert 2024-07-18 11:51:09 +02:00
ffce232d47 optimierung 2024-07-18 10:38:33 +02:00
87d012086b optimierung 2024-07-18 10:36:56 +02:00
7456e7f02a optimierung 2024-07-18 10:32:00 +02:00
9dbe3e1f5d optimierung 2024-07-18 10:29:01 +02:00
c8d8118d98 optimierung 2024-07-18 10:26:26 +02:00
4b093e86de optimierung 2024-07-18 10:22:42 +02:00
083767f626 optimierung 2024-07-18 10:20:21 +02:00
b081c33748 optimierung 2024-07-18 10:19:24 +02:00
eae3d4bae1 optimierung 2024-07-18 10:15:42 +02:00
5531952667 optimierung 2024-07-18 10:13:42 +02:00
48d347fb06 optimierung 2024-07-18 10:12:05 +02:00
be2a4a8c24 optimierung 2024-07-18 10:08:53 +02:00
8efc607e03 optimierung 2024-07-18 10:07:29 +02:00
6e717027c6 optimierung 2024-07-18 10:06:11 +02:00
8686a8ef19 lsp kommunikation optimierung 2024-07-18 10:04:00 +02:00
deb7f54bfb LSP Kommunikation verbessert. 2024-07-18 09:56:56 +02:00
2 changed files with 76 additions and 2899 deletions

2889
Data.csv

File diff suppressed because it is too large Load Diff

86
main.py
View File

@@ -11,6 +11,7 @@ import threading
import time import time
import numpy as np import numpy as np
import csv import csv
import os
class ArduinoGUI: class ArduinoGUI:
def __init__(self, root): def __init__(self, root):
@@ -19,14 +20,7 @@ class ArduinoGUI:
self.root.title("PRG 342 GUI") self.root.title("PRG 342 GUI")
self.root.attributes('-fullscreen', True) # Setzt das Fenster in den Vollbildmodus self.root.attributes('-fullscreen', True) # Setzt das Fenster in den Vollbildmodus
self.ser = serial.Serial( self.ser = None
port='/dev/serial0',
baudrate=192000,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
self.arduino = None self.arduino = None
self.ports = list(serial.tools.list_ports.comports()) self.ports = list(serial.tools.list_ports.comports())
@@ -50,8 +44,6 @@ class ArduinoGUI:
self.load_configurations() self.load_configurations()
# Start the communication thread # Start the communication thread
self.lsp_communication_tread = threading.Thread(target=self.lsp_communication_loop)
self.lsp_communication_tread.start()
self.communication_thread = threading.Thread(target=self.communication_loop) self.communication_thread = threading.Thread(target=self.communication_loop)
self.communication_thread.start() self.communication_thread.start()
@@ -169,6 +161,8 @@ class ArduinoGUI:
self.current_angle = 0 self.current_angle = 0
self.current_torque = 0 self.current_torque = 0
self.analogInput = 0 self.analogInput = 0
self.currentSetpoint = 0
self.currentOutput = 0
self.angle_label_var = customtkinter.StringVar() self.angle_label_var = customtkinter.StringVar()
self.angle_label_var.set("Drehwinkel: 0") self.angle_label_var.set("Drehwinkel: 0")
@@ -252,6 +246,38 @@ class ArduinoGUI:
messagebox.showerror("Fehler", str(e)) messagebox.showerror("Fehler", str(e))
else: else:
messagebox.showwarning("Warnung", "Bitte einen COM-Port auswählen") messagebox.showwarning("Warnung", "Bitte einen COM-Port auswählen")
def connect_lsp(self):
try:
ports = serial.tools.list_ports.comports()
used_ports = [port.device for port in ports]
serPort = None
if os.name == 'nt':
for i in range(1, 257):
port = f'(COM{i}'
if (port not in used_ports) and (serPort == None):
serPort = port
pass
else:
for i in range(256):
port = f'/dev/ttyS{i}'
if (port not in used_ports) and (serPort == None):
serPort = port
pass
for i in range(256):
port = f'/dev/ttyUSB{i}'
if (port not in used_ports) and (serPort == None):
serPort = port
pass
if serPort != None:
self.ser = serial.Serial(serPort, 9600, timeout=1)
print(F"Slave Port bereit an {serPort}")
except Exception as e:
print(F"Fehler beim Öffnen des Slave Ports an {serPort}")
pass
def set_setpoint(self): def set_setpoint(self):
if self.arduino: if self.arduino:
@@ -411,20 +437,42 @@ class ArduinoGUI:
self.csv_writer.writerow([formatted_time, formatted_angle, formatted_setpoint, formatted_torque, formatted_output]) self.csv_writer.writerow([formatted_time, formatted_angle, formatted_setpoint, formatted_torque, formatted_output])
except Exception as e:
print(e)
if self.ser:
if self.ser.in_waiting:
try:
command = self.ser.read(1).decode(errors='ignore').strip()
print(command)
if command == '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':
self.tare_angle()
if command == 'u':
time.sleep(5)
string = self.ser.read_until(b"u")
outCommand = F"u{string}u\n"
self.arduino.write(outCommand.encode())
time.sleep(0.1)
self.ser.read_all()
except Exception as e:
print(e)
#self.ser.write(b'Hallo\n')
else :
try:
pass
self.connect_lsp()
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(0.1) time.sleep(0.1)
def lsp_communication_loop(self):
while self.running:
if self.ser:
if self.ser.in_waiting:
command = self.ser.readline
self.ser.write(command)
def send_pid_parameters(self): def send_pid_parameters(self):
if self.selected_pid in self.pid_params: if self.selected_pid in self.pid_params:
pid_values = self.pid_params[self.selected_pid] pid_values = self.pid_params[self.selected_pid]
@@ -444,6 +492,8 @@ class ArduinoGUI:
self.running = False self.running = False
if self.arduino: if self.arduino:
self.arduino.close() self.arduino.close()
if self.ser:
self.ser.close()
self.root.quit() self.root.quit()
self.root.destroy() self.root.destroy()