Creating 3D models is hard

3D printing is easy. You can buy a 3D printer off the shelf for a few hundred of your Earth pounds, download patterns from thingiverse and be printing solid stuff straight away. Creating your own 3D models is harder, and it seems to me that this is now the bottleneck (at least, if you don’t want to spend a lot of money). There are several options. You can scan a real item, if you have a 3D scanner, and then use really awkward tools to manipulate the mesh. You can persuade powerful and confusing tools for animation and modelling like Blender to create models. You can use infuriatingly limited free versions of commercial tools like Sketchup. Or if you have really deep pockets, you can buy a proper CAD system.

I don’t like any of the above. I’m a programmer, and have a mechanical engineering background. I want to create precise, preferably parametric, models of components which I can then print out and fit together with other components to make machines. Up till now, I’ve been using OpenSCAD, and it’s been pretty good. OpenSCAD allows you to define shapes precisely using numbers, and combine them exactly (wrong word, I know) to create useful things. I love it. But it’s always had one major flaw (and a few little ones, but that’s another story). Building a model in OpenSCAD is like writing a program: it supports functions and loops, but it doesn’t support variables. At least not variable variables. You can assign a value to a variable and use it later, but that value cannot change. This is a bit of a pain, and it limits what you can do. Now there is an alternative, and that makes me happy.

The new kid on the block

OpenJSCAD is an entirely browser-based (yes, you read that right) editor and renderer for 3D models. It uses a language quite similar to OpenSCAD (indeed, it can import OpenSCAD files), but more powerful and a bit like C. And it supports proper variables. Hurrah! Here’s a screenshot of a little something I knocked up in it:

screenshot_4

Try doing that in OpenSCAD. I did, and the spiral ramp was not easy. Here’s an assembly of a few of them, printed out and stacked together. A ball bearing runs around them very nicely:

ball chute

Try OpenJSCAD. If you don’t like it, I’ll give you your money back.

Here’s my .jscad file which created the ball chute. You can simply cut the text and paste it into OpenJSCAD if you want to try it.

// title: Spiral ball bearing chute
// author: Peter Robinson
// license: None.  Free for all.
// description: A stackable spiral chute for ball bearings.

var radius = 50;
var slotwidth=6;
var wallthickness=1;


function main(params) {

    var a=2;
    return union(
        section(),
        section().translate([0,0,20]).rotateZ(90),
        section().translate([0,0,40]).rotateZ(180),
        section().translate([0,0,60]).rotateZ(270)
        );

}

function section(){
    return union(
        ramp(1,11,radius-4,radius-4,4),
        ramp(6,11,radius-3,radius-3,1),
        ramp(1,11,radius+3,radius+3,6),
        hub()
        );

}

function hub(){
    return  difference(
        union(
            CSG.cylinder({
            start:[0,0,0],
            end:[0,0,10],
            radius: 10,
            resolution:36
            }),
            CSG.cylinder({
            start:[0,0,10],
            end:[0,0,15],
            radiusStart: 8,
            radiusEnd: 7,
            resolution:36
            }),
            spoke().rotateZ(-27.5),
            spoke().rotateZ(-27.5-45).scale([1,1,0.5])
        ),
        union(
            CSG.cylinder({
            start:[0,0,-1],
            end:[0,0,17],
            radius: 6,
            resolution:36
            }),
            CSG.cylinder({
            start:[0,0,-0.5],
            end:[0,0,5.5],
            radiusStart: 7.9,
            radiusEnd: 6.9,
            resolution:36
            })
        )

    );
}

function spoke(){
    return CSG.cube()
        .scale([radius/2-slotwidth/2,1,5])
        .translate([-radius/2,0,5]);
}

function spiral(){
    var hex = CSG.Polygon.createFromPoints([
            [0,slotwidth/2, 0],
            [0,-slotwidth/2, 0],
            [0,-slotwidth/2, radius],
            [0,slotwidth/2, radius]
    ]).setColor(
        [0, 0.8, 0]
    );
    var angle = 5;
    return hex.solidFromSlices({
        numslices: 365 / angle,
        callback: function(t, slice) {
            var coef = 1 - t * 0.8;
            return this.
            translate([0 , radius, t*10]).
            rotateZ(angle * slice);
        }
    });

}

function ramp(slotwidth,climb,innerradius_start,innerradius_end,basethickness){
    var hex = CSG.Polygon.createFromPoints([
            [0,0, 0],
            [0,slotwidth, 0],
            [0,slotwidth, 1],
            [0,0, 1]
    ]).setColor(
        [0, 0.8, 0]
    );

    var base = CSG.Polygon.createFromPoints([
            [0,0, 0],
            [0,slotwidth, 0],
            [0,slotwidth, 1],
            [0,0, 1]
    ]).setColor(
        [0, 0.8, 0]
    );
    var angle = 5;
    var radiuschange = innerradius_end-innerradius_start

    var bottom = base.solidFromSlices({
        numslices: 95 / angle,
        callback: function(t, slice) {
            return this.
            translate([0 , innerradius_start +t*radiuschange, 0]).
            scale([1,1,basethickness]).
            rotateZ(angle * slice);
        }
    });

    var spiral = 
        hex.solidFromSlices({
        numslices: 95 / angle,
        callback: function(t, slice) {
            return this.
            translate([0 , innerradius_start +t*radiuschange, 0]).
            scale([1,1,climb*(0.1+t*0.9)]).
            rotateZ(angle * slice);
        }
    });


    return union(
        bottom,
        spiral.translate([0,0,basethickness])
    );

}

Lathe parts online

Some people (honestly, more than one) have asked for the source files for the parts for the 3D printed lathe. I’ve posted them under the OpenSCAD tab. There’s a direct link here. Don’t forget the Youtube video if you want to see it in action.

It’s not my fault!

It’s probably not my fault, at least.

If you’ve been following my blog (and why wouldn’t you?), you’ll know that I have had some issues with my 3D printer printing things skewed. It got particularly annoying a day or two ago when a five-hour print ended up unusable. It’s about time I got this problem sorted out. Annoyingly, it seems that every time I do a test print, the problem goes away. Indeed, a test print after the last failure was absolutely fine. Perhaps it is time to apply logic, and isolate the causal factor. My test prints tend to be small (so that they are quick and cheap), but I notice (or perhaps only care about) the problem on large objects which take a long time to print. This morning, I printed a set of test objects of increasing size, to see if the problem was size related. The objects I used as test pieces were simple hollow square-section blocks, connected by a thin strip. The model looked like this:

test_pieces

I printed each of the pieces individually, smallest first. The results were very interesting:

size-based distortion 2

size-based distortion 1

As you can see, the first three parts printed fine (I’m not worried about the finish quality, just the geometrical straightness). Only the largest one had any skew at all. The really weird thing is that the skew was pretty constant over the entire width. To me, this strongly suggests a printer firmware issue. If the hardware were misaligned, or a drive were slipping, I would expect to see this on all the prints. A structural problem would surely show up gradually as the parts grew bigger, or possibly show up more the further from the centre the print head moved. In fact, the skew at the centre is the same as the skew at the ends of the part, and there is no skew at all on the second-largest component.

So if the problem is not the hardware (that’s why it’s not my fault šŸ™‚ ), what is it? It could be the slicer, but this seems unlikely because I have used both Slic3r and Cura. Printing gcode files from either can have the problem. This seems to leave only one culprit: the printer firmware. I’m thinking that there is some rounding error, or some motor step-counter in the firmware which is overrunning or accumulating a consistent error on long print head movements. As the print head moves back and forth along the x-axis, this error fails to get reset between z-slices. Each layer is slightly offset from the one before. With smaller parts, this error simply does not occur. This is speculation at the moment.

I’m currently using Marlin firmware. My install is at least a year old, so my first step will probably be to upgrade to the latest version. This might be a bit of a pain, because I made a few customisations when I installed the last version, to suit my printer. If that doesn’t sort the issue out, I’ll have to delve into the source code. At least Marlin is open source, so I can fiddle with it.

Disappointment is…

… finding your five-hour print is faulty

Hmmm. Yesterday I replaced the heater in the printer’s hot end, vastly improving printing. Today I replaced a faulty power switch, reducing the chance of the printer cutting out mid-print. There seemed to be no reason not to make a start printing some of the bigger components I’ve been working on. Here’s the first one:

large thing 01

Don’t worry what it is. All will be revealed eventually. it’s a substantial bit of plastic, and demonstrates why I wanted to build a 3D printer in the first place. How else could I make components like that without a proper machine shop? I still want a proper machine shop, by the way, but I love the fact that I can make lightweight, stiff components straight from CAD models. I mean, just look at it.

large thing 02

So, you might think all is well. This component took five hours to print, and the printer didn’t miss a beat. What it did do, however, is print the whole thing skewed. It’s not immediately obvious, but look at this:

disappointment 01

and this:

disappointment 02

Makes you want to cry, doesn’t it? Both of those sides should be vertical, in case you didn’t realise. In fact the whole thing has been printed with a slant on it. I’ve had this problem before, but I thought I’d cured it by increasing the tension in the drive strings (the fault being that one or more was slipping). Clearly I hadn’t. Back to the drawing board I go.

Always remember: that which does not kill us makes us really annoyed.

Things are hotting up

I haven’t posted much about the 3D printer recently (or indeed about anything else). This is partly because I have been trying to work out what was the cause of poor print quality. I’ve finally worked out what the cause of the problem was. I’d been finding it increasingly difficult to print larger objects, particularly those which involved long continuous print movements. The symptom seemed to be a lack of material being extruded. I’d tried turning up the filament feed rate, but this only led to the extruder slipping as it tried to drive more filament through the print head. I turned up the temperature setting, to make it easier to extrude, and this worked over shorter movements, or at lower speeds. I could only get half-decent results by printing very slowly, with a feed rate of 120%.

The cause of the problem turned out to be very simple. The resistor used to heat the hot end simply could not provide enough heat to melt filament at the required rate. At low speeds, no problem. At higher speeds, insufficient power meant taht the hot end simply could not maintain the required temperature. Short distances were OK, because the hot end had time to heat up between extrudes.

The solution was to replace the resistor in the hot end with a cartridge heater. The J-head kit I bought came supplied with both options, and for some reason I can’t remember, I originally went for the resistor (there’s a picture in this previous post). Ten minutes of disassembly, rewiring and reassembly is all it took to fit the new heater. The hot end now reaches operating temperature much more quickly, and stays there very accurately, even if I turn the feed rate up and use a cooling fan. Goodness knows why I didn’t try it before.

Richmond revealed

I was at one of Rob’s excellent rather useful seminars yesterday.  As it was about 3D printing, Rob asked me to say a little bit about my printer.  Having not prepared to do anything, I relied on some bits of video I found on my tablet.  Thinking about it, I realised that although this blog has quite a few posts about specific parts of the building process, there isn’t really a post just simply describing the printer.  So this is it.  I call it Richmond.

P1000880

It’s inspired by Johannn Rocholl’s Rostock printer, but the design is my own.  I wish I could blame someone else for the design flaws, but I can’t.  The basic design features three columns made of extruded aluminium section (bought).  Up and down each column runs a carriage (the pink bits), with spring-mounted ball bearings to make it run smoothly and without wobbling.   Rob printed these for me.  Here’s a close-up of one.

P1000867

The blue parts are modifications (printed by me) to add extra ball-bearings.  The original design simply had screw in the plastic which gradually wore loose.  At the right of the picture, you can see the fishing line which is attached to the carriage to drive it.  This loops around a motor-driven pulley at the bottom of the pillar and and idler pulley at the top, to make it move up and down.  The grey rods are carbon fibre, and join the carriage to the tool head.  The rods are in pairs, to keep them in a parallelogram shape – this means that the print head can move in three axes, but will never rotate.  The tool head looks like this from above: The translucent tube in the centre guides the plastic filament into the heated part.

P1000865

The print head looks like this if you happen to be underneath it (which I don’t recommend, because it heats up to 220 Celsius):

P1000866

The underneath view shows you the hot end – the part that melts the plastic and squirts it out through a tiny (0.3mm) hole.  The plastic filament is driven through the flexible tube to the hot end by an extruder, in which it is pressed against a rotating gear.  It takes a surprising amount of force to push the filament though the tube and the hot end.  Here’s the machinery that does it (with its operator):

P1000872

As usual, these components were printed for me by Rob, but they are not my design.  Rather, I downloaded the designs from thingiverse.  There is no sense in reinventing the wheel, especially when so much effort has gone into making it work well.  The plastic filament is taken from a reel, which sits close by on a home-printed stand:

P1000876

The filament drive is powered by a NEMA17 stepper motor.  Each carriage is also driven by one of these, mounted at the bottom of each column:

P1000869

Each motor has a printed pulley on it (printed and then machined with my printed lathe, in this case) which drives the Spectra non-stretch fishing line to move the carriage.  The filament is kept under tension by an adjusting screw on the carriage.  How much tension?  Until it goes ā€˜ping’ rather than ā€˜boing’ when you pluck it, that’s how much.  As an aside, it also makes an interesting Aeolian harp if you take it outside on a windy day.  Each stepper motor moves as finely as 3200 steps per revolution, so with the pulleys I have this means about 55 steps per millimetre of vertical movement.

Also mounted at the base of each pillar is an adjustable mount for the print platform (which is just a circle of glass from a local glass shop).  These are ugly and badly designed, but they do the job for the time being.  When I redesign the base, they will go.  Using three supports means that I can ensure the print surface is as close as possible to being perpendicular to the pillars.  This is important for ensuring good prints, particularly so for getting the first layer of plastic to stick to the base.  If the base is not level relative to the  and y movement of the print head, then it’s likely that the first layer will vary between being too thin (resulting in nothing but an impression in the masking tape) and too thick (resulting in a strand of plastic not actually stuck to the base).  Bear in mind that this means the print plate has to be level to within plus or minus a tenth of a millimetre over its diameter, and you’ll see why this calibration has been such an issue for me.

P1000870

The hardware is mounted on a box made out of plywood I had lying around, painted purple because I had a can of purple spray paint to hand.  On the front of the box is a basic controller interface – an LCD and a simple rotary/click controller. 

P1000856

The LCD provides status information about the printer, and a menu system to allow various parameters to be adjusted without using an attached PC.  It is possible to fit it with an SD card holder, which will allow printing completely independently, but I have no need for that.  The display and controller are driven by and provide input to an an Arduino Mega controller inside the main box.  The arduino is fitted with a Ramps 1.4 shield, which provides the stepper motor driver electronics and the higher power switching for the hot end.  The arduino runs Marlin firmware, which generates the stepper motor motions required to translate standard cartesian G-codes to carriage movements for the delta configuration.  The firmware also controls the extruder, monitors the temperature of the hot end, and drives the LCD.  The power supply driving all this is also in the purple box.  It’s a scrap supply from a PC, which provides handy 5V and 12V outputs, at high enough currents to drive the motors and the hot end.

Looking back, it doesn’t seem that complicated.  Makes me wonder why it took me so long to build.

Turn again, Whittington!

As a devoted reader of my blog, you will know that I’m engaged in a continuing quest to improve the precision of my 3D printer.  The most recent improvement was to replace all the pivots in my original design, which were simply composed of screws passing through holes in plastic, with proper miniature ball bearings.  This has had a huge benefit – there is now very little play in the movement of the print head.  Printed shapes are much more precise than they were.

The next issue to tackle is one I’ve been aware of for a while, but have not had the means to fix.  First, a recap: the whole print mechanism is driven by three stepper motors.  Each stepper motor has a pulley mounted on its output shaft, which drives a belt made of stretch-free fishing line.  Each belt goes the length of a vertical column, passes around an idler pulley at the top, and is attached to a carriage, so as the motor turns, the carriage moves up and down the column (a picture may not be worth a thousand words in this case, but if I had had one to hand it would certainly have saved me fifty or so).  The amount by which the carriage moves depends on the number of steps the output shaft of the motor rotates and the diameter of the output pulley.  Knowledge of these two things allows the printer firmware to be calibrated for each motor with the number of steps required per millimetre of carriage movement.  Because this figure is set in firmware, it doesn’t matter what each pulley diameter actually is – I can simply measure it and do the calculation.  However…

The problem I found on measuring the pulleys (kindly printed for me by Rob) is that they are not perfectly circular – the diameter varies by about half a millimetre around the circumference.  Add to that the fact that when a pulley is mounted on the motor shaft there is a little added eccentricity, and you end up with a drive pulley whose radius varies by about 5% as it rotates.  Over long movements, this is not a problem – the eccentricity averages out – but for small movements this results in unevenness.  It’s particularly obvious on the first print layer, which is often thin.  It manifests itself as patches of thin or thick deposition, and it just won’t do!

The cure is obvious: I need pulleys which, when mounted on the motor shaft, are round.  The standard method of making round things is with a lathe.  I would dearly love to have a proper modelmaker’s lathe, but they are expensive.  I can’t really justify spending Ā£400 to make three plastic pulleys. I tried printing some more pulleys myself, but the accuracy of my prints was no better than Rob’s (not surprising, given that the pulleys weren’t round). 

I need a lathe.  I have a 3D printer.  You are ahead of me.  I had a search online to see if anyone had published designs for a 3D printed lathe, and the only one I could find was this one,  by a guy calling himself Sublime.  It’s a great piece of work, but it doesn’t look precise enough for my purpose, and I don’t need the three-jaw chuck.  For the time being, I only need to turn pulleys.  So I stole some ideas from Sublime, and designed my own lathe.  Here’s a video of it in operation:

I’m happy to say that it works.  It’s far from perfect, but the pulleys I have turned with it now have a variation in radius of 0.1mm or less, which makes for much better prints.  Now it’s on to the next improvement: automatic calibration of the print surface.  Watch this space.

The funny thing about thermoplastic…

… is that it melts when it gets hot.  ā€œWell, duh!ā€, as my daughters would say.  PLA, the thermoplastic used in most 3D printers, is a very practical material.  It’s light, strong enough for most purposes, and melts at a reasonable temperature.  Which is why I’ve used it for many of the parts in my printer.  Most of these parts have no chance of getting hot, so the fact that PLA softens as it heats up is of no concern.

The one area that does get hot is the area around the hot end (ā€œduh!ā€ again).  This is expected, and the J-head hotend uses a high temperature resistant polymer called PEEK to isolate it from parts made of PLA.  So far, so good.  At normal printing temperatures the (PLA) hotend holder remains cool enough because of the PEEK insulation.  If, however, one accidentally sets the hotend temperature to 2110°C instead of 210°C (no, the software doesn’t stop you doing that) and it takes one a few minutes to notice, then the PLA can get substantially hotter.  Easily hot enough to deform, in fact.  And no, I didn’t let it get to 2110°C – I spotted the problem when the temperature got to about 240°C, at which point I panicked a bit and found the BRS.

The net result is a deformed pair of print head mounting components:

P1000751P1000753

The deformation isn’t hugely obvious (its around the small hole in the middle of the pink part, and on the further prong of the red one), but the net result is that the j-head is slightly loose, and is set at a slight angle to the vertical.  This may help to explain why some (but not all) of my prints are slanted.  I suspect that the print head offers more resistance to movement in one direction than in another, and this manifests itself in a number of missed steps on one of the stepper motor axes.  Each layer may thus be slightly offset from the previous, leading to the slant.  Objects which do not require many movements in the ā€˜difficult’ direction have fewer missed steps, and print more vertically.  Perhaps.  This is only speculation.  Rob’s printing me a new head (that sounds weird), so I’ll see if the result is straight prints.

Eccentricity

Generally regarded as a Good Thing in an Englishman, eccentricity is rarely desirable in pulleys.  The drive mechanism of my printer uses six pulleys, all of which have themselves been printed.  In my ongoing pursuit of accuracy, I have discovered that some of these pulleys are not entirely circular, nor are they mounted entirely concentrically on the motor spindles (though exactly what ā€˜concentric’ means if the pulley is not circular is perhaps open to debate).  I’d really like to machine some small tolerance parts out of aluminium, but I don’t have access to a lathe (if you’ve got one, I’d love to use it for an afternoon…).  So how do I work with what I’ve got?  I need some way of ensuring circularity and accuracy of diameter.  The material is PLA, so it’s not too difficult to shape; I should be able to use the stepper motor itself as a lathe spindle, and turn the pulley in place.  My Idea is to print a bracket which will allow me to mount a dial gauge for measuring the pulley, and a makeshift cutting tool to pare it down.  I designed and printed one.

P1000705

Wonder of wonders, it printed pretty well!  I must be doing something right.  Now I can measure the variation in the pulley radius as it rotates:

P1000725

It turns out that the deviation is about half a millimeter over a full revolution.  Not, perhaps, a huge amount, but on a 20mm diameter pulley this is 2.5%. This does not mean that over a 100mm movement the carriage will move 2.5mm to much or too little – indeed, it’s possible that it could be completely accurate at specific points – but the linear motion will not be consistent with relation to the stepper motor steps.  Straight lines will wobble.  So now all (all?) I need to do is to drive the stepper motors at constant speed and pare down the pulleys to a constant and known diameter, than that’s one more inaccuracy removed.  We’ll see how that goes.

Concerning calibration

Or, Why You Should Always Listen To People Who Know More Than You.

There are many 3D printer designs out there.  I took ideas from some of them, and designed my own.  I’ve built it, and it kind of works.  My prints are dogged by a number of problems.  Principle amongst these has been a distinct slant to all the printed items (and by ā€˜distinct’, what I really mean is ā€˜45 degrees’).  This is not conducive to making precision parts for sundry other projects, which is the main purpose of the printer.  After fiddling round the edges for a while, and managing occasionally to get half-decent small prints, I realised it was time to do it properly.

In building my printer, I knew I would not have access to precision tools.  Any parts I made would be cut by hand with a saw.  Holes would be drilled with a hand-held drill.  High accuracy was not going to be the order of the day.  I naively didn’t think that this would be a problem – the machine is software controlled, after all, and it should be possible to account for misalignment of parts by judiciously tweaking the code.  It’s only software, after all.

This approach is feasible.  Software is flexible, and all sorts of hardware faults can be catered for in the software.  If, that is (and this is a big ā€˜if’) you know what they are.  Without accurate measuring tools, how do you know what errors need to be accommodated?  With the infinite flexibility that software configuration offers, it’s easy to get into a situation where more and more settings can be tweaked, but the settings become pure guesswork.  If something prints successfully, you don’t really know why, but you use those settings next time.  Post hoc ergo propter hoc

Also, adding all those settings involves time and effort.  Especially if you are using printer control firmware written by someone else, and you have to hack new tweaks into it.  This is labour that could be better used reducing the errors in the system rather than trying to accommodate them.

The better way

I’ve come to the staggering conclusion that it’s best to get the hardware as accurate as possible first.  To most people (including may writing on the web) this is blindingly obvious.  It took me a little longer to realise.  Having finally got the idea through my thick skull, though I set about re-engineering the hardware.  Firstly, I disassembled the arms and print head, and measured everything as accurately as I could.  It turned out that two of the delta arms were 1mm longer than the rest.  I picked one arm to use as a reference (and marked it) and reworked all the others so that they were as close to the same length as I could make them.  I estimate variation to be no more than +-0.1mm now.  Everything else seemed to be correct, so I reassembled it all.  Not much change there, really.  I then used a try square to adjust the print bed to be as perpendicular as I could to the vertical beams.  I had previously been adjusting this to try and level the prints, when really I should have been adjusting the print mechanism to move parallel to it.  Too many adjustment points, not enough logic.

The second part of the process is to use a consistent and structured set of steps to calibrate the system in a repeatable manner.  I found a nice article on how to do this sensibly, from which I quote: ā€œFirst, and foremost, build your printer as accurately as you can.ā€  I second that.  In the article, much of the calibration is done with small adjustments to the carriage end-stop screws.  Well, my design doesn’t have them.  I can shift the end stops, but not under fine control.  I thought I would do this in software.  So I needed to add adjusters to my carriages.  How could I make them?  If only I had a 3D printer…

The nice thing about small, non-precision parts is that the calibration errors don’t show themselves quite so much.  So I was able to print three small blocks with holes to allow me to add adjustment screws to the carriages. 

P1000592

These are the first parts I’ve printed which actually form part of the printer itself.  A small achievement, but quite a satisfying one. 

P1000599

With the new adjusters in place (superglue is a wonderful thing), and following the calibration plan closely,  I’ve finally managed to print some things which are (almost) straight and (almost) the right size.  Here’s a print head, straight after printing and before tidying up.

P1000608

It’s not perfect.  I’ve still got some tweaking to do with feed rates, temperatures and so on, but the RepRap Wiki has an excellent guide to printing problems which should help me sort these out.  Things are definitely looking up, and I should be producing upgraded parts for the printer itself Real Soon Now.