In the previous article (https://qiita.com/sato235/items/5e006ebbf2949cf59463), it was recommended to visualize the step input and step response in the circuit with the controller, so I created this article. Eventually, I would like to use it for robot control system design.
[1] Hiroki Minami, Ohmsha, "Introduction to Control Engineering with Python"
[a] Control block diagram: https://tajimarobotics.com/pid-block-diagram-transfer-function/ [b] [Control Engineering] Graphing transfer functions by Python: https://qiita.com/sato235/items/5e006ebbf2949cf59463 [c] [Control engineering] Calculation of transfer function and state space model by Python: https://qiita.com/sato235/items/f991411074c578d1640c
Source: [a]
The above "C" corresponds to the controller. The above feedback control circuit is used as a transfer function to visualize step input / response.
initial value
K=1
Kd=1
Wn=1
Ki=1
ita=1
Kp=1
Create transfer function
C=matlab.tf([Kd, Kp, Ki],[1,0])
G=matlab.tf([K*Wn**2],[1,2*ita*Wn, Wn**2])
H=1
print("H")
print(H)
print("------------")
print("C")
print(C)
print("------------")
print("G")
print(G)
print("------------")
CG=matlab.series(C,G)
print("C*G")
print(CG)
print("------------")
CGH= matlab.feedback(CG,H,-1)
print("C*G/(1+C*G*H)")
print(CGH)
print("------------")
The output is as follows.
H
1
------------
C
s^2 + s + 1
-----------
s
------------
G
1
-------------
s^2 + 2 s + 1
------------
C*G
s^2 + s + 1
---------------
s^3 + 2 s^2 + s
------------
C*G/(1+C*G*H)
s^2 + s + 1
---------------------
s^3 + 3 s^2 + 2 s + 1
------------
Visualize the step input and response using the transfer function created above.
t = np.linspace(0, 3, 1000)
yout, T = matlab.step(P, t)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(T,yout, label="step response")
ax.plot(T,[1]*1000, linestyle="--", label="step input")
ax.set_xlabel("time[s]")
plt.legend(bbox_to_anchor=(1, 0.25), loc='upper right', borderaxespad=0, fontsize=11)
The figure is as follows.
・ It was possible to visualize the step response in the feedback circuit with the controller. ・ Next, I would like to consider the stability and compare the behavior when the coefficients of the C, G, and H functions are changed.
Recommended Posts