bkubicek / Marlin

Reprap FW optimized for gen6
17 stars 1 forks source link

PID #28

Open bkubicek opened 12 years ago

bkubicek commented 12 years ago

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.

hurzl commented 12 years ago

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

bkubicek commented 12 years ago

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

j-c commented 12 years ago

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.

bkubicek commented 12 years ago

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 commented 12 years ago

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

bkubicek commented 12 years ago

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 commented 12 years ago

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

bkubicek commented 12 years ago

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 commented 12 years ago

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

hurzl commented 12 years ago

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

j-c commented 12 years ago

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.

bkubicek commented 12 years ago

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:

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

j-c commented 12 years ago

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 < reply@reply.github.com>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

bkubicek commented 12 years ago

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?

j-c commented 12 years ago

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 < reply@reply.github.com>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

hurzl commented 12 years ago

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

j-c commented 12 years ago

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.

bkubicek commented 12 years ago

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.

j-c commented 12 years ago

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.

hurzl commented 12 years ago

Ziegler-Nichols look doable, thanks

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

j-c commented 12 years ago

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 reply@reply.github.com 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

bkubicek commented 12 years ago

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.

hurzl commented 12 years ago

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

bkubicek commented 12 years ago

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.

hurzl commented 12 years ago

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

bkubicek commented 12 years ago

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

j-c commented 12 years ago

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?

jgeerds-zz commented 12 years ago

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

j-c commented 12 years ago

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 < reply@reply.github.com>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

jgeerds-zz commented 12 years ago

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 commented 12 years ago

jc: but auto tune would be awesome, the PiD in my espresso machine has it, and I love it.

j-c commented 12 years ago

There might be a case of the speed bias. If you look in configuration.h, there'll be a variable called Kc (default is 9 I think). This is a multiplier of sorts that adds a bias to the output based on your extrusion speed. Try dropping it lower.. M301 doesn't change it yet unfortunately.

If there's a systematic and reliable way to determine the ultimate gain, the initial auto-tune should be easy to implement. I'm still researching auto-tuning PID controllers.

On Tue, Nov 8, 2011 at 1:39 PM, jgeerds < reply@reply.github.com>wrote:

jc: but auto tune would be awesome, the PiD in my espresso machine has it, and I love it.


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

j-c commented 12 years ago

I might be making some headway on this... Wrote up a function to gather test data for auto-tuning PID. Seems to work reasonably well, but slow changing and/or noisy temp data is making it annoying to automatically determine numbers.

When I sort that issue out I'll attempt to push it and submit a pull request.

hurzl commented 12 years ago

for those not using PID, could you change lines from 976 in Marlin.pde like this to get the bed temp display back:

    Serial.print(current_raw);       
      #if TEMP_1_PIN > -1 
        Serial.print(" B:");

ifdef PIDTEMP

        Serial.println(HeaterPower); 

else

        Serial.println(bt);

endif

      #else
        Serial.println();
      #endif
jgeerds-zz commented 12 years ago

I found this PiD simulator: http://forums.reprap.org/read.php?147,102633

would this be helpful in this context?

joergen

j-c commented 12 years ago

Success! Or sort of. The basic idea is fine, just can't seem to get the correct process time (which at the moment appears to require me to store a very long array and run out of memory). But after graphing out the data and getting the correct process time, the generated PID+A settings are fairly good at the steady state (around 0 - 4 degrees above the set-point).

Also, I'm having minor issues trying to programtically find the required heater output (steady, not PID or bang-bang) to hit and maintain a certain temp. When finding the various tuning constants, I think it's recommended that you use the output level to hit your desired state. However, I aimed for 190, but got 240... results still seemed good.

What's this "A" I speak of? It's the heater output filter. I still haven't quantified that it works better, but I get the impression that it does.

Other changes that I had to do was add the temperature error (aka target_raw - current_raw) as the CObias in addition to your "C" extrusion speed bias.

bkubicek, after I clean up the code, shall I submit a push to your repository (and after I figure out how to do that)... I'd like for other brave souls to test this out as well.