Einstieg in die Regelungstechnik mit Python

Fachbuch von Hans-Werner Philippsen

Kapitel 5

Nachfolgend sind Python-Programme aufgeführt, die einen PI-Regler mit der Sprungantwort sowie dem Bode-Diagramm beschreiben und die Sprungantwort eines PID-T1-Reglers zeigen


web501

PI-Regler

Listing 5.1: Sprungantwort und Bode-Diagramm PI-Regler

# -*- coding: utf-8 -*-
"""

PI-Regler H(t) und Bode
Created on 10.11. 2018
@author: philippsen
""" 

import numpy as np
import control
from control.matlab import *
import matplotlib.pyplot as plt

reg = tf([6.0, 2.0],[3, 0.0])
t = np.linspace(0, 6, 200)
e = np.ones(200)
e[0]=0.0
y, t, xx = lsim(reg,e,t)
plt.plot(t,y)
plt.title('PI-Regler')
plt.xlabel('t [s]'); plt.ylabel(' y')
plt.grid(b=True)
plt.figure()
bode(reg)

web502

PID-T1-Regler

Listing 5.2: Mit Python wird die Sprungantwort eines PID-T1-Reglers simuliert, wobei der D-Anteil ebenfalls geplottet wird.

# -*- coding: utf-8 -*-
"""

PI plus D-T1 Regler
Created on 15.4. 2019
@author: philippsen
"""

import numpy as np
import control
from   control.matlab import *
import matplotlib.pyplot as plt

Kp= 2.0    #  Reglerverstärkung
Tn = 1.5    # Nachstellzeit
Tv = 0.5    # Vorhaltzeit
VV = 5      #	Vorhaltverstärkung

Zpi  = np.array([Kp*Tn , Kp ])
Npi  = np.array([ Tn, 0])
Zdt1  = np.array([Kp*Tv , 0])
Ndt1  = np.array([Tv/VV , 1])
t = np.arange(0,5,0.05)
Gpi = tf(Zpi,Npi)
ypi, t = control.matlab.step(Gpi,t)

Gdt1 = tf(Zdt1,Ndt1)
ydt, tt = control.matlab.step(Gdt1,t)
fig, ax1 = plt.subplots()

ax1.plot(tt, ypi+ydt, "b") 
ax1.set_ylabel('Stellgröße', color="blue", fontsize=14) 
plt.grid()
ax2 = ax1.twinx() 
ax2.plot(tt, ydt, "r") 
ax2.set_ylabel('D-Anteil', color="red", fontsize=14) 
ax1.set_xlabel('t [s]', fontsize=12) 
ax1.set_title('PID-T1 - Regler', fontsize=12)


Theme von Anders Norén