Marlin PID settings

2,365 views
Skip to first unread message

Triffid Hunter

unread,
Apr 5, 2012, 2:05:06 AM4/5/12
to make...@googlegroups.com
Hi all,

the default PID settings in Marlin for MakerGear hot-ends weren't really doing it for me, so I went about tuning them myself empirically by hand.

The settings I came up with are as follows:

    #define  DEFAULT_Kp 40.0
    #define  DEFAULT_Ki 0.55
    #define  DEFAULT_Kd 35

with these settings I get maybe 2-3c overshoot on warm-up, and a +/-0.5c swing during printing.

Wondering if it's just me, or if these are better than the existing settings for all?


Len Trigg

unread,
Apr 5, 2012, 4:48:34 AM4/5/12
to make...@googlegroups.com
On Thu, Apr 5, 2012 at 6:05 PM, Triffid Hunter <triffid...@gmail.com> wrote:
> the default PID settings in Marlin for MakerGear hot-ends weren't really
> doing it for me, so I went about tuning them myself empirically by hand.
>
> The settings I came up with are as follows:
>
>     #define  DEFAULT_Kp 40.0
>     #define  DEFAULT_Ki 0.55
>     #define  DEFAULT_Kd 35
>
> with these settings I get maybe 2-3c overshoot on warm-up, and a +/-0.5c
> swing during printing.

Have you tried the new marlin PID autotune option?

Cheers,
Len.

Triffid Hunter

unread,
Apr 5, 2012, 4:49:41 AM4/5/12
to make...@googlegroups.com
On Thu, Apr 5, 2012 at 6:48 PM, Len Trigg <len...@gmail.com> wrote:
Have you tried the new marlin PID autotune option?

yes, it gave me settings that caused an incessant +/-10c oscillation, that's one of the things that inspired me to do it myself 

B W Evans

unread,
Apr 5, 2012, 8:56:17 AM4/5/12
to make...@googlegroups.com
That's surprising. I was getting a +/- 2 C swing using bang bang and then I tried the autotune and it worked really well for me on my Mosaic. I ended up with these settings and a +/- 0.05 C swing:

#define  DEFAULT_Kp 24.72
#define  DEFAULT_Ki 0.88
#define  DEFAULT_Kd 231.1 

Brian

Joseph Bekedam

unread,
Apr 5, 2012, 11:05:03 AM4/5/12
to make...@googlegroups.com
That does sound odd. How many cycles did you let the M303 run for? I let it run ~5-6 cycles, and now my swing is +-0.2. Admittedly, I am using a MendelMax, but that really shouldn't affect things.

Triffid Hunter

unread,
Apr 5, 2012, 7:02:13 PM4/5/12
to make...@googlegroups.com
On Fri, Apr 6, 2012 at 1:05 AM, Joseph Bekedam <jbek...@gmail.com> wrote:
That does sound odd. How many cycles did you let the M303 run for? I let it run ~5-6 cycles, and now my swing is +-0.2. Admittedly, I am using a MendelMax, but that really shouldn't affect things.

I let it run for about 30 minutes, after which marlin panicked because it left my bed on and it hit the overtemperature cutout at 150c. It had been putting out the same numbers within ~1% for some time at that point.

Matt

unread,
Apr 6, 2012, 12:00:48 AM4/6/12
to make...@googlegroups.com

I've also had poor results with the marlin autotune. I've also noticed
that when you send a M301 to retrieve the current PID parameters, only
the proportional gain matches the value compiled in from
configuration.h. So are we supposed to compile in the numbers the
autotune gives us or..?

There are a few things I'm not sure about yet (haven't dug into the source)
- is the PID implementation interacting (proportional gain affects I & D)
- is the integral gain in repeats/min or min/repeat? kind of a big difference..

Triffid Hunter

unread,
Apr 6, 2012, 12:14:18 AM4/6/12
to make...@googlegroups.com
On Fri, Apr 6, 2012 at 2:00 PM, Matt <matt...@gmail.com> wrote:
I've also had poor results with the marlin autotune. I've also noticed
that when you send a M301 to retrieve the current PID parameters, only
the proportional gain matches the value compiled in from
configuration.h. So are we supposed to compile in the numbers the
autotune gives us or..?

yes, or use M301 to try them out 

There are a few things I'm not sure about yet (haven't dug into the source)
- is the PID implementation interacting (proportional gain affects I & D)
- is the integral gain in repeats/min or min/repeat? kind of a big difference..

dunno, I tweaked P until it oscillated a bit, tweaked D to stop the oscillation then tweaked I so it would actually sit right on the target instead of just below it.

Matt

unread,
Apr 6, 2012, 1:12:05 PM4/6/12
to make...@googlegroups.com
On Thu, Apr 5, 2012 at 9:14 PM, Triffid Hunter <triffid...@gmail.com> wrote:
> On Fri, Apr 6, 2012 at 2:00 PM, Matt <matt...@gmail.com> wrote:
>>
>> I've also had poor results with the marlin autotune. I've also noticed
>> that when you send a M301 to retrieve the current PID parameters, only
>> the proportional gain matches the value compiled in from
>> configuration.h. So are we supposed to compile in the numbers the
>> autotune gives us or..?
>
>
> yes, or use M301 to try them out

My issue is that, if I build and upload the firmware with:
#define DEFAULT_Kp 20
#define DEFAULT_Ki 0.3
#define DEFAULT_Kd 225

Then when I go online with the printer, I get:
>>>m301
SENDING:M301
ok p:20.00 i:2.29 d:29.49 c:0.13

So what is happening here? Do I ignore the firmware values and always
set the tuning parameters with M301?

Triffid Hunter

unread,
Apr 6, 2012, 6:48:40 PM4/6/12
to make...@googlegroups.com
On Sat, Apr 7, 2012 at 3:12 AM, Matt <matt...@gmail.com> wrote:
My issue is that, if I build and upload the firmware with:
   #define  DEFAULT_Kp 20
   #define  DEFAULT_Ki 0.3
   #define  DEFAULT_Kd 225

Then when I go online with the printer, I get:
>>>m301
SENDING:M301
ok p:20.00 i:2.29 d:29.49 c:0.13

So what is happening here? Do I ignore the firmware values and always
set the tuning parameters with M301?

Have you programmed some into the eeprom? Marlin supports saving and loading parameters using the chip's eeprom, which will overwrite default settings in flashed firmware

Joel Chia

unread,
Apr 15, 2012, 9:21:05 AM4/15/12
to make...@googlegroups.com
The current version of Marlin on github has eeprom saving/config disabled. So on reset you'll be using defaults.

As for the non correct I & D values, it's because Marlin manipulates the numbers before saving/printing them.
In Marlin.pde (1182):
if(code_seen('P')) Kp = code_value();
if(code_seen('I')) Ki = code_value()*PID_dT;
if(code_seen('D')) Kd = code_value()/PID_dT;
#ifdef PID_ADD_EXTRUSION_RATE
if(code_seen('C')) Kc = code_value();
#endif
updatePID();
SERIAL_PROTOCOL(MSG_OK);
SERIAL_PROTOCOL(" p:");
SERIAL_PROTOCOL(Kp);
SERIAL_PROTOCOL(" i:");
SERIAL_PROTOCOL(Ki/PID_dT);
SERIAL_PROTOCOL(" d:");
SERIAL_PROTOCOL(Kd*PID_dT);
#ifdef PID_ADD_EXTRUSION_RATE
SERIAL_PROTOCOL(" c:");
SERIAL_PROTOCOL(Kc*PID_dT);
#endif
SERIAL_PROTOCOLLN("");

Anyway, to allow settings to be saved to eeprom, look on configuration.h and uncomment "#define EEPROM_SETTINGS"



Cheers,
-Joel
Reply all
Reply to author
Forward
0 new messages