5.6. Time domain controller design#
5.6.1. Time domain PID controller design#
We can write a time function that describes a generic PID controller:
The Laplace transform of this equation (if we assume that \(y(0)=\dot y(0)=r(0)= \dot r(0)=0\)) is equal to
with \(k_p\) the propotional error gain, \(k_i\) the integrational error gain and \(k_d\) the differential error gain. This equation include an additional \(b_{sp}\) setpoint gain/weight that will be essential for this approach.
The figure shown below visualized the control loop include a first order system defined as
assuming that \(V_{sd}=0\) making \(v_m(t) =u(t)\) together with the PID controller with setpoint weighting \(b_{sp}\).
|
|---|
Fig.15 - PID control loop with set point weighting. |
The closed loop transfer function from R(s) to Y(s) can be found by substituting U(s) by
in equation \(\ref{eq:H(s)}\) leading to
After isolating the terms in R(s) and Y(s) we get
leading to the closed loop transfer function
If you want equation \(\ref{eq:CL}\) to fit the standard second order transfer function model
with \(\omega_n\) the natural frequency and \(\zeta\) the damping coefficient that can be directly relate to time conditions (\(t_s,t_p,t_r\), …) then we need to take \(k_d=0\) and \(b_sp=0\).
or
This lead to the following two conditions for \(k_i\) and \(k_p\) given desired values for \(\zeta\) and \(\omega_n\) (specifications) and a system defined by K and \(\tau\) (given in advance):
5.6.2. Time domain controller design in software#
To design a time domain controller in software we need to follow 5 steps:
Specify your transfer function
Determine \(\zeta\) and \(\omega_n\)
Determine K and \(\tau\) from the transfer function
Calculate the gains: \(k_i\) and \(k_p\) using equations \(\ref{eq:TD2},\ref{eq:TD3}\)
Simulate the closed loop response
Example: We have a first order transfer function \(H(s) =\frac{3}{0.2s+1}\) and we want to design a controller that has an overshoot of 3% and a rise time \(t_r\) of 0.8 seconds.
5.6.2.1. 1. We specify a transfer function:#
from control.matlab import tf,dcgain,pole,step,damp,stepinfo
import numpy as np
import matplotlib.pyplot as plt # Load the pyplot object fromthe matplotlib library
#from Mycode import response
sys = tf([3],[0.2,1])
print(sys)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from control.matlab import tf,dcgain,pole,step,damp,stepinfo
2 import numpy as np
3 import matplotlib.pyplot as plt # Load the pyplot object fromthe matplotlib library
ModuleNotFoundError: No module named 'control'
5.6.2.2. 2. We determine \(\zeta\) and \(\omega_n\) from time conditions#
Use the formulas derived in section 2.4 to determine the natural frequency (\(\omega_n\)) and damping ratio (\(\zeta\)) based on the given time domain criteria being \(M_p,t_r,t_s\) or \(T_p\).
To determine the damping ratio (\(\zeta\)) the previously derived equation:
can be rewritten as
To determine the natural frequency (\(\omega_n\)) the previously derived equation:
can be rewritten as
with \(\omega_d=\omega_n \sqrt{1- \zeta^2}\) this leads to an equation for \(\omega_n\)
#Overshoot
Mp=0.05
#Settling Time = ts
#ts=0.1
#Rise time = tr
tr=0.8
#Determine damping (z) and natural frequency (omega_n)
z = float(np.sqrt(-np.log(Mp)**2/(-np.log(Mp)**2-np.pi**2)))
#omega_n= 4/(ts*z)
omega_n = float((np.pi - np.arctan(np.sqrt(1-z**2)/z))/np.sqrt(1-z**2)/tr)
print("Damping ratio=",z)
print("Natural frequency=",omega_n)
Damping ratio= 0.6901067305598216
Natural frequency= 4.028617400280874
5.6.2.3. 3. Determine K and \(\tau\) from the transfer function#
The dcgain Python function is used to dertermine the gain at 0 Hz input (s=0) leading tot the calculation of K in the first order standard form \(C(s)=\frac{K}{\tau s+1}\).
The pole Python function is used to calculate the poles of a transfer function.
# Convert to standard form: k/(tau*s+1)
K= float(dcgain(sys))
tau = float(-1/pole(sys))
5.6.2.4. 4. Calculate the gains: \(k_i\) and \(k_p\) using equations \(\ref{eq:TD2},\ref{eq:TD3}\)#
#PI controller:
Ki=(omega_n**2*tau)/K
Kp=(2*z*omega_n*tau-1)/K
bsp=0
Kd=0
print("Ki is equal to %2.2f"%Ki)
print("Kp is equal to %2.2f"%Kp)
Ki is equal to 1.08
Kp is equal to 0.04
5. Simulate the closed loop response
CL =tf(K*Ki,[tau,K*Kp+1,K*Ki])
T = np.linspace(0,3,10000)
yout,T = step(CL,T)
wn,d,p= damp(CL)
plt.plot(T, yout, 'b', label='Step time response')
plt.grid()
plt.show() # show the plot
S=stepinfo(CL)
print("Percentage overshoot:%.2f" % S.get("Overshoot"),"%")
print("Rise time:%.2f" % S.get("RiseTime"), "sec.")
print("Settling time:%.2f" % S.get("SettlingTime"),"sec" )
_____Eigenvalue______ Damping___ Frequency_
-2.78 +2.916j 0.6901 4.029
-2.78 -2.916j 0.6901 4.029
Percentage overshoot:5.00 %
Rise time:0.53 sec.
Settling time:1.51 sec
The measured rise time (0.53 sec.) differs from the requested rise time (0.8 sec) because the requested rise time is measured between 0% and 100% while the stepinfo function returns the time between 10% and 90% (0.53 sec.).
