DangerKlippers / danger-klipper

Klipper but... Dangerous
GNU General Public License v3.0
256 stars 86 forks source link

Support dynamic power for PTC heaters in MPC #393

Open dberlin opened 1 month ago

dberlin commented 1 month ago

This change adds basic support to MPC for heaters whose max power changes as the temperature changes. We require the voltage, temperature coefficient, and ambient temp at which max wattage is spec'd (usually 23C). With that, we compute the available power as the temperature changes, instead of treating it as a constant.

The temperature coefficient is usually spec'd by the manufacturer, but can also be calculated if you have two wattage@temp points.

R@t1 = Voltage^2 / wattage@t1 R@t2 = Voltage^2 / wattage@t2

R@t2 = R@t1 (1 + temp_coefficient (t2 - t1)) Solve for temp_coefficient

I have some experimental code as a followup that tries to calculate the temp coefficient by seeing how actual heating changes when constant power is applied. It works okay, as most of these heaters are fairly linear.