feature_lsp_com #8

Merged
musabe24 merged 17 commits from feature_lsp_com into main 2024-07-18 12:26:59 +02:00
2 changed files with 61 additions and 2892 deletions
Showing only changes of commit deb7f54bfb - Show all commits

2889
Data.csv

File diff suppressed because it is too large Load Diff

64
main.py
View File

@@ -11,6 +11,7 @@ import threading
import time
import numpy as np
import csv
import os
class ArduinoGUI:
def __init__(self, root):
@@ -19,14 +20,7 @@ class ArduinoGUI:
self.root.title("PRG 342 GUI")
self.root.attributes('-fullscreen', True) # Setzt das Fenster in den Vollbildmodus
self.ser = serial.Serial(
port='/dev/serial0',
baudrate=192000,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
self.ser = None
self.arduino = None
self.ports = list(serial.tools.list_ports.comports())
@@ -169,6 +163,8 @@ class ArduinoGUI:
self.current_angle = 0
self.current_torque = 0
self.analogInput = 0
self.currentSetpoint = 0
self.currentOutput = 0
self.angle_label_var = customtkinter.StringVar()
self.angle_label_var.set("Drehwinkel: 0")
@@ -252,6 +248,35 @@ class ArduinoGUI:
messagebox.showerror("Fehler", str(e))
else:
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
else:
for i in range(256):
port = f'/dev/ttyS{i}'
if (port not in used_ports) and (serPort == None):
serPort = port
for i in range(256):
port = f'/dev/ttyUSB{i}'
if (port not in used_ports) and (serPort == None):
serPort = port
if serPort != None:
self.ser = serial.Serial(serPort, 19200, 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):
if self.arduino:
@@ -419,10 +444,25 @@ class ArduinoGUI:
def lsp_communication_loop(self):
while self.running:
if self.ser:
if self.ser:
if self.ser.in_waiting:
command = self.ser.readline
self.ser.write(command)
try:
command = self.ser.readline().decode(errors='ignore')
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
except Exception as e:
print(e)
#self.ser.write(b'Hallo\n')
else :
try:
pass
self.connect_lsp()
except Exception as e:
print(e)
def send_pid_parameters(self):
@@ -444,6 +484,8 @@ class ArduinoGUI:
self.running = False
if self.arduino:
self.arduino.close()
if self.ser:
self.ser.close()
self.root.quit()
self.root.destroy()