[Control engineering] Visualization and analysis of PID control and step response

1.First of all

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.

2 References

2.1 Books

[1] Hiroki Minami, Ohmsha, "Introduction to Control Engineering with Python"

2.2 Web page

[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

3 Implementation details

3.1 Block diagram of PID control

ブロック線図.png 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.

3.2 Transfer function

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

------------

3.3 Step input / response

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.

step_input_response.png

4 Summary

・ 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

[Control engineering] Visualization and analysis of PID control and step response
Analysis of financial data by pandas and its visualization (2)
Analysis of financial data by pandas and its visualization (1)
The world of control engineering books
Clash of Clans and image analysis (3)
Aggregation and visualization of accumulated numbers
[Control engineering] Calculation of transfer functions and state space models by Python
Starbucks Twitter Data Location Visualization and Analysis
Correlation visualization of features and objective variables
Visualization of CNN feature maps and filters (Tensorflow 2.0)
I tried morphological analysis and vectorization of words
[Introduction to PID] I tried to control and play ♬