古典制御理論について考えます。
PI制御です。
PI制御
P制御とI制御を組み合わせます。
目標値に速く向かわせて、かつ定常偏差を消し去ることを狙っていると思います。
Let’s Python Simulator
超簡易シミュレーターを実装します。
pi_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] )
TARGET = 10
COLD = 1
input = 0
## q : FIFO queue depth
# q = int( argv[3] )
q = 10000
history = deque([])
counter = 0
for i in np.arange( 1, 2000, 1 ):
y.append(input)
diff = TARGET - input
## with a heater
if counter < q:
history.append( diff )
else:
history.append( diff )
history.popleft()
output = (diff * kp) + (sum( history ) * ki)
## 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('pi.png')
queueを使って、ある程度過去より前を捨てることが出来るような実装をしています。
本稿においては余計な実装です。
TARGET – inputが、よくあるr-yです。
rが目標値で、yがセンサーで読み取った現在値です。
outputが、よくあるuです。
使い方です。
> python3 pi_controller.py 0.3 0.4
Kp = 0.4 / Ki = 0.05
Kp = 0.5 / Ki = 0.05
Kp = 0.6 / Ki = 0.03
まとめ
定常偏差が消えた !!
何がおきているのか / What’s Going on
Let’s Python Simulator
完全にやっつけですが、超簡易シミュレーターを実装します。
pi_controller_2.py
import sys
from collections import deque
import numpy as np
import matplotlib.pyplot as pyplot
x = np.arange( 1, 2000, 1 )
y = []
y_p = []
y_i = []
argv = sys.argv
kp = float( argv[1] )
ki = float( argv[2] )
TARGET = 10
COLD = 1
input = 0
## q : FIFO queue depth
# q = int( argv[3] )
q = 10000
history = deque([])
counter = 0
for i in np.arange( 1, 2000, 1 ):
y.append(input)
diff = TARGET - input
## with a heater
if counter < q:
history.append( diff )
else:
history.append( diff )
history.popleft()
output = (diff * kp) + (sum( history ) * ki)
y_p.append(diff * kp)
y_i.append(sum( history ) * ki)
## It's cold outside.
input += output - COLD
counter += 1
pyplot.plot( x,y )
pyplot.plot( x,y_p )
pyplot.plot( x,y_i )
y = np.full( 1999, TARGET )
pyplot.plot( x,y, color='r' )
pyplot.xlabel("x")
pyplot.ylabel("y", rotation=0)
pyplot.xlim(0, 100)
pyplot.ylim(0, 20)
pyplot.savefig('pi.png')
Kp = 0.6 / Ki = 0.03
橙がP制御成分で、緑がI制御成分です。これらを足しこんでいくと、外気温も影響もありますが、青の線になります。
Kpがいい感じに大きくて、Kiがいい感じに小さいと、ぴたっとな感じで制御できるでしょう。
総まとめ
定常偏差が消えた !!
広告
IT開発関連書とビジネス書が豊富な翔泳社の通販『SEshop』
さくらのレンタルサーバ

ムームードメイン

Oisix(おいしっくす)

らでぃっしゅぼーや

珈琲きゃろっと

エプソムソルト
