Marlin icon indicating copy to clipboard operation
Marlin copied to clipboard

PID

Open bkubicek opened this issue 12 years ago • 36 comments

the pid settings developed at madlab last week seem to have too little "umpf" for my machine. It never reaches the desired temperatures of M109 and waits forever.

bkubicek avatar Oct 30 '11 19:10 bkubicek

yes, the resulting temp is very much constant but always a few degrees lower than the target temp.

hurzl avatar Nov 02 '11 04:11 hurzl

i have more powerfull PID settings in the code since monday. If I have enough time this evening, I will try this: http://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method

bkubicek avatar Nov 02 '11 06:11 bkubicek

Using the following values: P1440 I52.3636 D9900 I get +-3 degrees.

I did do a short print (20mins) and it seemed to hold out quite well. Didn't notice the temps dropping by much when printing at 78mm/s & 50 mm/s (perimeters).

I'll test again with a longer print tomorrow night.

j-c avatar Nov 02 '11 12:11 j-c

just for reference: the settings derived from a adjusting session in Eindhoven, with non-extrusion: PID_dT 0.05 Kp = 750; Ki =10*PID_dT;
Kd = 0;

The badly adjusted settings I use right now: kp= 1000; Ki =100*PID_dT;

I would prefer to have meaningful PID values derived in the firmware: e.g. CriticalPID_P= aprox 1500; SwingPeriod= aprox 50;//seconds full wave osciliation time at CricticalPID_I

kp=0.6_CriticalPID_P; ki= 2 kp/SwingPeriod; kd=kp_SwingPeriod/8;

bkubicek avatar Nov 02 '11 13:11 bkubicek

jc's 1440<>55.3636<>9900 corresponds to a swing period of 52 sec, and a critical gain of 2400.

bkubicek avatar Nov 02 '11 13:11 bkubicek

with j-c's values i get a swing of +-9° while printing at ~220 degree, thin walled with a speed of 80mm/sec and a layer height of 0.1mm

bkubicek avatar Nov 02 '11 14:11 bkubicek

I have a pink-silicon insulated hot end, maybe also worth mentioning

bkubicek avatar Nov 02 '11 14:11 bkubicek

How about using a 4th term in the PID+C. C=factor*Extruded material mm^3/second. PID then could be adjusted at non-extrusion, and C is then adjusted thereafter for the extrusion only?

bkubicek avatar Nov 02 '11 15:11 bkubicek

I spend the last two hours PID-tuning, and have now some reasonables for P,I,D+the proposed C. It works with a +2°-3° variation on my machine, that features the pink silicone cap. Please everybody, try if this works for you aswell commit: https://github.com/bkubicek/Marlin/commit/786b83d2f4b01d8e04c30fe086fdea45e93e1485

bkubicek avatar Nov 02 '11 19:11 bkubicek

now I get 10 degrees more than wanted. i don't understand how it works, shouldn't it take the difference between wanted and measeured temperature into account? it should not heat at all if measured is higher

... in the meantime .. it should be higher to get the desired value at the filament? the results are brilliant, especially when I set 225°C for PLA, readings are about 239-242°C

hurzl avatar Nov 02 '11 20:11 hurzl

bkubicek, the "C" factor is quite like the bias (CO bias) in http://mbed.org/cookbook/PID Looking at your committed code, it seems your Kc is pretty much that. However that link doesn't explain how to calculate that bias value.

Btw, how are you measuring your swing time and delay values? I'm using a watch (seconds only) and watching the temp graph on the RepG (Printrun's temperate sample rate is too low).

hurzl, reason why it's heating even past the set point is that in a system, there might be delays between the controller output and a measured change from the sensor. Also in some cases it prevents the temperature from just plummeting and ended with a high frequency occiliation. However, this is only in theory. It depends on your PID constants.

Also, do you have any insulation and if so, what kind? And were those readings during printing or at rest?

I know there are self-tuning PID routines, but a cursory search hasn't yielded any implementation details yet.

j-c avatar Nov 02 '11 22:11 j-c

hurzl: Could you please try the tuning routine described in this post, and submit your results? Maybe my heater is different, I have serial #7 of the first batch, and it has a pink silicone cast enclosure for the hot end. An overshoot after initial heating is desirable IMHO, but after 4 minutes + extruding, 10° offset should not be. Maybe the Kc value is too high? This you could check if you also have the high offset if the machine in not extruding but only heating. Is there also this offset?


j-c: from what I understand, the bias is a constant value, while my kc is a proportionality to the extruder speed. The tuning procedure I followed yesterday was using my fancy lcd-panels, for convenience:

  • start repg, control panel, set temp to 220. Always push in a bit of pla from time to time, otherwise you risk clogging of the hot end. But not soo much that you cool the hot end dramatically.
  • look at the bed temperature=heater output right now (thanks to peter)
  • Set PID-D and PID-I to zero, and my K-c=0.
  • Set PID-p to 1500.
  • Wait if it stabilizes, viewable if the oscillations at the heater graph decrease in amplitude. You have to wait at least 3 periods to see whats going on.
  • it should stabilize at Kp=1500.
  • At Kp=2000, the oscillation amplitude grew. At 1900, the oscillation amplitude decreased slowly.
  • Then, I did the whole with my hot-end fan turned on. The result was a kp of 3000.
  • At the critical kp i measured the period of a full wave using a watch. it was 45 seconds with or without watch.

Because I print usually with the fan turned on, I used the kp_critical of 3000.

  • The wikipedia table linked further above was used to from that calculate the other values. Its done by define statements in the configuration.h.
  • While printing, I and used my LCD-interface to adjust my Kc so that a print with dramatic infill and skeinforge skin and slow perimeter caused no dramatic temperature drops in the infill. Also, I had a bit of constantly 5° too little. Which for me was solve-able by increasing the Ki a bit. Not sure why this is necessary.

bkubicek avatar Nov 03 '11 07:11 bkubicek

Yeah, but the CO bias doesn't have to be a constant. It can quite quite happily be a function really. Still, regardless what form it takes, I think it'd be easier to deal with that than try to figure out 2 different PID constants for fast and slow extrusions.

As for increasing the Ki, the K-N method isn't perfect. You'll still need to tweak the values, but it gives a good starting point. From my readings: http://www.mstarlabs.com/control/znrule.html Presents another set of rules in addition to the Z-N rule. I'll probably test out the Pessen Integral Rule and see how well the "default" behaviour is.

I'll also give your values a go when I get home and see how well that works out for me.

On Thu, Nov 3, 2011 at 5:04 PM, Bernhard Kubicek < [email protected]>wrote:

hurzl: Could you please try the tuning routine described in this post, and submit your results? Maybe my heater is different, I have serial #7 of the first batch, and it has a pink silicone cast enclosure for the hot end. An overshoot after initial heating is desirable IMHO, but after 4 minutes + extruding, 10 offset should not be. Maybe the Kc value is too high? This you could check if you also have the high offset if the machine in not extruding but only heating. Is there also this offset?


j-c: from what I understand, the bias is a constant value, while my kc is a proportionality to the extruder speed. The tuning procedure I followed yesterday was using my fancy lcd-panels, for convenience:

  • start repg, control panel, set temp to 220. Always push in a bit of pla from time to time, otherwise you risk clogging of the hot end. But not soo much that you cool the hot end dramatically.
  • look at the bed temperature=heater output right now (thanks to peter)
  • Set PID-D and PID-I to zero, and my K-c=0.
  • Set PID-p to 1500.
  • Wait if it stabilizes, viewable if the oscillations at the heater graph decrease in amplitude. You have to wait at least 3 periods to see whats going on.
  • it should stabilize at Kp=1500.
  • At Kp=2000, the oscillation amplitude grew. At 1900, the oscillation amplitude decreased slowly.
  • Then, I did the whole with my hot-end fan turned on. The result was a kp of 3000.
  • At the critical kp i measured the period of a full wave using a watch. it was 45 seconds with or without watch.

Because I print usually with the fan turned on, I used the kp_critical of 3000. Then, i put the wikipedia table linked further above, to from that calculate the other values. Its done by define statements in the configuration.h. Then I printed, and used my LCD-interface to adjust my kc so that a print with dramatic infill and skeinforge skin and slow perimeter caused no dramatic temperature drops in the infill. Also, then I found that I have a bit of constant temperature deviation. Which for me was solve-able by increasing the Ki a bit. Not sure why this is necessary.

Reply to this email directly or view it on GitHub: https://github.com/bkubicek/Marlin/issues/28#issuecomment-2613899

j-c avatar Nov 03 '11 07:11 j-c

from Peters mail:

I tested your latest build on my machine. I see some strange effects: +/- 2 degC oscilation. Strange discretesation of the measured value.

He had a picture of a sine wave +-2° with approx 10 discrete plateaus:

http://www.flickr.com/photos/bernhardkubicek/6308099445/in/photostream

I suspect that the P-d value is too large, so that noise in the ad-conversion causes discrete additional values. Still not sure if d is actually useful, maybe PI would be sufficient?

bkubicek avatar Nov 03 '11 07:11 bkubicek

From what I've read, PI is usually good. D is only good if it's well tuned.

On Thu, Nov 3, 2011 at 5:45 PM, Bernhard Kubicek < [email protected]>wrote:

from Peters mail:

I tested your latest build on my machine. I see some strange effects: +/- 2 degC oscilation. Strange discretesation of the measured value. He had a picture of a sine wave +-2 with approx 10 discrete plateaus.

I suspect that the P-d value is too large, so that noise in the ad-conversion causes discrete additional values. Still not sure if d is actually useful, maybe PI would be sufficient?

Reply to this email directly or view it on GitHub: https://github.com/bkubicek/Marlin/issues/28#issuecomment-2614127

j-c avatar Nov 03 '11 07:11 j-c

I have a different heater (I built a kind of "Uitistrap"). It has a smaller aluminum block, the thermistor is a bit nearer, and the heater a bit farer from the nozzle I think. Nozzle is also smaller, just a thread whith hole. Smaller thermal capacity. When it is not extruding the temperature is perfect. When extruding and I set it to 225 it reads from 237 to 244... I will try your numbers when I find time

hurzl avatar Nov 03 '11 12:11 hurzl

Hey bkubicek,

I tried your PID settings with a solid 20mm calibration cube. 195 degrees @ 78 mm/s I get between -4.08 & +2.27 degrees.

Also, using the Pessen Integral Rule, with your settings and a Kc of 9, I get a variance of -3.59 to +3.24 degrees. So it seems that with your settings, for me it undershoots a little more often.

Probably your insulation is better than mine :) I think I might have to up Kc a little for my setup.

j-c avatar Nov 03 '11 14:11 j-c

hurzl: if your heating system is different, the PID values you get are not valueable for the usual Ultimakers, because they will not be compatible in any direction.


currently I am working with a p=1360 i=1.2 d=0 and c=9, and its very +-1.5° stable on my insulated system while printing.

bkubicek avatar Nov 04 '11 12:11 bkubicek

indeed. hurzl, you probably should be looking at calibrating your own PID values since it sounds like it has different thermal characteristics than a stock one. The wikipedia link in this thread will give you some idea.

Pretty much you need to figure out your critical gain (aka ultimate gain) and your swing time (aka occiliation time/period) via experimentation. Unfortunately there isn;t any procedure that I could find to explain how to find the ultimate gain. I just did it by trial and error till I got the output (compiled the firmware with PID_DEBUG and the heater output gets printed as B:xxx aka the bed temperature). Then after a few periods if the amplitude seems to be the same, I start timing 1 complete period to determine the swing time.

After that you plug those numbers into the Zeigler Nichols method or the Pessen Integeral rule to get your base PID values.... Then follow the charts on the wikipedia article as a guide to hand tune the values after that.

j-c avatar Nov 04 '11 13:11 j-c

Ziegler-Nichols look doable, thanks

BTW. how do I get bed temperature back when I'm finished?

hurzl avatar Nov 04 '11 15:11 hurzl

You can do it via: M301 Pxxx Ixxx Dxxx

And if it works you'll either need to enter it into the firmware or save it to EEPROM (can't remember the code for that).

Cheers, -Joel

On 05/11/2011, at 1:07 AM, hurzl [email protected] wrote:

Ziegler-Nichols look doable, but I cannot set K_p by a gcode command? Do I have to reflash for every K_p?


Reply to this email directly or view it on GitHub: https://github.com/bkubicek/Marlin/issues/28#issuecomment-2631947

j-c avatar Nov 04 '11 15:11 j-c

please look a minute at the sourcode in the the git, i have already inpemented the formulas for the Ziegler-Nicholsm, PI, and PID, and in an earlier post i have exactly described how to do the tuneing procedure.

bkubicek avatar Nov 04 '11 15:11 bkubicek

can anyone tell me how to send commands via replicatorg? I am using pronterface.py but it has no graphical temp display

hurzl avatar Nov 05 '11 21:11 hurzl

have not tried: but create a empty file test.gcode open it in repg. you can edit the content there, build it =send, and then have a look at the control window. hopefully.

bkubicek avatar Nov 05 '11 21:11 bkubicek

wow this is terrible. how do you test your PID parameters?

hurzl avatar Nov 05 '11 21:11 hurzl

with my fancy-pancy panel. Helps a lot for that. but still it took ~2h

bkubicek avatar Nov 05 '11 21:11 bkubicek

bkubicek, do you know why pTerm, iTerm and dTerm are all divided by 100? As far as I can tell from wikipedia's PID article, and looking at what the math is attempting to do, this doesn't seem necessary and adds 3 more mathematical operations to compute. Or was that in the original Marlin code?

j-c avatar Nov 06 '11 03:11 j-c

I am also using the default PiD values from 81202a8, and get about +15 deg... still prints OK (base was 215)

jgeerds-zz avatar Nov 08 '11 02:11 jgeerds-zz

I'm assuming your heater isn't insulated?

Mine is insulated differently and I have to use different PID settings. Best bet is to try to figure out the critical gain (or ultimate gain) and the swing time and determine your own PID constants (or PI in this case).

I wonder if this is a case for implementing some kind of PID auto tune... even if it's just to get base/sane values for a given setup.

On Tue, Nov 8, 2011 at 12:08 PM, jgeerds < [email protected]>wrote:

I am also using the default PiD values from 81202a8, and get about +15 deg... still prints OK (base was 215)


Reply to this email directly or view it on GitHub: https://github.com/bkubicek/Marlin/issues/28#issuecomment-2662927

j-c avatar Nov 08 '11 02:11 j-c

j-c: my heater is well insulated (8mm silicone foam), but I also have a different 50W heater than the 40W stock model heater. but the only difference should be the attack (heater power) and the dampening (insulation)... not the permanent landing temp (which stayed at +15 deg for 60 minutes printing).

jgeerds-zz avatar Nov 08 '11 03:11 jgeerds-zz