import matplotlib.pyplot as plt class PIDRegler: def __init__(self, kp, ki, kd): self.kp = kp self.ki = ki self.kd = kd self.prev_error = 0 self.integral = 0 def regeln(self, setpoint, ist_temperatur): error = setpoint - ist_temperatur P = self.kp * error self.integral += error I = self.ki * self.integral D = self.kd * (error - self.prev_error) self.prev_error = error return P + I + D # Define the PID parameters kp = 0.5 ki = 0.005 kd = 0.1 # Create the PID regulator regler = PIDRegler(kp, ki, kd) # Define the setpoint setpoint = 22.0 # 22 degrees Celsius # Simulate the heating system ist_temperatur = 15.0 # Initial temperature temperature_over_time = [] for i in range(500): # Runtime: 200 time units regelung = regler.regeln(setpoint, ist_temperatur) ist_temperatur += regelung * 0.05 # Adjustment factor temperature_over_time.append(ist_temperatur) # Plot the temperature over time plt.plot(range(500), temperature_over_time) plt.xlabel('Time') plt.ylabel('Temperature (Celsius)') plt.title('Temperature Over Time') plt.grid(True) plt.show()