Reprap 기반의 코드에 적용되어 있는 PID 를 튜닝하는 방법은 다음과 같이 PID Auto-tune을 사용해서 상수값 Kp, Ki, Kd값을 정하고 Configuration.h에 설정을 한다.
M303 E0 S210 C8
위 코드의 의미는 타겟온도 210도로 하고 8번의 사이클을 거쳐서 값을 정하는것. 그러면 다음과 같이 값이 나온다.
bias: 92 d: 92 min: 196.56 max: 203.75
Ku: 32.59 Tu: 54.92
PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h
Configuration.h 파일에 설정후 컴파일을 하는 대신에 다음과 같이 M301커멘드로 테스트가 가능하다.
M301 P19.56 I0.71 D134.26
- The PID test doesn’t use a PID control loop to control the temperature! It shouldn’t matter what values you have stored when you run the autotune. Instead, the autotune function runs the heater in “bang-bang” mode, leaving the heater on for an extended period of time, and then off for an extended period of time, and simply observing the thermal behavior in response to heating and cooling.
- Each cycle in the autotune run is a test where the controller cycles the heater, intentionally overshooting the target value for 5 seconds and observing how far up it goes, and how long it takes to coast back down to the target temperature. Once below the target temperature for 5 seconds, it observes how far the temp fell, and then cycles the heater on for another run at the target.
- The first three cycles calculate a “bias” to dial in the level of maximum power that will be used for the remainder of the cycle/tests. You will get to see those bias numbers, but there’s not much you can do with them. You will not get PID parameters from these initial cycles.
- The fourth and subsequent tests still overshoot by 5 seconds and undershoot by 5 seconds, but this time the observed duration of the heat cycle, and the min and max temperatures reached, are put through the mathematical formulas described in the Ziegler–Nichols PID tuning method. This is a mathematical way to determine PID constants that perform acceptably in many systems. Values for the three parameters Kp, Ki, and Kd will be displayed for the cycle, and a new cycle will begin.
- After all the test cycles are finished, you can average the values you get from each of these cycles and use those as your baseline parameters.
Kp, Ki, Kd의 의미
- 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.
- Kp is the “proportional” term. The further off target you are, the more power this term contributes.
- Ki is the “integral” term. This term contributes more control input as the accumulated offset over time between measured and target temperatures increases. In other words the longer you’ve been off target, the more input this term will contribute in the direction of the target (could be more or less heater power).
- Kd is the “derivative” term. This term allows the controller to “predict” or look ahead of the current temperature to slow the rate of change down and let the measured temperature creep up on the target. Mathematically speaking it attempts to minimize the slope of the temperature curve with respect to the target.
- if it overshoots a lot and oscillates, either the integral gain needs to be increased or all gains should be reduced
- Too much overshoot? Increase D, decrease P.
- Response too damped? Increase P.
- Ramps up quickly to a value below target temperature (0-160 fast) and then slows down as it approaches target (160-170 slow, 170-180 really slow, etc) temperature? Try increasing the I constant.
- if the temperature is getting too hot before settling down, increase Kd and decrease Kp (more creeping up on the temperature and less muscling it around)
- if the temperature tapers off just under the target and never quite reaches it, decrease Kd and increase Ki (less creeping up alongside the target, and more correction for cumulative offset) Increasing Ki means that cruising just a hair under the target for a long time will cause Ki to gradually put more power into the heater until it reaches the target. A higher Kd would fight this process by decreasing power to get the measured temperature curve parallel to the target temperature line.
- if the temperatures are taking a long time to settle, oscillating or hunting indefinitely, decrease Ki and increase Kd (less agitation from cumulative error, and more gliding into alignment with the target); alternatively try decreasing all three terms… the PID equivalent of taking some deep breaths and relaxing the amount of control you’re exerting