Code: Alles auswählen
class PID_Controller:
def __init__(self):
self.Kp = 0.0
self.Ki = 0.0
self.Kd = 0.0
self.Setpoint = 0.0
self.Fehler = 0.0
self.PID_Val = 0.0
self.Val_Max = 0.0
self.Val_Min = 0.0
self.P_Anteil = 0.0
self.I_Anteil = 0.0
self.D_Anteil = 0.0
self.Integrator = 0.0
self.Differenzierer = 0.0
self.Integrator_Max = 100.0
self.Integrator_Min = -100.0
def Set_Parameters(self, P, I, D, Setpoint, PID_Max, PID_Min):
self.Kp = P
self.Ki = I
self.Kd = D
self.Setpoint = Setpoint
self.Val_Max = PID_Max
self.Val_Min = PID_Min
def Compute(self, Meassurement):
self.Fehler = self.Setpoint - Meassurement
self.P_Anteil = self.Kp * self.Fehler
self.D_Anteil = self.Kd * (self.Fehler - self.Differenzierer)
self.Differenzierer = self.Fehler
self.Integrator = self.Integrator + self.Fehler
if self.Integrator > self.Integrator_Max:
self.Integrator = self.Integrator_Max
elif self.Integrator < self.Integrator_Min:
self.Integrator = self.Integrator_Min
self.I_Anteil = self.Ki * self.Integrator
self.PID_Val = self.P_Anteil + self.I_Anteil + self.D_Anteil
if self.PID_Val > self.Val_Max:
self.PID_Val = self.Val_Max
elif self.PID_Val < self.Val_Min:
self.PID_Val = self.Val_Min
return self.PID_Val
P = 5.88
I = 0.08647
D = 99.96
Sollwert = 110.0
DC_Max = 10.0
DC_Min = 4.0
Messwert = 0.0
PID_Controller.Set_Parameters(P=P, I=I, D=D, Setpoint=Sollwert, PID_Max=DC_Max, PID_Min=DC_Min)
DutyCycle = PID.Compute(Messwert)
Habe mir einen PID-Regler geschrieben.
Die Funktion Set_Parameter stellt den Regler ein.
Die Funktion Compute Soll den Reglerwert berechnen.
Nun ist es aber so, dass meine Entwicklungsumgebung mir beim Aufruf der Funktionen Fehler gibt.
PID_Controller.Set_Parameters(P=P, I=I, D=D, Setpoint=Sollwert, PID_Max=DC_Max, PID_Min=DC_Min):
"This inspection reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments (e.g. duplicate named arguments) and incorrect argument order. Decorators are analyzed, too."
DutyCycle = PID.Compute(Messwert):
"Expected type 'PID_Controller', got 'float' instead less... (⌘F1)
This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations."
Könnt ihr mir sagen woran das liegt?
Bin der Meinung es passt so.