Compare commits
31 Commits
678357b838
...
feature_di
| Author | SHA1 | Date | |
|---|---|---|---|
| 5685eebe2c | |||
| f2ed9c9724 | |||
| db17fbc1d9 | |||
| 451cd9bc68 | |||
| f8d788d92e | |||
| b1ceb7c913 | |||
| ac2180b041 | |||
| 729bf18aec | |||
| 6013acc226 | |||
| 945e088667 | |||
| 8269b5112f | |||
| 582bdec6c5 | |||
| 74c7746142 | |||
| 1a1f228b69 | |||
| a099481b3e | |||
| ffce232d47 | |||
| 87d012086b | |||
| 7456e7f02a | |||
| 9dbe3e1f5d | |||
| c8d8118d98 | |||
| 4b093e86de | |||
| 083767f626 | |||
| b081c33748 | |||
| eae3d4bae1 | |||
| 5531952667 | |||
| 48d347fb06 | |||
| be2a4a8c24 | |||
| 8efc607e03 | |||
| 6e717027c6 | |||
| 8686a8ef19 | |||
| deb7f54bfb |
30
Beispiel Kennlinien/02_sprungantworten.txt
Normal file
30
Beispiel Kennlinien/02_sprungantworten.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
0;0
|
||||
4.9;0
|
||||
5;5
|
||||
9.9;5
|
||||
10;7
|
||||
14.9;7
|
||||
15;10
|
||||
19.9;10
|
||||
20;12
|
||||
24.9;12
|
||||
25;15
|
||||
29.9;15
|
||||
30;17
|
||||
34.9;17
|
||||
35;15
|
||||
39.9;15
|
||||
40;12
|
||||
44.9;12
|
||||
45;10
|
||||
49.9;10
|
||||
50;7
|
||||
54.9;7
|
||||
55;5
|
||||
59.9;5
|
||||
60;0
|
||||
69.9;0
|
||||
70;15
|
||||
79.9;15
|
||||
80;0
|
||||
90;0
|
||||
2
conf.txt
2
conf.txt
@@ -5,7 +5,7 @@
|
||||
}
|
||||
227C-024-15 PID_Regler 2{
|
||||
Kp:0.11
|
||||
Ki:0.08
|
||||
Ki:0.09
|
||||
Kd:0.00
|
||||
}
|
||||
227C-024-15 I-Regler{
|
||||
|
||||
83
main.py
83
main.py
@@ -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())
|
||||
@@ -50,8 +44,6 @@ class ArduinoGUI:
|
||||
self.load_configurations()
|
||||
|
||||
# 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.start()
|
||||
|
||||
@@ -169,6 +161,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 +246,38 @@ 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
|
||||
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):
|
||||
if self.arduino:
|
||||
@@ -411,20 +437,39 @@ class ArduinoGUI:
|
||||
|
||||
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 = ""
|
||||
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())
|
||||
if command[0] == 'w':
|
||||
self.tare_angle()
|
||||
if command[0] == 'u':
|
||||
outCommand = F"command: {command}\n"
|
||||
self.arduino.write(outCommand.encode())
|
||||
time.sleep(0.1)
|
||||
|
||||
self.ser.read()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
#self.ser.write(b'Hallo\n')
|
||||
else :
|
||||
try:
|
||||
pass
|
||||
self.connect_lsp()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
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):
|
||||
if self.selected_pid in self.pid_params:
|
||||
pid_values = self.pid_params[self.selected_pid]
|
||||
@@ -444,6 +489,8 @@ class ArduinoGUI:
|
||||
self.running = False
|
||||
if self.arduino:
|
||||
self.arduino.close()
|
||||
if self.ser:
|
||||
self.ser.close()
|
||||
self.root.quit()
|
||||
self.root.destroy()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user