PID Tuning/ja

From RepRap
Jump to: navigation, search

PID チューニングとは、ほとんどのRepRapのホットエンドやヒートベッドにおいて使用される、比例(Proportional)・積分(Integral)・微分(Derivative) 制御アルゴリズムの調整を行うことを指しています。

PIDでは、ノズルやヒートベッドの温度を制御するために、P,I,D の値が定義されている必要があります。加熱時に温度が一旦急上昇してからターゲット温度に向けてゆっくりと下がっていく場合や、ターゲット温度の前後で温度が振れている場合には、これらの値は適切に設定されていないと言えます。

Marlinやその他ファームウェアで、 PID 自動チューニング を利用するには、ノズルが冷えている際に、以下の Gコードを送信します。

 M303 E0 S200 C8

このコマンドでは、まずノズルを加熱し (E0)、与えられたターゲット温度 (S200) を 8回 (C8) 前後し、そして P, I, D それぞれの値を返します。例として、http://www.soliwiki.com/PID_tuning では、以下のように表示されています。

bias: 92 d: 92 min: 196.56 max: 203.75
Ku: 32.59 Tu: 54.92
Clasic PID
Kp: 19.56
Ki: 0.71
Kd: 134.26
PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h
//訳: PID自動チューニングが完了しました! 定数 Kp, Ki, Kd を configuration.h ファイルに保存してください。

Marlinでは、これらの値はそれぞれのヒーター部品の制御式における、ソフトPWM電力制御のカウント数値 (0 から PID_MAX) を表しています。ソフトPWMの値は、関連するヒーターの制御信号のデューティサイクルを制限します。これは f=(FCPU/16/64/256/2)で表されます。 The proportional (P) constant Kp is in counts/C, representing the change in the softPWM output per each degree of error. The integral (I) constant Ki in counts/(C*s) represents the change per each unit of time-integrated error. The derivative (D) constant Kd in counts/(C/s) represents the change in output expected due to the current rate of change of the temperature. In the above example, the autotune routine has determined that to control for a temperature of 200C, the soft PWM should be biased to 92 + 19.56*error + 0.71 * (sum of errors*time) -134.26 * dError/dT. The 'sum of errors*time' value is limited to the range +/-PID_INTEGRAL_DRIVE_MAX as set in Configuration.h. Commercial PID controllers typically use time-based parameters, Ti=Kp/Ki and Td=Kd/Kp, to specify the integral and derivative parameters. In the example above: Ti=19.56/0.71=27.54s, meaning an adjustment to compensate for integrated error over about 28 seconds; Td=134.26/19.56=6.86s, meaning an adjustment to compensate for the projected temperature about 7 seconds in the future.

Kp, Ki, Kd の値はそれぞれ以下のように入力します。

 M301 P19.56 I0.71 D134.26 

複数のエクストルーダーが使われている場合 (E0, E1, E2)、それぞれのエクストルーダーが別々に制御されるとしても、これらのPIDの値は全てのエクストルーダーで共有されます。EEPROMが有効になっているのであれば、M500コマンドを使って保存しましょう。無効化されているようであれば、configuration.h ファイルにこれらの設定を保存しましょう。

ヒートベッドには、以下のコマンドを使用します。

 Bed: M303 E-1 S60 C8 

そして、以下のコマンドでヒートベッドの設定を保存します。

 M304 P1 I2 D3 

手動調整のコツ:

  • オーバーシュート (目標値を通り過ぎて変化しすぎてしまうこと) が多く見られる場合や、発振が見られる場合には、積分ゲインを増やすか、全てのゲインを減らすかのどちらかを行う必要があります。
  • オーバーシュートの幅が大きいですか? Dを増やし、Pを減らしましょう。
  • レスポンスが悪くなりすぎましたか? Pを増やしましょう。
  • ターゲット温度の下まではすぐに加熱するのに (0-160℃まで早い)、ターゲット温度に近づくにつれ、遅くなりすぎていますか? (160-170℃で遅く、170-180℃で異常に遅いなど) I 定数を増やしてみましょう。


Marlin のオートチューニング機能 (2014-01-20, https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/temperature.cpp#L250) では、ジーグラ・ニコルス法のうち、'Classic' 法と呼ばれる方法を用いています。この方法では、設定値の近くで最も振動するゲインを探し出し、得られる振幅と振動周期から、比例・積分・微分定数を算出します。Wikipedia の PID制御 や、ジーグラ・ニコルス法 もご参照ください。

PID設定の保存

変更したPIDの値を固定するには、EEPROMに書き込むか、configuration.h ファイルを書き換える必要があります。

EEPROM に保存するには、以下のコマンドを使用してください。

M500


Marlinオートチューニングパラメータの変更

デフォルトの Marlin M303 コマンドでは、ジーグラ・ニコルス法 の "Classic" 法によってパラメータを計算します。これらのパラメータは、Ku (最大ゲイン) と Pu (最大周期) によって計算されます。この Ku と Puは、目標値を中心とする平均出力レベルの周りにて、オンオフ制御をわざと偏らせ、振動を発生させることで探し出されます。(参照: https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/temperature.cpp#L238)

    Kp_classic=Ku*0.6
    Ki_classic=2*Kp_classic/Tu
    Kd_classic=Kp_classic*Tu/8
 

"Classic" のパラメータは、ジーグラ・ニコルス法の "Some Overshoot" のパラメータには、以下のように計算することで変換できます。

    Kp=Kp_classic*0.55
    Ki=Ki_classic
    Kd=Kd_classic*8/3
 

同様に、"No Overshoot" のパラメータには以下のように変換できます。

    Kp=Kp_classic/3 
    Ki=Ki_classic 
    Kd=Kd_classic*8/3
 


Note that the multipliers for the autotuning parameters each have only one significant digit (implying 10% maximum precision), and that the other schemes differ by factors of 2 or 3. PID autotuning and tuning isn't terribly precise, and changes in the parameters by factors of 5 to 50% are perfectly reasonable.

In Marlin, the parameters that control and limit the PID controller can have more significant effects than the popular PID parameters. For example, PID_MAX and PID_FUNCTIONAL_RANGE, and PID_INTEGRAL_DRIVE_MAX can each have dramatic, unexpected effects on PID behavior. For instance, a too-large PID_MAX on a high-power heater can make autotuning impossible; a too-small PID_FUNCTIONAL_RANGE can cause odd reset behavior; a too large PID_FUNCTIONAL_RANGE can guarantee overshoot; and a too-small PID_INTEGRAL_DRIVE_MAX can cause droop.

PID Tuning by Commercial PID

If you have access to a PID controller unit and a compatible thermal probe that fits down into your hotend, you can use them to tune your PID and calibrate your thermistor.

Connection of the output of the PID to your heater varies depending on your electronics. (I used a 1K2:4K7 voltage divider to drop the 22V output of the PID to 5V for my bread-boarded VNP4904)


After the PID is connected you can use it to measure the nozzle temperature and correlate it with the thermistor readings and resistances.

Conversion from the commercial PID values of kP in %fullscale, Ti in seconds, and Td in seconds is as follows:

       Kp_marlin = 255 * kP_%fs / 100             (counts/C)

       Ki_marlin = Kp_marlin/Ti                   (counts/(C*s)) 

       Kd_marlin = Td/Kp_marlin                   (counts/(C/s))


As an example, a $30 MYPIN TD4-SNR 1/16 DIN PID temperature controller and $10 type-K probe can hold a particular Wildseyed hotend with a 6.8ohm resistor at 185.0C+/-0.1C using 12V with about a 43.7% duty cycle, or 0.437*12*12/6.8=9.25W. Invoking the autotuning on the controller produces these parameters: P=0.8%/C, I=27s, D=6.7s. Converting these to Marlin PID values:

   
       Kp_marlin = 255counts/fs * 0.8% / (100%/fs) = 2.04 counts/C

       Ki_marlin = Kp_marlin/Ti = 2.04counts/C/(27s) = 0.7 counts/(C*s)

       Kd_marlin = Td/Kp_marlin = 6.7s/(2.04 counts/C) = 3.3 counts/(C/s)

Differences between the results can be caused by physical differences in the systems, (e.g: the thermocouple is closer to the heater than the thermistor,) or by different choices of autotuning parameters (e.g.: the MYPIN TD4 autotuning process is a proprietary black box, while Marlin uses Zeigler-Nichols "Classic" method.)

The Temperature/resistance table below was developed by using the PID+thermocouple system to set temperatures on a sample hotend by controlling the heater while measuring the thermistor resistance. These values can be used with Nophead's http://hydraraptor.blogspot.com/2012/11/more-accurate-thermistor-tables.html or Marlin's https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/createTemperatureLookupMarlin.py to create calibrated thermistor tables. The PID column collects the autotuning values produced by the PID controller for the indicated temperature. The kP,Ki,Kd lists the converted parameters.

温度 デューティ
サイクル
サーミスターの
抵抗値
PIDの目安 Kp, Ki, Kd
60.0 6.0 31630
100.0 15.7 10108 1.1%/C, 35.5s, 8.8s 2.81, 0.08, 3.13
120.0 22.5 5802 1.0%/C, 32.0s, 8.0s 2.55, 0.08, 3.14
135.0 26.5 3967
150.0 28.5 2840 1.2%/C, 29.0s, 7.2s 3.06, 0.10, 2.35
170.0 34.0 1829
185.0 43.7 1347 0.8%/C, 27s, 6.7s 2.04, 0.08, 3.28
190.0 45.9 1200 0.8%/C, 26s, 6.5s 2.04, 0.08, 3.18
200.0 51.0 977