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])
    );

}

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.

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.

Pink plastic printer parts printed

Last weekend, the ever-generous Rob very kindly printed out a whole batch of parts for my 3D printer:

Printer_parts

With the ones he’s already done for me (and a few bearings, nuts and bolts and bit of carbon fibre rod) these comprise enough to build the printer completely, apart from the ‘hot end’.  So that’s what I’ve done over the last few days.  Although the parts were printed to quite high accuracy, with holes in the right places, there was still a fair bit of smoothing, trimming and tapping of holes to be done.  I also had to drill one or two new holes where I had forgotten to design them in.  This is version 1, after all.  The assembled result looks like this:

Printer_assembled

It’s a bit of a monster.  At least I’ll be able to print large things (think ‘traffic cone’) if I want to. 

Here’s a close up of the print head.  The bit in the middle is a holder for a pen, so I can do some tests for accuracy before I fit a hot extruder.

tool_head

I’m sure you want to see it working.  There is a video on YouTube, which shows it moving around at a variety of speeds.  Now I need to get a printing platform in place, hack the Marlin firmware in the controller to support a delta configuration, and start doing some serious tests.

Printer Claus has come to town!

As you know (because you follow my blog very closely), I’m building my own 3D printer.  Today I received a box of stepper motors, an Arduino Mega 2560 board and a RAMPS controller board kit.  These are the major items that I had to buy (rather than getting Rob to print for me).  Having spent actual money, I’m now really committed to building the printer.  Any day now I should receive the aluminium extruded sections I am using as vertical struts.  Watch this space.

WP_20130211_001

WP_20130211_004