<h3>Short answer</h3>
<p>PID reacts only <strong>after</strong> the temperature changes are registered by the sensor. MPC instead calculates the expected heat loss <strong>before</strong> the temperature actually changes and then applies heat to <strong>prevent</strong> those changes.</p>
<p>Here's a graph comparing PID and MPC, <a href="https://www.reddit.com/r/ender3/comments/ykqkta/model_predictive_control_mpc_in_marlin_is_a_game/" rel="nofollow noreferrer">created by Reddit user yelleck</a>:</p>
<p><a href="https://www.reddit.com/r/ender3/comments/ykqkta/model_predictive_control_mpc_in_marlin_is_a_game/" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lFpq2.png" alt="Graph showing the comparison of temperature regulation between PID and MPC" title="Graph showing the comparison of temperature regulation between PID and MPC" /></a></p>
<h3>Slightly derogatory answer</h3>
<p>PID and its modifications<sup>1</sup> is the duct-tape solution to the hotend temperature regulation problem<sup>2</sup>, and MPC is the engineering-PhD solution.</p>
<h3>Slightly longer answer</h3>
<p>MPC is a <strong>predictive</strong> model that compensates <strong>before the temperature actually changes</strong>. It calculates a physical heat model (effectively a <a href="https://en.wikipedia.org/wiki/Thermal_conductance_and_resistance" rel="nofollow noreferrer">Thermal Resistance Circuit)</a>. Using this, it figures out how much heat energy (in <a href="https://en.wikipedia.org/wiki/Heat" rel="nofollow noreferrer">Joules</a>) will leave the hotend in a given time—through <a href="https://en.wikipedia.org/wiki/Thermal_radiation" rel="nofollow noreferrer">radiation</a>, <a href="https://en.wikipedia.org/wiki/Convection_(heat_transfer)" rel="nofollow noreferrer">convection</a>, and extruded <a href="https://en.wikipedia.org/wiki/Heat_capacity" rel="nofollow noreferrer">molten plastic</a>—and thus it knows exactly how much heat energy (again in Joules, or &quot;Watts times Seconds&quot;) it has to put in to keep the temperature the same or move to a new temperature. The properties of this physical model (heat capacity, emissivity, etc.) can be obtained automatically with fairly good accuracy or looked up in a table (filament heat capacity per mm).</p>
<p>PID on the other hand is a <strong>reactive</strong> model that can only work <strong>after the temperature has already changed</strong>. It is more like a vigilant operator who stares <strong>only</strong> at the measured difference between the actual and desired temperature. If this temperature difference changes by just a tiny bit, or by a large step, it will immediately try to counteract that error by applying its three rules: P, I, and D.</p>
<p>The three PID coefficients can also be auto-tuned, but the results are... well, let's say there is a reason that there are dozens if not hundreds of PID tuning guides and forum questions out there. The coefficients are not linked to any distinct physical property of your hotend: The geometry, fan, heater power, silicone sock, and filament are all mushed together into three abstract numbers. So far I have tried a handful of times to get a deep, intuitive understanding of PID behavior and tuning, but have failed each time, and honestly, I don't consider it worth my time anymore. MPC just makes so much more sense.</p>
<p>The PID controller does not know or care why the temperature difference changed. It could be due to faster extrusion speed, switching on the fan, or a changed temperature setpoint (<code>M104</code>), for example. A PID controller has to react to any changes using the same rigid 3-rules-system<sup>1</sup>, although the three situations will in practice require different reactions. The MPC model, on the other hand, can figure out precisely how much each of those changes would influence the temperature and how it must react to prevent that.</p>
<p>So in a PID-based system, the temperature will always fluctuate a little <strong>by design</strong>. It <strong>needs</strong> those temperature changes in order to know how to react (unless you assume a completely static situation), because it is the only measurement it has. Consequently, a noisy temperature measurement, which looks like a lot of tiny, very fast changes, will force the PID controller to react to them, which leads to even more noticeable fluctuations because the system reacts to a change that isn't really there, since it's just noise. Alternatively, you could make it react slower to ignore these fast noise fluctuations, but that will make it... well... slower.</p>
<blockquote>
<p>And why is it more useful for 'high-power heaters'?</p>
</blockquote>
<p>As explained above, the PID controller must react to noise. With a high-power heater, even a tiny adjustment in the PWM can lead to a large increase in temperature. So the controller must react more slowly and carefully so as not to overshoot or oscillate. But by going more slowly, you are throwing away the main benefit of your high-power heater, namely: faster heating. Since MPC largely ignores noise, it won't oscillate. And since it knows your heater power in Watts and the exact amount of energy needed in Joules, it can just go &quot;full throttle&quot; when a higher temperature is needed<sup>3</sup>, stopping just in time to avoid overshooting. With a lower-powered heater, this problem is not so apparent, because it can only go slowly <strong>anyways</strong>.</p>
<hr />
<p><sup>1</sup> Yes, Marlin has <code>PID_FUNCTIONAL_RANGE</code>, <code>PID_EXTRUSION_SCALING</code>, and <code>PID_FAN_SCALING</code> to work around these issues. Those are hacky, ad-hoc solutions that try to do the same thing as MPC, but without a correct and complete physical model underneath. It's rather like adding more duct tape to the problem instead of stepping back, understanding the situation, and engineering a proper solution. Also, each of these functions has its own configuration parameters, which require separate tuning, while the auto-tuning in MPC can take care of all of them together (except filament heat capacity, which you can look up or calculate using physics instead). So if you consider using those additional PID features, you are essentially using MPC, but without a solid theoretical foundation, so you could as well go all the way and just use MPC instead.</p>
<p><sup>2</sup> Don't get me wrong: PID control is a flexible and well-established tool that is for many, many different tasks everywhere. Just like duct tape. But it is not the best tool for every job. A well-tuned PID can control the hotend temperature within a few degrees with little overshoot. It just wasn't specifically <strong>designed</strong> for this case, and thus it is outperformed by tools that <strong>were</strong>.</p>
<p><sup>3</sup> Marlin PID tries to do the same thing with <code>PID_FUNCTIONAL_RANGE</code>: it goes full power when the temperature difference is greater than this configured value. But with a high-power heater, this is an additional value that you have to tune. And after the PID kicks in, it needs some time to &quot;wind up&quot;, which is another time during which the heater is not using its full potential. Also, the PID coefficients have to be tuned for different, partially conflicting goals: heating up quickly, avoiding overshoots, and avoiding oscillations. Again, all are lumped together into three abstract numbers with no physical meaning.</p>

CC BY-SA 4.0
2023-12-06T20:56:07.430Z
Welcome @Fritz and a very good and comprehensive answer. Thank you!
Bob Ortiz
CC BY-SA 4.0
2023-12-06T14:27:50.523Z
2023-12-07T04:25:29.733Z
2023-12-07T04:25:29.733Z
Fritz
<p>The <a href="https://www.youtube.com/watch?v=4D9XwclutOo" rel="nofollow noreferrer">YouTube video 'PID vs MPC'</a> from Mark Misin Engineering Ltd perfectly demonstrates that Model Predictive Temperature Control (MPC) is more powerful than Proportional-Integral-Derivative (PID). Marlin implemented MPC as described in <a href="https://marlinfw.org/docs/features/model_predictive_control.html" rel="nofollow noreferrer">Marlin's MPC documentation</a>. The Marlin-based firmware version I use also describes MPC in the <a href="https://github.com/mriscoc/Special_Configurations/releases/tag/MPC" rel="nofollow noreferrer">mriscoc MPC documentation</a> and as follows:</p>
<blockquote>
<p>In the latest releases, MPC is being incorporated in all versions. MPC has proven to be a better algorithm for keeping the nozzle temperature stable, and it is also very useful for high-power heaters.<br><sub>Source: <a href="https://github.com/mriscoc/Ender3V2S1/wiki#model-predictive-temperature-control-mpc" rel="nofollow noreferrer">GitHub mriscoc repository for Ender 3 V2/S1</a></sub></p>
</blockquote>
<p>Since 3D printers, especially the heated parts (bed and nozzle), are relatively simple, with only simple control and sensor readings, why <strong>exactly</strong> is MPC a better choice than PID? And why is it more useful for 'high-power heaters'?</p>

<marlin><temperature><pid><mriscoc>
Why is MPC better than PID for 3D printers, and (why) is it more useful for 'high-power heaters'?
Bob Ortiz
# Why is MPC better than PID for 3D printers, and (why) is it more useful for 'high-power heaters'?

(Asked by: username_0 on 2023-11-27)

The [YouTube video 'PID vs MPC'](https://www.youtube.com/watch?v=4D9XwclutOo) from Mark Misin Engineering Ltd perfectly demonstrates that Model Predictive Temperature Control (MPC) is more powerful than Proportional-Integral-Derivative (PID). Marlin implemented MPC as described in [Marlin's MPC documentation](https://marlinfw.org/docs/features/model_predictive_control.html). The Marlin-based firmware version I use also describes MPC in the [mriscoc MPC documentation](https://github.com/mriscoc/Special_Configurations/releases/tag/MPC) and as follows:

> In the latest releases, MPC is being incorporated in all versions. MPC has proven to be a better algorithm for keeping the nozzle temperature stable, and it is also very useful for high-power heaters.  
> Source: [GitHub mriscoc repository for Ender 3 V2/S1](https://github.com/mriscoc/Ender3V2S1/wiki#model-predictive-temperature-control-mpc)

Since 3D printers, especially the heated parts (bed and nozzle), are relatively simple, with only simple control and sensor readings, why **exactly** is MPC a better choice than PID? And why is it more useful for 'high-power heaters'?

**Tags:** marlin, temperature, pid, mriscoc

---

## 1 answers

### Answer by username_1 on 2023-12-06. Score: 2 | Accepted answer

### Short answer

PID reacts only **after** the temperature changes are registered by the sensor. MPC instead calculates the expected heat loss **before** the temperature actually changes and then applies heat to **prevent** those changes.

Here's a graph comparing PID and MPC, [created by Reddit user yelleck](https://www.reddit.com/r/ender3/comments/ykqkta/model_predictive_control_mpc_in_marlin_is_a_game/):

[![Graph showing the comparison of temperature regulation between PID and MPC](https://i.sstatic.net/lFpq2.png "Graph showing the comparison of temperature regulation between PID and MPC")](https://www.reddit.com/r/ender3/comments/ykqkta/model_predictive_control_mpc_in_marlin_is_a_game/)

### Slightly derogatory answer

PID and its modifications1 is the duct-tape solution to the hotend temperature regulation problem2, and MPC is the engineering-PhD solution.

### Slightly longer answer

MPC is a **predictive** model that compensates **before the temperature actually changes**. It calculates a physical heat model (effectively a [Thermal Resistance Circuit)](https://en.wikipedia.org/wiki/Thermal_conductance_and_resistance). Using this, it figures out how much heat energy (in [Joules](https://en.wikipedia.org/wiki/Heat)) will leave the hotend in a given time—through [radiation](https://en.wikipedia.org/wiki/Thermal_radiation), [convection](https://en.wikipedia.org/wiki/Convection_(heat_transfer)), and extruded [molten plastic](https://en.wikipedia.org/wiki/Heat_capacity)—and thus it knows exactly how much heat energy (again in Joules, or "Watts times Seconds") it has to put in to keep the temperature the same or move to a new temperature. The properties of this physical model (heat capacity, emissivity, etc.) can be obtained automatically with fairly good accuracy or looked up in a table (filament heat capacity per mm).

PID on the other hand is a **reactive** model that can only work **after the temperature has already changed**. It is more like a vigilant operator who stares **only** at the measured difference between the actual and desired temperature. If this temperature difference changes by just a tiny bit, or by a large step, it will immediately try to counteract that error by applying its three rules: P, I, and D.

The three PID coefficients can also be auto-tuned, but the results are... well, let's say there is a reason that there are dozens if not hundreds of PID tuning guides and forum questions out there. The coefficients are not linked to any distinct physical property of your hotend: The geometry, fan, heater power, silicone sock, and filament are all mushed together into three abstract numbers. So far I have tried a handful of times to get a deep, intuitive understanding of PID behavior and tuning, but have failed each time, and honestly, I don't consider it worth my time anymore. MPC just makes so much more sense.

The PID controller does not know or care why the temperature difference changed. It could be due to faster extrusion speed, switching on the fan, or a changed temperature setpoint (`M104`), for example. A PID controller has to react to any changes using the same rigid 3-rules-system1, although the three situations will in practice require different reactions. The MPC model, on the other hand, can figure out precisely how much each of those changes would influence the temperature and how it must react to prevent that.

So in a PID-based system, the temperature will always fluctuate a little **by design**. It **needs** those temperature changes in order to know how to react (unless you assume a completely static situation), because it is the only measurement it has. Consequently, a noisy temperature measurement, which looks like a lot of tiny, very fast changes, will force the PID controller to react to them, which leads to even more noticeable fluctuations because the system reacts to a change that isn't really there, since it's just noise. Alternatively, you could make it react slower to ignore these fast noise fluctuations, but that will make it... well... slower.

> And why is it more useful for 'high-power heaters'?

As explained above, the PID controller must react to noise. With a high-power heater, even a tiny adjustment in the PWM can lead to a large increase in temperature. So the controller must react more slowly and carefully so as not to overshoot or oscillate. But by going more slowly, you are throwing away the main benefit of your high-power heater, namely: faster heating. Since MPC largely ignores noise, it won't oscillate. And since it knows your heater power in Watts and the exact amount of energy needed in Joules, it can just go "full throttle" when a higher temperature is needed3, stopping just in time to avoid overshooting. With a lower-powered heater, this problem is not so apparent, because it can only go slowly **anyways**.

---

1 Yes, Marlin has `PID_FUNCTIONAL_RANGE`, `PID_EXTRUSION_SCALING`, and `PID_FAN_SCALING` to work around these issues. Those are hacky, ad-hoc solutions that try to do the same thing as MPC, but without a correct and complete physical model underneath. It's rather like adding more duct tape to the problem instead of stepping back, understanding the situation, and engineering a proper solution. Also, each of these functions has its own configuration parameters, which require separate tuning, while the auto-tuning in MPC can take care of all of them together (except filament heat capacity, which you can look up or calculate using physics instead). So if you consider using those additional PID features, you are essentially using MPC, but without a solid theoretical foundation, so you could as well go all the way and just use MPC instead.

2 Don't get me wrong: PID control is a flexible and well-established tool that is for many, many different tasks everywhere. Just like duct tape. But it is not the best tool for every job. A well-tuned PID can control the hotend temperature within a few degrees with little overshoot. It just wasn't specifically **designed** for this case, and thus it is outperformed by tools that **were**.

3 Marlin PID tries to do the same thing with `PID_FUNCTIONAL_RANGE`: it goes full power when the temperature difference is greater than this configured value. But with a high-power heater, this is an additional value that you have to tune. And after the PID kicks in, it needs some time to "wind up", which is another time during which the heater is not using its full potential. Also, the PID coefficients have to be tuned for different, partially conflicting goals: heating up quickly, avoiding overshoots, and avoiding oscillations. Again, all are lumped together into three abstract numbers with no physical meaning.

> **Comments:**
> **username_0**: Welcome @Fritz and a very good and comprehensive answer. Thank you!  

---

