PID Auto Tuning in Marlin

Adding Go Faster Stripes to your 3D Printer
thamask
Posts: 11
Joined: Wed Jan 10, 2018 2:33 pm

PID Auto Tuning in Marlin

Post: # 228Post thamask
Tue Jan 16, 2018 9:46 am

Making sure the Hotend and Hotbed are tuned correctly is something I have recently come and across and in Marlin its sooooo easy.

If you notice temp swings greater than a few degrees running PID autotune can reduce those wild swings and stop the potential thermal banding that can occur on prints.

You have to make sure in configuration.h you have to uncomment #define PIDTEMPBED and and comment //#define BED_LIMIT_SWITCHING, you will need to run the Arduino software to edit that config file.

To Auto PID tune the Hotend send GCODE, make sure your hotted or Heated is cold before you run the GCODE

M303 E0 C8 S225

This will heat up your hotned to 225 over 8 cycles, it can take several minutes and will return a result like:

Kp: 19.56
Ki: 0.71
Kd: 134.26
PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h

enter YOUR settings not the ones above in with the GCODE

M301 P19.56 I0.71 D134.26

Do the same for your Heated with GCODE

M303 E-1 S60 C8

and enter the results with

M304 P1 I2 D3 (remembering to enter your settings for P I and D)

Remember to commit your setting to memory with M500

It is advised you run this process if you change your printers location, or if there are ambient temperature changes in the room your printer is located in. It doesn't take very long one you have done it once.



ModMike
Posts: 26
Joined: Thu Feb 08, 2018 3:07 pm

Re: PID Auto Tuning in Marlin

Post: # 377Post ModMike
Thu Feb 08, 2018 3:47 pm

You can also enable the PID Auto tune in the LCD Menu and enter the values there. I did it in Marlin Instant Configurator so not sure which line it is.
Last edited by ModMike on Mon Feb 19, 2018 12:37 pm, edited 1 time in total.

Mystikal
Posts: 4
Joined: Mon Feb 05, 2018 1:02 am

Re: PID Auto Tuning in Marlin

Post: # 378Post Mystikal
Thu Feb 08, 2018 4:04 pm

ModMike wrote:
Thu Feb 08, 2018 3:47 pm
You can also enable the PID Auto tune in the LCD Menu and enter the values there. I did it in Marlin Easy so not sure which line it is.
Line #346

Code: Select all

//#define PID_AUTOTUNE_MENU // Add PID Autotune to the LCD "Temperature" menu to run M303 and apply the result.

ModMike
Posts: 26
Joined: Thu Feb 08, 2018 3:07 pm

Re: PID Auto Tuning in Marlin

Post: # 382Post ModMike
Thu Feb 08, 2018 5:11 pm

Unfortunately it only seems to enable the hot end auto tune cycle, which works really well by the way. I cant seem to find a way to tune the bed from the LCD, unless I need to enable something else.

Any ideas?

ModMike
Posts: 26
Joined: Thu Feb 08, 2018 3:07 pm

Re: PID Auto Tuning in Marlin

Post: # 383Post ModMike
Thu Feb 08, 2018 6:50 pm

When I ran the bed autotune I got what seems to be a common error: PID Autotune failed! Bad extruder number

This is due to a value greater than 127 in the WATCH_BED_TEMP_PERIOD. Mine was at 140 so I lowered it to 120 and everything worked fine.

Apparently this issue will be fixed in the next release of Marlin.

steve83931
Posts: 2
Joined: Sat Feb 10, 2018 8:27 am

Re: PID Auto Tuning in Marlin

Post: # 406Post steve83931
Sat Feb 10, 2018 10:22 am

Thanks ModMike,

now heatbed PID tuning should also work for me!

Can you tell me where to add the values?
I have two areas in configuration.h:

#if ENABLED(PIDTEMPBED)

//#define PID_BED_DEBUG // Sends debug data to the serial port.

//120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
#define DEFAULT_bedKp 337.76
#define DEFAULT_bedKi 46.85
#define DEFAULT_bedKd 608.72

//120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
//from pidautotune
//#define DEFAULT_bedKp 97.1
//#define DEFAULT_bedKi 1.41
//#define DEFAULT_bedKd 1675.16

Do i have to remove the backslashes for the values in the pidautotune "block" and add them in the FOPDT section?

steve83931
Posts: 2
Joined: Sat Feb 10, 2018 8:27 am

Re: PID Auto Tuning in Marlin

Post: # 407Post steve83931
Sat Feb 10, 2018 10:39 am

Changed to:

//120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
//#define DEFAULT_bedKp 337.76
//#define DEFAULT_bedKi 46.85
//#define DEFAULT_bedKd 608.72

//120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
//from pidautotune
#define DEFAULT_bedKp 97.1
#define DEFAULT_bedKi 1.41
#define DEFAULT_bedKd 1675.16

Hope it works now.

ModMike
Posts: 26
Joined: Thu Feb 08, 2018 3:07 pm

Re: PID Auto Tuning in Marlin

Post: # 528Post ModMike
Sat Feb 17, 2018 7:16 am

Steve, so sorry I didn't answer until now, I forgot to subscribe to this thread!

I am sorry but I don't know, I spent close to 40 hours dealing with unnbricking and setup for an A2. I promise that I will get back to you if I figure out the bed part. My other issue is that I am using Marlin Instant Configurator by akaJes or some such so I have no line numbers to refer back to, only the specific function name. You can use the free editor Atom, it makes editing way easier.

Cheers.
Last edited by ModMike on Mon Feb 19, 2018 12:41 pm, edited 1 time in total.

WarHawk8080
Posts: 52
Joined: Sun Feb 11, 2018 6:19 pm

Re: PID Auto Tuning in Marlin

Post: # 544Post WarHawk8080
Mon Feb 19, 2018 9:01 am

Awesome! Good writeup!

ModMike
Posts: 26
Joined: Thu Feb 08, 2018 3:07 pm

Re: PID Auto Tuning in Marlin

Post: # 547Post ModMike
Mon Feb 19, 2018 12:40 pm

I referred to Marlin Instant Configurator earlier. You can get it here:

https://github.com/akaJes/marlin-config

Its a bit of an install but is totally worth it.

Post Reply