Posts Tagged ‘ pid

Building the C-Bot 3d Printer : Part 38 : PID Autotune on RepRap Firmware, fix z-artifacts

Jump to C-Bot blog index to see all the posts.


In my last post on the subject, I described how I completely rebuilt my C-Bot printer.  The main goal was to get better print quality based on some odd z-artifacting I’d been experiencing for some time.  But, the z-artifacing still persisted.

This post is to talk about both the solution to the artifact issue, and how to PID Autotune your hotend and heated bed with RepRap Firmware.

Solving the Z-artifacting

After the rebuild, the z-artifact was still there.  Was so frustrating to have a machine that printed so well, yet on the Z-axis, I’d get this:

z-ringing <- Click on it to make bigger, and look on the inside of the print.

The real oddity was that the artifact didn’t match the pitch of my leadscrew, which seemed like the obvious culprit, and the period of the artifact could vary based on what you were printing.  For example, a 20mm calibration cube showed off the issue much more than the above cylinder.  And it was more of a square-wave, not an s-curve.

3D printer people to the rescue:  I posted my issues to the ‘3D Printer Tip, Tricks and Reviews‘ Google Group, and through a lot of back and forth discussion (thanks JetGuy + several others), the users figured it was either one of two things:

  • Thermal expansion of the bed during the bang/bang heat cycle was causing these anomalies.
  • The hit the heated bed was making on my power supply:  When I built my machine 2 years ago I was recommended a fancy PC power supply (Corsair CTX 500), but as it turns out, this may not have been the right choice for a 3D printer.

Check Thermal Expansion

To troubleshoot the thermal expansion, user Joseph Chiu suggested a great idea:  Shine a laser off a mirror on the bed during the heat cycle, and track the dot on the wall.  If the dot moves during the bang/bang cycle, then it’s thermal expansion.  So, I gave it a shot:  Heated up the bed, waited for the temp to start banging back and fort, and then stared a dot on the wall…

frikkin_lasers The ol’ Replicator1 served as a based for the vice holding the laser.

That laser was bright, so I moved the mirror so it hit a “splotch” on it, and gave a nice diffusion pattern on the wall.  This was much easier to look at, and track the specks to see if the changed / moved : The did not.  This is not a thermal expansion issue.

Check Power Supply

The easiest way to check if this is a power supply issue?  Just ‘not print with the heated bed on’:  I normally always do, at 60c:  Not required, but sometimes helps large PLA prints stick better over time.

So, I did the same cylinder print with no heated bed and: The z-artifacting was gone!  Can’t believe I’ve been having this issue for a year-ish, and never realized it was the amp-draw the heated bed puts on the PSU, even though the PSU is rated for it, based on numbers.

Compare PID Tuning vs no heatbed

One thing I’d never done since upgrading the bot to RepRap Firmware, was PID autotune the hotend, or bed:  The defaults seemed fine, and the temp curves as shown in my slicer seemed “good enough” : I could easily see the bed overshoot based on the bang/bang setup, and a slight wobble on the hotend.  But I figured this would be a good time to PID autotune both the hotend and bed (discussed in more detail in the next section):  Would this help any of the z-artifacting?

Why, in fact it does.  Here’s a comparison shot:

print_compare

‘Bed off’ and ‘Bed with PID Autotune’ are nearly the same:  The artifacing caused by the bang/bang is completely removed, and only a very slight, larger-period artifact remains (which I’m happy enough with at this point).

I should also note that my temp curves, for both hotend and bed, are now dead flat.  PID tuning completely makes a difference.

However, I noticed that while the pid-tuned bed works, the LED strips on my bot flicker with the same frequency as the SSR controlling the bed:  The same power-hit that caused the bang/bang artifact is still there, it’s just happening at such a high rate, the artifact is being averaged out of existence.

For future improvement, I need to choose one of these:

  • Get a separate power supply for just the 12v bed.
  • Switch to an entirely separate 120v AC heated bed.  This is the option I’m currently investigating.
  • Switch all my electronics out to 24v (ugh).

But in the meantime, at least the stupid z-artifact is gone.

PID Autotune your hotend and heated bed in RepRap Firmware

These are the steps I went through to PID autotune my hotend and heated bed in RepRap Firmare:  None of it hard, just took a good amount of digging online to figure out what exactly needed to be done.

In RRF gcode, ‘H’ Is the heater number: H0 is the bed, H1 is the first hot end, H2 the second etc.

PID Autotune the hotend

To PID autotune the hotend, these were the steps I took:

  • Position nozzle over bed
  • Turn on cooling fan 50% to simulate real printing environment.
  • Start with a cold hotend.
  • Enter this gcode, + the result returned as it’s ran:
    • I chose 230c as the target temp, since I print a lot of filament at that temp.
    • If you get an temp overshoot error during the tune, you may need to add / adjust your M143 in config.g:  The default value for hotends is 262c.

M303 H1 S230
READ: Auto tuning heater 1 using target temperature 230.0C and PWM 1.00 – do not leave printer unattended
READ: Auto tune phase 2, heater off
READ: Auto tune phase 3, peak temperature was 234.6
READ: Auto tune heater 1 completed in 228 sec
READ: Use M307 H1 to see the result, or M500 to save the result in config-override.g

  • Then entered this gcode, the result returned as it’s ran:
M307 H1
READ: Heater 1 model: gain 325.3, time constant 117.3, dead time 5.0, max PWM 1.00, mode: PID
READ: Computed PID parameters for setpoint change: P12.9, I0.110, D45.0
READ: Computed PID parameters for load change: P12.9, I1.026, D45.0
  • Finally entered this gcode to save the results out to config-override.g
M500
  • Which in turn, added this info (actually more, but this is what’s important to this operation) to config-override.g
M307 H1 A325.3 C117.3 D5.0 S1.00 B0 
  • Note, the B0 = PID tuned.  B1 = bang/bang.

PID Autotune the heated bed

To PID autotune the heated bed, these were the steps I took.  Note, it’s very similar to the hotend above.

  • Start with a cold heated bed.
  • Enter this gcode, + the result returned as it’s ran.
    • I chose 60c as the target temp, since I print a lot of filament at that temp.
    • If you get an temp overshoot error during the tune, you may need to add / adjust your M143 in config.g:  The default value for heated beds is 125c.
M303 H0 S60
READ: Auto tuning heater 0 using target temperature 60.0C and PWM 1.00 - do not leave printer unattended
READ: Auto tune phase 2, heater off
READ: Auto tune phase 3, peak temperature was 61.2
READ: Auto tune heater 0 completed in 1105 sec
READ: Use M307 H0 to see the result, or M500 to save the result in config-override.g
  • Note, it took forever for this to finish, since it wants the bed to cool down before it completes.  I had to point a fan at it to help it along after ‘phase 3’.
  • Then entered this gcode, the result returned as it’s ran:
M307 H0
READ: Heater 0 model: gain 111.6, time constant 814.0, dead time 20.5, max PWM 1.00, mode: PID
READ: Computed PID parameters for setpoint change: P63.5, I0.078, D911.1
READ: Computed PID parameters for load change: P63.5, I1.082, D911.1
  • Finally entered this gcode to save the results out to config-override.g
M500
  • Which in turn, added this info (actually more, but this is what’s important to this operation) to config-override.g
M307 H0 A111.6 C814.0 D20.5 S1.00 B0
  • B0 = PID.  Previously, it was B1, bang/bang.

Configure config-override.g

The M500 command entered above does a live update to the config-override.g script living on the SD card, which is a great feature.  However, I’d never used this feature before, so my config.g had no idea to execute this script.

To do so, simply (I did mine a the bottom), enter this gcode in your config.g

M501

This will then execute the contents of config-override.g from within your config.g, when the machine boots up.

Optionally, you could simply copy the M307 lines (as generated by M500) from config-override.g and paste them directly into config.g, and remove the M501 call.  Either will work.

PID Autotune related gcodes

  • M135 : Set PID sample interval
  • M301 : Set PID parameters
  • M303 : Run PID Tuning
  • M304 : Set PID Parameters – Bed  :  This command is identical to M301 except that the H parameter (heater number) defaults to zero.
  • M307 : Set or report heating process parameters

Jump to C-Bot blog index to see all the posts.

C-Bot 3D Printer: Supercharging the Volcano

Jump to C-Bot blog index to see all the posts.


When I installed the 1.2mm E3D-v6 Volcano nozzle, I noticed that when my PLA cooling fan kicked on, the hotend would have a really hard time maintaining temp running at a ‘high’ (45mm/sec) extrusion speed (for the Volcano):  If starting at 220 deg, when the fan would kick on it would just drop and drop, and I’d stop the print or kill the fan when it hit 200 deg.  If I dropped the speed down to say, 10mm/sec, it could keep up.  This made me think fan+cold filament was too much for the hotend.

After much discussion on Google+ (here, and here), I tried a variety of things, none that got it working 100%.  I re did the Marlin auto-PID with the fan on full blast:  This got it to the point the temp would drop some 10-15 deg, then slowly creep back up.  But this is far from optimal.

The thing that tipped me off was the suggestion to figure out what the power is of the heater-cartridge in my Volcano hot-end:  Measuring the resistance gave me 7.1 ohm, which equal to 20.3w (voltage^2 / resistance = 12v*12v/7.1 = 20.3w).  Checking online, I noticed that there are 40w heater cartridges as well, so I picked one up (I got that one simply because it could be shipped via Amazon Prime…).  Installation ensued:

volcanoUpgrade

And that my friends, is the secret sauce:  After I got the new heater cartridge installed, I re-ran the PID-Autotune in Marlin (via Simplify3D)…

M303 E0 S200 C8

…waited a number of minutes for it to finish, then crammed the three values back into my Configuration.h, uploaded that via the Arduino IDE to the Rumba, and I was in business:  Not only does the hotend heat up faster now (220 deg in 1min 50 sec with full fan compared to 2 min 30 sec with no fan), but I can maintain hotend temp with 100% 24cfm fan kicked on.  It’ll drop maybe 3 deg when the fan blasts on, then pull right back up to temp.

So a note to any of you Volcano users:  Make sure you have the 40w heater cartridge (the one with the red leads) not the 25w one (blue leads).

I measured the new heater before I put it in:  4.1 ohm resistance, which equals 35w, not 40w.  But it works, so I’m happy :)

Another thing learned:  When you issue a M105, and get something like this back:

RECEIVED: ok T:206.1 /220.0 B:26.0 /0.0 T0:206.1 /220.0 @:127 B@:0

The @:127 is the ‘power’ going to the hotend.  Note that 100% = 127, not 255, in this instance.


Jump to C-Bot blog index to see all the posts.

Building the C-Bot 3D printer: Part 21 : Software Day 4: PID Autotune & start/end G-Code

Jump to C-Bot blog index to see all the posts.


Total time : 2.5 hours

Even though I need to really un-spaghetti the machine and do the final wiring, I can’t help but want to print more, especially since I installed & tuned the DRV8825 stepper drivers:  I want to make sure they actually work!

Start & End G-Code

At the same time, I wanted to create better start & end G-Code for the bot:  I slice & print using Simplify 3D (S3D):  When you create a new custom printer profile, for the start G-Code, all it does is a G28:  Auto-home.  It seems to take care of the extruder and bed heating for you.

In addition, even though I’d previously figured out how in S3D you can set ‘global G-Code offsets’ in its G-Code tab, which lets you define the offset between home and the build platform, I thought it’d be better to set it in the start G-Code instead. I don’t know why, but it feels safer in there…

I’ve never done any start\end G-Code ‘programming’ before. The start/end G-Code for my Replicator1 was already setup.  So heading off to the ‘G-Code in Marlin‘ page, I researched what I wanted it to do on start:

  • Lower the bed a bit just in-case it hadn’t before
  • Home all axes
  • Warm up the extruder (and eventually heated bed)
  • Purge the nozzle
  • Move nozzle to edge of the bed and zero it (per the above paragraph).
  • Start print

And on end:

  • Turn off extruder and bed heating
  • Lower the z-platform slightly
  • Home XY
  • Disable motors

Another great resource is S3D itself:  Once you’ve connected to your machine, and are in the Machine Control Panel, any commands you issue show up in the Communication log:  So I set about doing each step manually, then creating the G-Code script for them.

What I came up with is currently below.  I’m sure this will change in the future.  But just in case my computer explodes I’ll have a backup here.  Note that [stuff in brackets] is S3D’s own internal syntax for embedding variables to help make the gcode more temperature agnostic.  Pretty nice.

Start G-Code:

G92 Z0 ; Set current z position to zero.
G1 Z20 ; Lower Z to be safe 20mm.
G28 ; Safe Homing of All Axes
M104 [extruder0_temperature] T0 ; Set extruder targe temp
M109 S[extruder0_temperature] T0 ; Wait for extruder current temp to reach target temp.
G1 E50.0 F600 ; Purge nozzle 50mm at 10mm/sec
G92 E0 ; zero extruder
G1 X2 Y26 ; Move nozzle to left front corner of build platform.
G92 X0 Y0 ; Zero X & Y here to start the build.

End G-Code:

M104 S0 ; turn off extruder
M140 S0 ; turn off bed
G92 Z0 ; Set current z position to zero.
G1 Z10 ; Lower Z to be safe 10mm.
G28 X0 Y0 ; Home XY
M84 ; disable motors

So I fired off my first print over USB, and ran into all sorts of weird problems over the next hour.  Long story short:

Gotchas:

  • Every time I change a setting in S3D and want to re-print, I need to turn my printer off and on.  I don’t know if this is a S3D bug, a Rumba bug, a Marlin bug, or what.  But if I don’t do this, the start G-Code won’t properly execute.  Side effects include it not heating and immediately starting a print, or heating up but then never beginning the print after it.
  • Once that was resolved, for the longest time I couldn’t get the filament to stick to the bed:  it would just curl up around the extruder.  I finally realized that a new profile I’d setup had my layer height set to 200 micron… printing with a 1mm wide Volcano nozzle:  Once I set that back to 500 micron the printing had no problems.
  • I really need to get a print-cooler fan installed:  I built a custom one for my Replicator 1 which has really helped.  When I finally got my printing working, and was working on a 2cm test cube, the sides looked pretty good for effectively my second print:
    • not too bad
  • But when it got to the top, the whole print was so hot that the extruded top layer filaments literally started grabbing & collapsing the side-walls.  Plus when I went to remove it when the print was done, it was soft like warm gummy bear:
    • aaaugh
  • Top priority: Get print cooler fan installed.  Or maybe a jet of liquid nitrogen…. :)

PID Autotune:


Update:  Since authoring this post I have switched my electronics to RADDS, and my firmware to Repetier.  See the “Part 31 post” for the latest on it.


 

While my extruder has been heating up fine, I noticed that as it approaches the target temp (say, 200c) it really slows down for the last few degrees, and takes a long time getting to the final temp.  I remember that when I switched my Replicator 2x to Sailfish firmware, the extruders stopped heating up correctly, and talking on the forums they told me I needed to update my PID settings.

PID stands for “proportional-integral-derivative“, something I did not learn about in math class.  But in a nutshell it’s a way via the maths to reach a target value smoothly and quickly, without banging/oscillating all over the place.  And luckily, Marlin comes with a PID autotune feature you can run as G-Code directly from S3D (or any software that can issue G-Code):

M303 E0 S200 C8

Fire that off when you extruder is cold, and a few minutes later it’ll spit out something that looks like this:

Recv:  bias: 213 d: 41 min: 199.38 max: 200.71
Recv:  Ku: 77.96 Tu: 13.40
Recv:  Classic PID
Recv:  Kp: 46.77
Recv:  Ki: 6.98
Recv:  Kd: 78.32
Recv: PID Autotune finished! Put the last Kp, Ki and Kd constants from above into Configuration.h

And those values you then enter back into Marlin’s Configuration.h file.

These were my original values when I authored this blog post:

#define DEFAULT_Kp 46.15
#define DEFAULT_Ki 5.10
#define DEFAULT_Kd 104.32

UPDATE (2016-01-13) :  But I found when my powerful 24cmf cooling fan would kick on to cool the Volcano nozzle, the temp would drop, and it would take a loooong time trying to catch back up.  So instead, I cranked my fan to 100% (255) and re-running the auto-pid gave me the values in the code snatch two paragraphs up.

I never timed the nozzle warmup before, my E3d-V6 Volcano now heats up from cold to 200c in 2min 10 seconds:  Not too bad.

I’ve still not got my heated bed soldered up yet (waiting on 10-gauge wire in the mail), but I’ll run this again on the bed when it’s ready.


Jump to C-Bot blog index to see all the posts.