301 古典制御

読み込み

In [1]:
from pylab import *
import control as matlab
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import warnings
warnings.filterwarnings("ignore")

パラメータ定義

In [2]:
TIME_MAX = 10 # min

V = 10
n = 10
K = 1000
K_1 = 100
a = 100
R_a = 8
J_a = 0.02
D_a = 0.01
K_b = 0.5
K_t = 0.5
N_1 = 25
N_2 = 250
N_3 = 250
J_K = 1
D_L = 1

K_pot = 0.318
K_m = 2.083
a_m = 1.71
K_g = 0.1

伝達関数定義

In [3]:
TF_Potentiometer = matlab.tf([K_pot],[1])
TF_Preamplifer = matlab.tf([K],[1])
#TF_PowerAmplifier = matlab.tf([K_1], [1, a])
TF_PowerAmplifier = matlab.tf([1], [1])
TF_Moter = matlab.tf([K_m], [1, a_m, 0])
TF_Gear = matlab.tf([K_g], [1])

sysPI = TF_Potentiometer * matlab.feedback(TF_Preamplifer*TF_PowerAmplifier*TF_Moter*TF_Gear, TF_Potentiometer)#If u can not make a closed loop tf, use it
print(sysPI)

        66.24
--------------------
s^2 + 1.71 s + 66.24

応答のグラフ化

In [4]:
yout, trange = matlab.step(sysPI, arange(0, TIME_MAX, 0.1))
plt.plot(trange, yout, 'r')

plt.xlim([-2,TIME_MAX])
plt.xlabel('Time')
plt.ylabel('Response p.u.')
plt.title('Controller behavior analysis')

plt.grid()
plt.show()
../_images/materials_301_Control_7_0.png

ナイキスト線図・ボード線図

In [5]:
a= matlab.nyquist(sysPI)
plt.title('Nyquist')
plt.show()

a=matlab.bode(sysPI)
plt.title('Bode')
plt.show()

a = matlab.pole(sysPI)

x = []
y = []
for tmp in a:
    x.append(tmp.real)
    y.append(tmp.imag)
plt.scatter(x, y, c="green", marker = "o", label='Plant model')

plt.xlabel("Real")
plt.ylabel("Imaginary")

art = []
lgd = plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
art.append(lgd)
plt.grid()
plt.title('Pole')
plt.show()

a=matlab.rlocus(sysPI)
plt.title('Rloucus')
plt.show()
../_images/materials_301_Control_9_0.png
../_images/materials_301_Control_9_1.png
../_images/materials_301_Control_9_2.png
../_images/materials_301_Control_9_3.png