# SetPointWeight



In [1]:

# Import needed modules
import sympy as sp
import numpy as numpy
from sympy import init_printing
init_printing()




In [2]:

# Define the symbols
# Needed variables for LaPlace Transformation and the Frequency
s = sp.symbols('s', positive = True)
omega = sp.symbols('omega', positive = True, real = True)
# Needed for the plant
K, T, L = sp.symbols('K T L', positive = True, real = True)
# Needed for PI Controller
kp, ki, ti, b = sp.symbols('K_p K_i T_i b', real= True)
# Define a FOTD
def FOTD(x,y,z):
return x/(y*s+1)*sp.exp(-z*s)
# Define a PI
def PI(x,y):
return b*x + y/s




In [3]:

# Define the plant and the controller
G = FOTD(K,T,L).subs(L,0)
C = PI(kp,ki)
# Define the sensitivity function
S = 1/(1+G*C)
# Define the complementary sensitivity function
CS = sp.simplify(G*C/(1+G*C))
# Define the open Loop
O = sp.simplify(G*C)




In [4]:

# Change to complex frequency
from sympy import I
CP_s = (O)
CP_s = sp.simplify(CP_s)
print('Open Loop Transfer Function')
CP_s




Open Loop Transfer Function

Out[4]:

$$\frac{K \left(K_{i} + K_{p} b s\right)}{s \left(T s + 1\right)}$$




In [5]:

# The Absolute value of the
CP_o = sp.Abs(CP_s.subs(s,I*omega))
# Get the roots
Roots = sp.solve(sp.Eq(CP_o-1,0),omega)
for i in range(0,len(Roots)-1):
Roots[i] = sp.simplify(Roots[i])
print('Roots of the characteristic Polynomial')
Roots




Roots of the characteristic Polynomial

Out[5]:

$$\left [ - \frac{1}{2 T} \sqrt{2 K^{2} K_{p}^{2} b^{2} - 2 \sqrt{K^{4} K_{p}^{4} b^{4} + 4 K^{2} K_{i}^{2} T^{2} - 2 K^{2} K_{p}^{2} b^{2} + 1} - 2}, \quad \frac{1}{2 T} \sqrt{2 K^{2} K_{p}^{2} b^{2} - 2 \sqrt{K^{4} K_{p}^{4} b^{4} + 4 K^{2} K_{i}^{2} T^{2} - 2 K^{2} K_{p}^{2} b^{2} + 1} - 2}, \quad - \frac{1}{2 T} \sqrt{2 K^{2} K_{p}^{2} b^{2} + 2 \sqrt{K^{4} K_{p}^{4} b^{4} + 4 K^{2} K_{i}^{2} T^{2} - 2 K^{2} K_{p}^{2} b^{2} + 1} - 2}, \quad \frac{\sqrt{2}}{2 T} \sqrt{K^{2} K_{p}^{2} b^{2} + \sqrt{K^{4} K_{p}^{4} b^{4} + 4 K^{2} K_{i}^{2} T^{2} - 2 K^{2} K_{p}^{2} b^{2} + 1} - 1}\right ]$$




In [35]:

# Assume a Relationship between kP and kI
alpha = sp.symbols('alpha')
RL = sp.Eq(ki , alpha*omega)
CP_R = CP_o.subs(omega,ki/alpha)
ki_sol = sp.solve(sp.Eq(CP_R-1,0),ki)
# Get kp
KP_EQ = sp.Eq(alpha**2*ki**2,K*kp*ki/T)
kp_sol = sp.solve(KP_EQ,kp)
print('Assume the following relationship')




Assume the following relationship




In [36]:

RL




Out[36]:

$$K_{i} = \alpha \omega$$




In [37]:

KP_EQ




Out[37]:

$$K_{i}^{2} \alpha^{2} = \frac{K_{i} K_{p}}{T} K$$




In [41]:

ki_sol, kp_sol




Out[41]:

$$\left ( \left [ - \frac{\alpha}{T} \sqrt{K^{2} K_{p}^{2} b^{2} + K^{2} \alpha^{2} - 1}, \quad \frac{\alpha}{T} \sqrt{K^{2} K_{p}^{2} b^{2} + K^{2} \alpha^{2} - 1}\right ], \quad \left [ \frac{K_{i} T}{K} \alpha^{2}\right ]\right )$$




In [39]:

EQ1 = sp.Eq(ki_sol[0].subs(kp,kp_sol[0]),ki)
EQ2 = sp.Eq(ki_sol[1].subs(kp,kp_sol[0]),ki)




In [40]:

EQ1,EQ2




Out[40]:

$$\left ( - \frac{\alpha}{T} \sqrt{K^{2} \alpha^{2} + K_{i}^{2} T^{2} \alpha^{4} b^{2} - 1} = K_{i}, \quad \frac{\alpha}{T} \sqrt{K^{2} \alpha^{2} + K_{i}^{2} T^{2} \alpha^{4} b^{2} - 1} = K_{i}\right )$$




In [42]:

SOL1 = sp.solve(EQ1,ki)[0]
SOL2 = sp.solve(EQ2,ki)[0]




In [43]:

SOL1




Out[43]:

$$\frac{\alpha}{T} \sqrt{\frac{- K^{2} \alpha^{2} + 1}{\alpha^{6} b^{2} - 1}}$$




In [44]:

SOL2




Out[44]:

$$- \frac{\alpha}{T} \sqrt{- \frac{K^{2} \alpha^{2} - 1}{\alpha^{6} b^{2} - 1}}$$




In [ ]: