Python Control Systems Libraryを用いて、Pythonによる制御設計の基本コードを記述しています。
Pythonで下記の様なグラフを作成しましょう
main.py
#!usr/bin/env python
# Chap4 main function
import Chapter.Chap4.TFmodel.functions as TFfunc
def main():
TFfunc.TranceformModel_delay_T()
if __name__ == '__main__':
main()
functions.py
from control.matlab import step, tf
import matplotlib.pyplot as plt
import numpy as np
import Chapter.Chap4.Plot.plot as ppt
# 1次遅れ系のステップ応答(標準モデル)
def TranceformModel():
T, K = 0.5, 1 # 時定数とゲインの設定
P = tf([0, K], [T, 1]) # 1次遅れ系の伝達関数
y, t = step(P, np.arange(0, 5, 0.01)) # ステップ応答(戻り値の順番に注意)
ppt.showPlot(y, t)
# 1次遅れ系のステップ応答(時定数Tを変化させる)
def TranceformModel_delay_T():
LS = ppt.linestyle_generator()
fig, ax = plt.subplots()
K = 1
T = [1, 0.5, 0.1]
for i in range(len(T)):
y, t = step(tf([0, K], [T[i], 1]), np.arange(0, 5, 0.01))
ax.plot(t, y, ls=next(LS), label=f'T={T[i]}')
ppt.plot_set(ax, 't', 'y', 'best')
plt.show()
Comments are closed