Monday, 21 April 2008

Fun with Python and G code

The current RepRap host software is a monolithic Java program that imports STL files, lets you place the objects to be made on the table, slices and dices them and controls the machine.

In my opinion the slice and dice code should be a separate program from the machine controller. Its inputs should be the 3D model in STL format plus the filament dimensions and the output should be an XML file with extruder paths grouped into layers, outlines and infills. The machine controller then reads the XML and controls the speed, temperature, fan, nozzle wiping, cooling delays, etc, according to the selected material and the machine characteristics. A third layer of software should be the communication protocol to the slave device, e.g. SNAP or G code over serial, USB, Ethernet, etc.

I have moved a little way towards that model by making my machine accept G code from the RepRap host or Enrique's Skeinforge script. I throw away most of the G codes, looking at just enough to build be an internal representation of the extruder path. This is simply a list of layers, which are lists of threads, which are lists of points. From that information I can control my machine, make animated GIFs or preview the paths in a GUI. All of this is trivial in Python.

Here is my first cut at the preview GUI: -

The preview shown is from G code generated by the RepRap host, and here is the object it made: -

Behind is the same object made from G code generated by Skeinforge.bsh. The RepRap one has sharper corners and the infill is a bit better but the Skienforge one is faster to produce because it has sparse infill.

Here is a video of it being made: -

Here is my first attempt to make Vik Olliver's shot glass: -

When it got to the stem the fan could not get the heat away faster than it was arriving and the whole thing became a molten mass. I fixed that by slowing down the extruder to 8mm/s when the layer gets small: -

It took five hours to process with Skeinforge and an hour and a half to build. I couldn't get the RepRap host to process it.

Wednesday, 16 April 2008

Python & Beans make object

Having got bored of making rectangular blocks for months I decided it was time to hook up my machine to the RepRap host software so that I could make arbitrary 3D objects from STL files. My original plan was to hack the host code to replace the serial comms with Ethernet and cope with the differences of my machine from the RepRap Darwin. Zach Smith added a G code back end so I decided to just add a G code parser into my Python to save me having to modify the host.

In the meantime Enrique Perez published a plug-in script called Skeinforge.bsh for ArtOfIllusion that also converts 3D objects to G code extruder paths. It is written in the Beanshell script language, which is Java like. I decided to try both approaches, as in theory a G code parser would allow me to use either.

Enrique posted some new scripts that process G code and drive the RepRap hardware using a Python SNAP protocol driver written by greenarrow, so I didn't even need to think about writing a G code parser, I just cut and pasted a few lines from Enrique's.

Before letting it drive my machine I thought it would be a good idea to look at the paths on screen. I knocked up a little script which used my HydraRaptor simulator to draw them. The script is just a few lines of Python that use TkInter.

It was soon apparent that Enrique's code had a bug that left off some of the outline, but apart from that it looked very promising because it has the ability to do sparse infill. That speeds up building objects, saves plastic and reduces warping so it is very worth while. Not only that, it had a novel infill pattern. Instead of parallel lines like this: -

He moves the ends together so that the outer wall is stronger: -

This looks like a good idea because it makes the outer wall effectively two layers thick but probably gives a bit less warping than a second continuous layer would give.

In order to communicate the results to the forums I came up with the idea of making an animated GIF showing all the layers in sequence. This turned out to very easy using Google and Python. The Python Image Library (PIL) can make GIF files and I found a script called which takes a list of images and uses PIL to calculate the deltas and write out an animated GIF.

Enrique fixed the bug very quickly, here is the sliced extruder pump body: -

The red lines are moves without filament flowing (ideally) and the each new section of filament is a different colour.

And here is the same object sliced by the reprap host :-

A side effect of Enrique's algorithm is that the corners get rounded, however I don't think that matters too much because the filament has a minimum bend radius anyway. The main downside is that beanshell script is very slow, so it takes longer to slice than it does to extrude at the moment. A faster PC will probably sort that.

The first object I tried to make was this opto mounting bracket from the RepRap Darwin: -

I choose it because it is small, so does not take too long, but reasonably complex with a horizontal hole. Here is the sliced path from Enrique's script: -

And here is my first attempt at making it: -

This is PCL extruded onto MDF, 0.625mm filament extruded at 10mm/s with the fan on, no interlayer pauses.

A bit hairy due to the extruder not being able to stop the filament flow quickly, but I was quite pleased with it for a first attempt. It is too tall due to a bug in my code and its not the latest version, which has teardrop shaped holes to make the overhangs less than 45°.

Here it is cleaned up a bit: -

It is 50% filled which is probably not appropriate for this size object in PLA but that part is fully functional I think.

Enrique was pleased to see it as he doesn't have a machine to test his code with. A perfect partnership, he writes all the hard bits in beanshell script and I write the easy stuff in Python!

Thursday, 10 April 2008

Basket case

I was using two old component spools to hold my feedstock, see all-wound-up, but I don't have any more so now that I have four polymers I decided to give Vik Olliver's design a try. It has the advantage that you don't have to spool all the filament on, you can just drop in an open reel if that is how your filament comes.

This is my take on it: -

The uprights are 15x15mm aluminium angle. The beam across the top is a piece of 20x10mm channel. The bearing is a standard ball bearing and I reduced its internal diameter with a couple of bushes I had lying around. I then used a bolt with holes through the head as an axle. I found it in the road while I was on a walk wondering what to use. That is the third piece of HydraRaptor that I have picked up in the street.

The baskets are £4.21 in B&Q and have a plate in the bottom with a central hole just right for feeding the filament through. As the machine pulls the filament from the centre of the reel, the basket rotates to prevent it becoming twisted.

It works very well and has the advantage I can buy as many baskets as I have plastics and just take them on an off as needed.

It also allows the filament to rotate in the extruder but ironically, since I tweaked my extruder, PLA no longer feels the need to rotate. Presumably it rotates if the friction between the screw and the plastic is higher than between the plastic and the filament guide. I think that gives a clue to which of my tweaks made all the difference in reducing the extruder torque needed. I think it was adding the washers to space the top of the pump apart so that the screw bites in progressively and sharpening the screw thread.

More PLAying

The tweaks I made to my extruder dramatically improved its ability to extrude PLA. I am not sure which one made all the difference or whether they are all needed. I can now extrude at my target 0.5mm filament 16mm/s with about 75% motor PWM duty cycle. That is less than I needed for ABS before the tweaks.

I can also extrude at lower temperatures. I think 180°C is a bit on the hot side as the plastic is very runny at the temperature. It will flow out of the extruder under gravity and has negative die swell. At 140°C it behaves more like the other plastics and swells to 0.6mm, which is very low.

In a previous article I stated that I could not make sparse filled objects because the filament slumped too much. With the reduction in temperature and increase is speed I now can. Here is a 50% filled block: -

It is still very strong. I expected the warping to be less but I have switched from MDF to balsa and I think that increased it. The balsa I have is only 2mm thick and was only stuck down with masking tape. I might try gluing two pieces back to back with the grains at right angles to get it stiffer.

So now with a slightly tweaked extruder I can do PCL, PLA and ABS at 0.5mm @ 16mm/s. I had to slow down for HDPE to prevent thermal damage to the extruder.

To get good definition at high speed I extrude with a fan running. The fan cools the nozzle which causes more heater power so the barrel temperature rises to the point where PTFE goes soft and the JB Weld turns to dust. PCL and PLA are no problem because the temperature is less. ABS does not seem to need the fan.

I plan to make a PTFE cover for the nozzle which will probably insulate it well enough and hopefully stop filament sticking to it and burning.

Tuesday, 8 April 2008

Fantastic PLAstic

I have managed to get the GM3 to extrude PLA reliably with the following tweaks: -
  • I locked the clutch as per Solarbotics instructions.
  • I lubricated the GM3 with silicon grease as per Adrian Bowers suggestion.
  • I sharpened the thread a bit with a half round file following Vik Olliver's instructions.
  • I spaced the top half of the pump slightly further apart with some thicker washers. That gives the thread a gentle lead in.
  • Plenty of oil on the filament.
  • I throttled back the flow rate to 3/4 of the rate I normally use (π mm3/s).
The motor runs warm, but not alarmingly so. For some reason the filament is no longer rotating in the extruder.

My first attempt curled away from the MDF bed so I used 2mm balsa wood as Adrian has been using for PCL. That worked well so it's good that we can use it for both. I have yet to try it with HDPE and ABS.

I made my standard test block with 0.5mm filament extruded at 180°C (at the nozzle), layer height 0.4mm, pitch 0.6mm, fan on constantly. The results are excellent: very good filament compliance, i.e. sharp corners and flat sides, excellent layer bonding.

It is slightly more warped than my first test. That is probably because balsa is softer than MDF.

No warts on this one!

Monday, 7 April 2008

Locking the Solarbotics GM3 clutch

All the adverts for the Solarbotics GM3 gearmotor say the clutch can easily be locked but don't say how. I emailed them today and got a quick reply from Dan: -
Locking the clutch is actually very easy... we should make an effort to get the instructions on-line. All you have to do is glue the little plastic clutching mechanism in its cavity, but to ensure a good contact you should first wipe it out with rubbing alcohol to get the grease out, then score the surface up a bit with the tip of an Exacto knife and then you can use either super glue, model cement, or epoxy to lock it.
So that is what I shall try next to see if i can get it to extrude PLA without warts.

Sunday, 6 April 2008

A day with PLA

Adrian Bower has kindly given me a small sample of polylactic acid (PLA) filament to evaluate and some parts to make the new geared extruder are on their way. Being a bit too impatient I decided to try extruding it with my current extruder.

Each polymer I have tried so far (HDPE, PCL and ABS) has had very different characteristics and PLA is very different again. At room temperature it is very hard and brittle and is completely transparent. At somewhere between 50-80°C it has a glass transition temperature above which it becomes a rubbery jelly. If you put it in boiling water and then pick it out with tongs you can bend it as much as you want and when it cools it will set in that shape. These are the two bits of 3mm filament I showed earlier when I had bent a 150mm piece double and it snapped :-

After dipping them in boiling water I could tie knots in them but I had to be quick because it hardens in seconds. If I return them to boiling water they untie themselves and return to being a straight rod.

PLA melts at about 175°C, the highest of all the polymers I have tried so far, where it transitions from jelly to a liquid with the consistency of a thin syrup. If you extrude it quickly into mid air it sets almost instantly and forms a filament, but if you extrude it slowly it forms drops that drip from the nozzle like water from a tap, but are solid when they hit the deck. Very different from HDPE and ABS which extrude more like a paste. Like PCL, PLA is sticky when molten so it sticks to MDF quite well, unlike HPDE and ABS.

Getting it to extrude from the original extruder is next to impossible, I really should have waited for the gears. The problem is that the extruder pumps the filament by cutting a thread into it. PLA is so hard that it needs an enormous force to press the thread into its surface. That is no problem with the springs I have, but it also seems to have a high coefficient of friction, so the torque required to turn the thread is then too much for the GM3 gearmotor and its clutch slips.

Recently I had an idea to cut the torque requirement by shortening the thread. The reasoning goes like this: -

A substantial part or perhaps most of the force required to push the polymer is not the extrusion pressure but the lateral friction of pushing the filament through the filament guide and the tangential friction of cutting the thread. Both of these are equal to the respective coefficients of friction multiplied by the force exerted by the springs. But the force required to achieve enough pressure to push the thread into the plastic must be proportional to the length of contact. So once you have enough thread to push the filament without shearing off, any more is counter productive. It requires more spring force, which creates more friction, which makes the filament harder to push, a vicious circle.

Ian Adkins put the theory to the test and reported he could still extrude PCL with only 7mm of thread. The motor current dropped from 240mA to 190mA. The no load current was 62mA so that indicates about a 50% reduction in torque required. Not being as brave as Ian, I reduced mine a bit less radically to start with. I roughly halved it: -

I used a couple of washers at the top set of screws to space the pump halves apart, to keep them parallel, and just tightened the bottom pair of springs. That did reduce the torque required but even with plenty of oil the GM3 clutch was still slipping. It is a good modification because you save two springs, hence two less adjustments, and the extruder is quicker to strip down and rebuild. Plus future versions of the pump can be made much shorter.

All the adverts for the GM3 say the clutch can easily be locked but don't say how. I opened the gearbox and found the clutch is inside the last gear wheel. I tried putting some bits of thick wire into it to stop the springy bits from compressing.

That worked for a while until one fell out. I thought they would be trapped by the lid but seemingly not. My next attempt was to stick them in with super glue. That worked but the clutch still slips somehow.

Another issue with PLA is that the filament likes to rotate in the pump. Other polymers do that as well, but if you hold them so they can't rotate they still extrude. With PLA, if you don't let it rotate it slows down the motor. Presumably by letting it turn it removes the tangential friction leaving only the sliding friction. The problem with letting it rotate is that I think it means the forward motion is less so the extrusion rate is not what it should be.

When the clutch slips it jumps one notch. Because my shaft encoder is on the output shaft the firmware makes up the difference. If it does not happen too often I still get the right volume extruded. It does however cause a shock wave which makes a blob in the extruded filament. I decided to try and make an object anyway with it slipping occasionally.

Because I only had 8m of filament I decided to try a sparse filled object first. That does not work with PLA because the unsupported filaments sag: -

However, this messy object has a perfectly flat base so shows some promise.

Next I tried a 100% filled block, extruded at 180°C (at the nozzle) 0.75mm filament at 8mm/s, layer height 0.6mm, pitch 0.9mm, fan on continuously. A bit slow and course compared to my other tests but I always start slow and move up in speed.

During this build the clutch started slipping once or twice per revolution causing the warty surface. Near the end it started slipping continuously so this is only about 18.5mm high rather than my standard 20mm test. Never the less, it only has 0.19mm warping after more than 24 hours making it the least warping yet for a solid object. Added to that it is probably the hardest material of the four.

PLA's main downside is the low temperature at which it goes soft, not much better than PCL, even though it has a much higher melting point. In this respect it is very like PVC which also has a high melting point and a glass transition around 80°C.

Here is my warped league: -

I think I can explain why plastics are good and bad for warping. It is simply how much they contract between the point they go solid and room temperature.

HDPE has a high freezing point and high thermal coefficient.
ABS has a slightly lower freezing point and a low thermal coefficient.
PCL has a very low freezing point.
PLA has a glass transition point not much higher than room temperature.

If the object can be stuck to a rigid base while it is cooling then the warping is reduced.

My theory of needing to extrude at twice the melting point minus ambient certainly does not hold for PLA, otherwise I would need to extrude it at 330°C. I get very good bonding at 180°C. It may be that if I extrude very fast it would need to be hotter but I expect it would decompose at 330°C. It may be that the glass transition makes the theory invalid or maybe it is plain wrong. It does seem to be true for polymers which are paste like and not sticky, i.e. ABS and HDPE. PCL and PLA are both sticky when molten. I.e. they will stick to things like glue does whereas HDPE will only weld to things like itself. It has no adhesive quality.

I haven't entirely given up with making the non geared extruder work with PLA. The problem with the geared version is that it can't keep up with my extrusion speeds. I can try reducing the thread even more. I can try sharpening it as Vik Olliver has done. I can find a solution to locking the clutch. The motor does get quite hot so it probably won't last long. I do have three more to burn through before I find a better motor. They only seem to last a couple of weeks in my machine anyway.

Wear and tear

Half way thorough my evaluation of PCL the extruder's flexible drive coupling started to break up again. When I moved to ABS that was the final straw: -

The first one I made was only 2.5mm cable. This was a 3mm one from BitsFromBytes. I replaced it with some 3.2mm cable from B&Q. I drilled the hole out to 3.3mm so it is a snug fit. I also soldered it while it was held in alignment by my lathe so it is very straight.

I think the force required to bend a cable goes it with the fourth power of its diameter so this one is considerably stiffer. Possibly some of the motor torque is wasted in flexing it.

The good thing about the shaft I got from BitsFromBytes is that it solderable, so it makes it easy to replace. My original shaft was stainless steel so I had to glue the cable in with JB Weld, making it harder to replace.

My next extruder will be direct drive!

I also wore out the brushes on a second GM3 gearmotor. I replaced it with a 12V version which has to be ordered by phone from Solarbotics in Canada. It looks the same except that it has a black end cap instead of a white one. It runs a bit quieter but I don't know if it will last any longer. As you would expect the coil resistance is higher so the current through the brushes will be lower.

Stuck fast

In the previous article I said I could use both sides of the advertising board as bed material. Well the back of the board is a thick layer of a leathery sort of plastic, I think it may be PVC. I can certainly deposit ABS onto it, but it sticks so well and is so tough I found it completely impossible to remove.

The front of the board has a very thin layer of plastic with paper behind. That may also be PVC, but being so much thinner is easy to peel away.

Interesting that ABS appears to bond so well to PVC, if that is what it is.

Friday, 4 April 2008


I have been testing Acrylonitrile butadiene styrene (ABS) in the RepRap extruder and I have to say it works rather well. It is surprising how different each plastic I try is. For example, if I fold a short piece of filament double and let it go this is what happens :-

PCL is rubbery and springs back almost straight, HDPE is a lot less springy. ABS bruises when bent sharply and is a more opaque cream colour rather than white. PLA is transparent like glass and breaks when bent through a small radius. The progression from top to bottom is from rubbery to brittle. I think the reason for this is that ABS and PLA are below their glass transition (Tg) at room temperature, whereas with PCL and HDPE their Tg is well below 0°C.

I have a bit of a routine now for getting my machine working with new plastics. First I look at the extruder performance at different flow rates and temperatures. Then I have to experiment to find a bed material it will stick to. After that I make test blocks to fine tune the temperatures and find the best speed and filament diameter to build with. Finally I look at the warping with different infill densities.

So here is the flow rate versus motor duty cycle extruding at 190°C measured at the nozzle (the other plastics are at different temperatures):-

As you can see ABS works the motor harder. Part of this is due to the fact that it has to run faster (for the same flow rate) as the ABS filament I have is only 2.75mm rather than 3mm. However, I think that it is due mainly to the increased force and friction required to cut the thread in the pump. At first I had a lot of problems with the GM3 motor's clutch slipping. I got it working reliably by loosening the top springs and just tightening the bottoms ones. I also have the filament running through a felt washer soaked in oil, which I had to add when doing PCL.

Here is how the filament diameter varies with flow rate :-

ABS has much lower die swell than HDPE and is quite a bit better than PCL. That makes it good for extruding fine filaments at high speed.

I think the graph above shows that the viscosity increases a lot as the temperature drops but the motor duty cycle remains pretty constant showing that most of the torque is used overcoming friction in the pump.

I tried using PP and MDF as bed materials but ABS does not want to stick to them. Unlike PCL which stays molten for a very long time, ABS filament sets soon after leaving the nozzle. PCL and HDPE turn transparent when they are molten but ABS does not. I think its specific heat capacity is quite low compared to HDPE so the workpiece cools quite quickly and I can get away without a fan.

The best material I have found for a bed is plastic laminated board. My wife bought me a big sheet of it for 10p when I was experimenting with HDPE. It was cheap because it was scrap advertising material. She was disappointed when HDPE did not stick to it, but is made up now that I have found a use for it. I think possibly it works because the thin plastic lamination is actually polystyrene.

I can extrude ABS on to it and it sticks well enough without needing a raft. To remove it I cut the lamination around it with a penknife and pull the surface off. I can then peel the lamination off the base of the object leaving a clean finish. It works well but I don't know where to get any more and it is single use although you can use both sides.

It is good not to need a raft because while I can remove an HDPE raft with scissors or a sharp knife, ABS 1mm thick is too hard to cut off easily.

My theory about welding temperatures is that you need to extrude at least twice the melting point (105°C) minus ambient. That works out at 190°C. In practice I needed to go a bit hotter to get a satisfactory bond between the layers at high speed. I settled on 220°C for the first layer and 200°C for the rest of the object.

Layer bonding can be quite variable with ABS. It is easy to make objects which can be peeled apart again. I think this is because even at 220°C ABS is quite paste like and less fluid than the other plastics are at their critical weld temperature. That makes the filament contact points very tangential and so smaller. Plastics that are more fluid slump and get a bigger contact area, hence a stronger weld. Also, the time the plastic is in contact and above the melting point determines the amount of fusion. I think if I spend some time on this (and with the other plastics) I will be able to use plastics as their own support material for making overhangs. The layer height will be crucial to making this work so it will have to wait until I have replaced the PTFE insulator with stainless steel.

Here is my standard warp test shape: 40 x 10 x 20mm block made with 0.5mm filament at 16mm/s, layer hight 0.4mm, filament pitch 0.6mm: -

The warping figure I got after leaving it a few days was 0.38mm compared to 0.53mm for 100% HDPE and 0.21mm for 100% PCL. 50% filled ABS gives a figure of 0.15mm which is the lowest I have measured yet and ABS is still very strong at densities less than that, whereas PCL is not. Also, this was without a raft which gives worse figures for PCL and ridiculous warping for HDPE.

The filament is very soft and compliant when it is molten, with no spring in it, so it goes where the head leads it and produces good definition. Here is a top view showing how accurate the corners and infill are: -

Here is a 50% infill pattern: -

This is very accurate compared to the same pattern in HDPE shown here. 25% fill is also very good and the object remains strong: -

For some reason my 9M pixel camera doesn't like taking close ups of white things.

When I was extruding thick rafts I noticed some bubbling of the surface. I think this is due to absorbed moisture turning to steam because ABS has ten times more water absorption than HDPE. Oddly, it does not happen when extruding the object so is not a problem, at least with the current weather conditions.

ABS smells a little when it is hot but not enough to be objectionable.

My acorn nut nozzle, with the very shallow exit hole, is very incontinent with ABS as it was with HDPE but not with PCL. This means that even though I wipe it clean with the toothbrush it has extruded another few millimeters by the time it gets to where it has to start the object. The problem with that is that it sets so fast it is solid when it meets the table so will not stick and stops the following filament sticking. I am hoping the latest nozzle design will fix that.

On to the same test with PLA before I alter the extruder.