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 gifmaker.py 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.