Advertisement
SamirBaghirzada

Assignment 2 5.a

Apr 1st, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import control.matlab as cn
  4.  
  5. # PID parameters Kp, Ki, Kd
  6. Kp = 4.9
  7. Ki = 5.1
  8. Kd = 2.5
  9.  
  10. ##################################################################################
  11. Ts = 0.01
  12.  
  13. Tf = 15
  14. t = np.arange(0, Tf, Ts)
  15. sG = cn.tf([1,1,0], [1,2,3,2])
  16. controller = cn.tf([Kd, Kp, Ki], [1,0,0]) # GC is system in series with controller
  17. clsys = cn.feedback(cn.series(sG,controller),1) # GC/(1+GC) you can use this expression instead of cn.feedback()
  18. y, T = cn.step(clsys, t)
  19. info = cn.stepinfo(clsys,t)
  20. # Algorithms for computing Rise time, Settling time, Maximum Overshoot and steady state Error
  21. ess = 1-info["SteadyStateValue"]
  22. tr = info["RiseTime"]
  23. ts = info["SettlingTime"]
  24. mp = info["Overshoot"]/100
  25. tp = info["PeakTime"]
  26.  
  27. plt.plot(T,y, label=f'Steady state error: {np.absolute(ess):.2f}')
  28. plt.scatter(tp,1+mp,label=f'Peak time = {tp} sec and Maximum overshoot = {mp:.3f}')
  29. plt.scatter(ts,1,label=f'Settling time = {ts:.3f} sec')
  30. plt.scatter(tr,info["SettlingMin"],label=f'Rising time = {tr:.3f} sec')
  31. plt.plot(T, np.ones(T.size), "--", label = "Reference")
  32. plt.xlabel("t")
  33. plt.ylabel("c(t)")
  34. plt.tight_layout()
  35.  
  36. plt.legend()
  37. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement