Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import control.matlab as cn
- # PID parameters Kp, Ki, Kd
- Kp = 4.9
- Ki = 5.1
- Kd = 2.5
- ##################################################################################
- Ts = 0.01
- Tf = 15
- t = np.arange(0, Tf, Ts)
- sG = cn.tf([1,1,0], [1,2,3,2])
- controller = cn.tf([Kd, Kp, Ki], [1,0,0]) # GC is system in series with controller
- clsys = cn.feedback(cn.series(sG,controller),1) # GC/(1+GC) you can use this expression instead of cn.feedback()
- y, T = cn.step(clsys, t)
- info = cn.stepinfo(clsys,t)
- # Algorithms for computing Rise time, Settling time, Maximum Overshoot and steady state Error
- ess = 1-info["SteadyStateValue"]
- tr = info["RiseTime"]
- ts = info["SettlingTime"]
- mp = info["Overshoot"]/100
- tp = info["PeakTime"]
- plt.plot(T,y, label=f'Steady state error: {np.absolute(ess):.2f}')
- plt.scatter(tp,1+mp,label=f'Peak time = {tp} sec and Maximum overshoot = {mp:.3f}')
- plt.scatter(ts,1,label=f'Settling time = {ts:.3f} sec')
- plt.scatter(tr,info["SettlingMin"],label=f'Rising time = {tr:.3f} sec')
- plt.plot(T, np.ones(T.size), "--", label = "Reference")
- plt.xlabel("t")
- plt.ylabel("c(t)")
- plt.tight_layout()
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement