Extruder PID Temperature Controller 7

Posted by Tim on September 30, 2009

After getting my extruder running, I noticed that the drive was struggling a bit. I could hear the motor working harder, and the filament would start slipping. The problem didn’t happen all the time — just periodically. That first got me thinking that the drive bushing wasn’t engaging the filament evenly. But then I noticed that the problem was synchronized with the blinking of the heater drive LED. Hmm…

Is it possible that the extruder temp was falling low enough during the heating cycle that the drive would have trouble pushing it through the extruder?

Mostly out of curiosity, I began to investigate the heater controller code. After a bit of poking around the code and tinkering with the thermistor location, I wasn’t quite satisfied with the temperature control, I decided to try to improve it a bit by implementing a PID controller. At the time, I also stumbled across the BareBones Coffee Controller which uses an Arduino to control the temperature of coffee and espresso machines and has a nice GUI temperature monitor.  With a bit of tweaking, I was able to hook up the monitor to my extruder controller and do some experimenting.

Here’s a plot of the default bang-bang temperature control operating on my machine: (click image for larger version)

Extruder default (bang-bang) temperature control

This shows the controller taking the heater temperature from ~50C to a target temp of 220C. The blue line shows the heater control PWM output (0-255). You can clearly see how the bang-bang control switches between high and low settings when the temperature crosses the target.

Now here is a plot of the PID controller in operation:

Extruder temperature PID control

The target temperature is reached a bit slower, but with minimal overshoot. And when it is up to temp, the temperature error is greatly improved.

The heater control looks very erratic (and it is!), but I found that the spikes are from the D (damping) term which is a function of the temperature rate of change. Since the temperature sampling produces a relatively low resolution discrete value, the temperature changes in steps. And each of these steps looks like a big rate of change of temp to the controller. What is interesting is that it still works well. When I take out the damping term, I have more overshoot, so the term is still doing what it should.

Selecting good PID gains was a bit painful due to the slow moving plant. I’m not at all sure that I’ve got gains that are even close to optimal. But I’ve been using the controller for the past week, and it seems to work fine as it is.

Could the performance of the default bang-bang controller be improved? Most definitely. This is somewhat an unfair comparison because I did a lot of tweaking of the PID parameters, but didn’t change the default heater_high and heater_low parameters at all.

I’ve made the code for the PID controller available here as a patch to the arduino slave firmware. I’m working off the Makerbot svn codebase. The default controller or the PID controller can be selected at compile time.

To run the monitor, you need to connect your serial line directly to the extruder (the monitor can’t be used during normal printing operation — it is just for testing). I’ve included the ability to change target temp, toggle the motor on and off and change direction, and a few other things from the monitor. The code is available here.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Open Source FTW - MakerBot Industries Thu, 01 Oct 2009 14:45:47 GMT+7

    [...] Tim at BotHacker coded up a patch which implements PID on the heater.  The result is much, much better temperature control, yielding a smoother extrusion and less [...]

  2. Geert Bosch Mon, 05 Oct 2009 12:23:14 GMT+7

    Hi Tim,

    You beat me to the punch. I had cooked up my own PID code, but not yet published it, as I decided to first redo the temperature reading code to get high resolution readings. I’ll try merging that with your changes, so we’ll have better info for the D part of the signal.

    -Geert

  3. Matt Tue, 13 Oct 2009 14:58:11 GMT+7

    Looking good. Whenever you get a chance put up the video of it moving !

  4. Prober Wed, 09 Dec 2009 09:32:58 GMT+7

    You made my day! Great thinking. Just wondering could a second temp reading i.e. the temp of the air inside the cabinet be sent to the Arduino to control the temperature?

  5. Tim Thu, 10 Dec 2009 14:34:49 GMT+7

    I’m working on a two channel temperature controller board right now. I’ve got it assembled and working here on my desktop. More info soon…

  6. madscifi Mon, 05 Apr 2010 23:17:16 GMT+7

    I’m not an expert on PID design, but it seems that the code is taking the derivative of the input (temperature) and not of the error. Is there a reason for this?

    Fragment of code:

    dTerm = temp_dGain * (current_temperature – temp_dState);
    temp_dState = current_temperature;

    I would expect the fragment to be:

    dTerm = temp_dGain * (error – temp_dState);
    temp_dState = error;

    Bug in the code or a bug in my understanding of PID?

    –Jim

  7. madscifi Tue, 06 Apr 2010 19:48:11 GMT+7

    … and the answer turns out to be a bug in my understanding. If I had spent 30 seconds to work out the algebra, I would have known that the two different approaches actually calculate exactly the same thing.

    I’m going to go hide under a rock now.

Comments