古典制御理論について考えます。
PID制御です。
P制御とI制御とD制御を組み合わせます。
Let’s Python Simulator
超簡易シミュレーターを実装します。
pid_controller.py
import sys
from collections import deque
import numpy as np
import matplotlib.pyplot as pyplot
x = np.arange( 1, 2000, 1 )
y = []
argv = sys.argv
kp = float( argv[1] )
ki = float( argv[2] )
kd = float( argv[3] )
TARGET = 10
COLD = 1
input = 0
## q : FIFO queue depth
# q = int( argv[3] )
q = 10000
# hist : history
hist = deque([])
# p : previous
p_diff = 0
# c : current
c_diff = 0
## delta t
dt = 1
counter = 0
for i in np.arange( 1, 2000, 1 ):
y.append(input)
diff = TARGET - input
c_diff = diff
## with a heater
if counter < q:
hist.append( diff )
else:
hist.append( diff )
hist.popleft()
output = (diff * kp) + (sum( hist ) * ki) + (((c_diff - p_diff) / dt) * kd)
p_diff = c_diff
## It's cold outside.
input += output - COLD
counter += 1
pyplot.plot( x,y )
y = np.full( 1999, TARGET )
pyplot.plot( x,y, color='r' )
pyplot.xlabel("x")
pyplot.ylabel("y", rotation=0)
pyplot.xlim(0, 200)
pyplot.ylim(0, 20)
pyplot.savefig('pid.png')
使い方です。
> python3.9 pid_controller.py 0.9 0.04 0.1
Kp = 0.9 / Ki = 0.04 / Kd = 0.1
Kp = 0.9 / Ki = 0.04 / Kd = 0
まとめ
例を部屋と暖房としていますが、やはりD制御とは合いません。
急に寒くなったり暑くなったりする環境の部屋には合うと思いますが、それをソースコードで再現させるくらいなら倒立振子をやります。
というわけで、暖房ならPI制御で十分と結論付けたいと思います。
PID制御だと、「急な温度変化にも対応できて安心 !!」かもしれません。
広告
IT開発関連書とビジネス書が豊富な翔泳社の通販『SEshop』
さくらのレンタルサーバ

ムームードメイン

Oisix(おいしっくす)

らでぃっしゅぼーや

珈琲きゃろっと

エプソムソルト
