New Option: Model Predictive Temperature Control (Experimental)

Hi all,

Support for a new option to replace PID heating for the hotend has just been merged. This seems to have a lot better control over the hotend heater, and at least in my testing, seems to have a better profile for heating.

You can find the new setting in the Firmware Builder as per the below screenshot.

The documentation is still being processed - but in simple terms, the new command M306 is now added.

The basic options are:

 A<watts/kelvin>           Ambient heat transfer coefficient (no fan).
 C<joules/kelvin>          Block heat capacity.
 E<extruder>               Extruder number to set. (Default: E0)
 F<watts/kelvin>           Ambient heat transfer coefficient (fan on full).
 P<watts>                  Heater power.
 R<kelvin/second/kelvin>   Sensor responsiveness (= transfer coefficient / heat capcity).
 T                         Autotune the active extruder.

Once you flash your printer with a MPC enabled firmware, set your heater power as per the rating - most printers have either 30W or 40W heaters (mine is 70W), so you’d run:

M306 P30 ; 30W heater
M306 P40 ; 40W heater
M306 P70 ; 70W heater

Once that’s done, run the autotune:

M306 T

At this point, the rest of the setup is automatic.

When it finishes, save your settings via M500.

On my personal printer, the heatup profile when from this with an overshoot of 10-15c when using PID:
image

To this when autotuned using MPC:
image

I look forward to seeing peoples feedback on this brand new feature.

1 Like

I am extremely happy with temperature control! However, it has taken control of part cooling fan. It is constantly changing speeds. I just ran a temp tower with bridging allowed and it failed the bridging terribly. The fan is still oscillating and bridging needs max cooling to cool filament when crossing the bridge. How can I get control of cooling fan from this feature?

MPCTEMP doesn’t control the fans. I’d suggest checking your slicer settings.

this is great. For some strange reason I was NOT able to tune PID at all, no matter how many iterations I tried. It’d always end up with a huge delta. (I’d set it to 215 and it’d jump from 213 to 218, some times 220! then back to 212, etc)
Tried MPC out of curiosity, and now is rock solid (± 1°C). No hardware changes at all. This is on Marlin 2.1.1. The hotend is a Volcano with a 70W cartridge. The rest is a simple Tevo Tornado without any mods in the extruder area.

Disclaimer: I still need to test it properly. This is just after one hour of playing with MPC. But I’m pretty happy with it so far. Even if it’s not perfect in the long run, it’s much better than my previous PID calibration.

1 Like

My fan issue was an intermittent wire connection to fan. When the fan kicked on the wire disconnected. The fan stopped spinning and power reconnected to fan- thus fan ramping up and down. I thought software, but wiring issue. I have used MPC for many hours and very solid temps!! It puts PID to shame. I love it!

1 Like

I don’t have octoprint but enabled it instead of the pid with bang bang. With stock settings in Marlin at 50mm/s and I am getting better quality than I did with the other way around. And seeing rock solid temps on the hotend unlike the stock settings used in YouTube videos for setup. Have some things to iron out with my SKR 2 rev B. In the firmware and make a new case for it. Once I have my manta M8P I will play around with the settings

Is anyone having issues with getting MPC Autotune to work on an Ender3Pro v4.2.7 w/bltouch and stock hotend?
Everytime I try to autotune it stops at first attempt ramping to 200C

Send: M306 T
Recv: MPC Autotune start for E0
[…]
Recv: M106 P0 S0
Recv: M106 P0 S255
[…]
Recv: Cooling to ambient
[…]
Recv: M106 P0 S0
Recv: Heating to over 200C
Recv: MPC Autotune interrupted!
Recv: M106 P0 S0
[…]
Recv: ok P15 B3

I can’t figure any reason for it to not work. I’m using a custom build made with the firmware builder (tried today’s build to be sure it wasn’t a bug already patched) and although it does seem to print okay and the ramp up is nice and free of ringing I can’t get the autotune working.
When first trying it out I didn’t set my heater power and just tried to autotune. Today I read I was supposed to set that heater power (M306 P40) but it didn’t help with the autotune.

Am I stuck tuning it manually?

That’s interesting - I’ve never seen that before…

Do you see the temperature rise when heating is in progress?

That’s just the thing - it fails with “MPC Autotune interrupted” as soon as it reaches the “Heating to over 200c” stage (no changes in hotend temp observed). Odd that it fails to heat up when I was able to manually tune it thereafter following the Marlin documentation and the performance seems to be as expected.

Let try this… Reset your printer to factory defaults (M502), then store those settings to the EEPROM (M500), power cycle the printer, and then try M306 T again.

The default / stock hotend power I believe is 40W, so that setting shouldn’t need to be changed.

I’m just wondering if something weird is going on in the saved EEPROM settings…

After M502 + M500 + power cycle the M306 T command did the same as before, not even engaging the hotend for a moment before “interruption” (see log excerpt below)

Recv: Cooling to ambient
Recv: T:24.59 /0.00 B:27.32 /0.00 @:0 B@:0
Recv: T:24.55 /0.00 B:27.37 /0.00 @:0 B@:0
Recv: T:24.58 /0.00 B:27.37 /0.00 @:0 B@:0
Recv: T:24.59 /0.00 B:27.34 /0.00 @:0 B@:0
Recv: T:24.58 /0.00 B:27.34 /0.00 @:0 B@:0
Recv: T:24.55 /0.00 B:27.30 /0.00 @:0 B@:0
Recv: T:24.63 /0.00 B:27.35 /0.00 @:0 B@:0
Recv: T:24.61 /0.00 B:27.34 /0.00 @:0 B@:0
Recv: T:24.56 /0.00 B:27.34 /0.00 @:0 B@:0
Recv: T:24.61 /0.00 B:27.32 /0.00 @:0 B@:0
Recv: T:24.63 /0.00 B:27.28 /0.00 @:0 B@:0
Recv: M106 P0 S0
Recv: Heating to over 200C
Recv: MPC Autotune interrupted!
Recv: M106 P0 S0
[…]
Recv: T:24.63 /0.00 B:27.28 /0.00 @:0 B@:0
Recv: ok P15 B3
Send: M113 S2
Recv: ok P15 B3
Recv: T:24.61 /0.00 B:27.27 /0.00 @:0 B@:0

Isn’t the autotune script supposed to be running M104 S200 / M109 S200 at the point it errors?

Certainly there should be some heating going on… If you just set a heat for the hotend normally, does it heat up ok?

If so, I’d jump over and lodge an issue here including all your logs:

Yes, the hotend operates as expected outside of the MPC autotune. Prints normal and can be manually set with no issue.

I’ll head over to the Issues page you linked. Thanks, @CRCinAU

Well, if you read the Marlin page about Model Predictive Control you have the Manual Tuning section that says " If M306 T doesn’t work –e.g., with positive temperature coefficient (PTC) hotends– MPC can be configured manually."

I was also excited to try this new feature when I got the same MPC Autotune interrupted! message.
The manual procedure seems too complicated. I’ll buy a Trianglelab NTC 100K B3950 thermistor for my Ender 3.

I’ve been informed that there’s a fix for this pending under this PR:

If you keep an eye on that PR, once its merged, an hour or so later, the builder will grab the fixed version and you can try building a custom firmware again.

If you use the nightlies, the next build will have those fixes.