#112회 Lag Compensator 풀이
import control as ct
import numpy as np
import matplotlib.pyplot as plt
#transfer fucntion
num_G1 = [20]
den_G1 = [1, 21, 20]
sys_G1 = ct.tf(num_G1, den_G1)
sys_G1
#Sensor
num_H = [50]
den_H = [1, 5]
sys_H = ct.tf(num_H, den_H)
sys_H
# transfer fucntion
# sysTopenloop = sys_G1/(1+sys_G1*(sys_H-1))
sysTopenloop = ct.feedback(sys_G1,(sys_H-1))
sysTopenloop
sysT = ct.feedback(sys_G1,sys_H)
sysT
#total system
# sysTuc = sysT/(1+sysT)
sysTuc = ct.feedback(sysTopenloop,1)
sysTuc
time, response = ct.step_response(sysTuc)
plt.plot(time, response, label='Step Response')
plt.show()
s = ct.TransferFunction.s
G_s = sysTopenloop
E_s = 1 / (1 + G_s)
# Final Value Theorem to find steady-state error
sse_step = ct.evalfr(E_s, 0) # Evaluate E(s) at s=0
print(f"Steady-State Error for Step Input: {sse_step}")
Steady-State Error for Step Input: (0.9090909090909091+0j)
#Compensator
num_C = [1, 1.2]
den_C = [1, 0.1]
sys_C = ct.tf(num_C, den_C)
sys_C
# transfer fucntion compensator
# sysTc = sys_C* sysTuc/(1+sys_C* sysTuc)
sysTc = ct.feedback(sys_C* sysT, 1)
sysTc
sysTc_openloop = sys_C* sysT
sysTc_openloop
time_tc, response_tc = ct.step_response(sysTc)
plt.plot(time_tc, response_tc, label='Step Response')
plt.show()
s = ct.TransferFunction.s
# G_s = sysTc
G_s = sysTc_openloop
E_s = 1 / (1 + G_s)
# Final Value Theorem to find steady-state error
sse_step = ct.evalfr(E_s, 0) # Evaluate E(s) at s=0
print(f"Steady-State Error for Step Input: {sse_step}")
Steady-State Error for Step Input: (0.4782608695652174+0j)
# ess == 1%로 수정시 새로운 kp = 100
# z/p은 100배 차이
#Compensator
num_C = [1, 12.0]
den_C = [1, 0.1]
sys_C = ct.tf(num_C, den_C)
sysTc = ct.feedback(sys_C* sysT, 1)
sysTc_openloop = sys_C* sysT
time_tc, response_tc = ct.step_response(sysTc)
plt.plot(time_tc, response_tc, label='Step Response')
plt.show()
G_s = sysTc_openloop
E_s = 1 / (1 + G_s)
# Final Value Theorem to find steady-state error
sse_step = ct.evalfr(E_s, 0) # Evaluate E(s) at s=0
print(f"Steady-State Error for Step Input: {sse_step}")
Steady-State Error for Step Input: (0.08396946564885496+0j)