Archive for Tutorial

GCode Tutorial: Building Circles

Parametric Print Tutorial Set

In the previous GCode tutorial, we covered the creation of GCodes using Python, and introduced the basic structure of a script that uses GCode objects as a tool for creating GCode files.  In this tutorial, we’ll move from Para01.py to Para02.py in the first GCode Script Pack. In this file, we’ll start using the math library to create circles from straight GCodes.

First, a bit of bookkeeping.  Using trigonometric functions means getting back floating-point values with lots of decimal places of precision, but in a GCode file it’s usually a bad idea to have more than a few decimal places of precision, since it bloats serial operations and finer than 10um precision isn’t attainable on most current hardware anyway.  So we need a rounding function to truncate these floating-point numbers. My friend Ryan Vilbrandt was kind enough to lend me his:

gcode_tutorial_01

This is called from the GCode string output function later to make sure that the GCodes sent to the file are tidy.

In the next step, we’ll use the parametric formula of a circle:
X = cos (T)
Y = sin (T)

Inside the Zsteps loop from the previous example, we put a loop for Tsteps equal to two pi radians (360 degrees) minus a little bit.  Here we do 62 steps of 0.1 radian each:

gcode_tutorial_01_02

Smaller steps will make for shorter GCodes and a more perfectly circular curve, and larger ones will even produce visibly flat sides to the cylinder.  This script can be used to make shapes like octagons and pentagons by reducing the number of steps to the number of desired sides.  Additionally, by entering an integer multiplier into one or both of the trigonometric function arguments, this script can generate lisajous patterns.

There are a lot of shapes that can be build based off even this simple example– scripting GCodes directly isn’t going to work for every application, but it’s a great way to build certain classes of objects, and doesn’t require learning how to use a 3D modeling tool.

Leave a Comment

Python Scripted GCode: The Basics

Parametric Print Tutorial Set
This tutorial series will show off ways of making your own GCode files directly with python scripting.  In a lot of applications, it can be more efficient to work directly on GCode than to build a 3D model.  Further, directly modeling a shape can be less fiddly than skeinforge, particularly ones with single walls.

This tutorial will explain the file para_01.py found in the GCode Starter Kit. If you’ve never programmed before, you might want to study a few tutorials on the Python language, but this program is simple enough that if you’ve got the basics down, it shouldn’t be too hard to deal with this one.

The first few lines in this file are a “class definition” for an object called G1Code.  In the case of this file, this is just a handy way of storing the variables X, Y, Z, and F (F is feedrate) and a good place to put the function that makes a text GCode out of those variables:


#G1 Code Object
class G1Code:
def __init__(self, X=0, Y=0, Z=0, F=0):
self.X =X
self.Y =Y
self.Z = Z
self.F = F


def __str__(self):
string = "G1 X" + str(self.X) + " Y" + str(self.Y) + " Z" + str(self.Z) + " F" + str(self.F)
return string

With the above definitions in place, we can now access the coordinates in an object of type G1Code by adding a .X, .Y, .Z, or .F to the end of its name. We can also print a gcode just by calling str(G1Code). Next we’ve got some variable declarations:


filename = "test.gcode"
Zsteps = 0
ThisGCode = G1Code(X=0, Y=0, Z=0, F=1000)

This program only has one G1Code object– we just change its value repeatedly and write it out to the file after each change. Next, we’ll take that file name, open a text file, and write out headers. Thes GCode and MCode references explain how these settings tell the printer to operate in absolute coordinates, milimeters, and set up the extruder.


FILE = open(filename,"w")
FILE.writelines("G21\n")
FILE.writelines("G90\n")
FILE.writelines("M103\n")
FILE.writelines("M105\n")
FILE.writelines("M104 S220.0\n")
FILE.writelines("M101\n")

Now that we’ve got a header, it’s just a matter of using a loop in the program to lay down each layer of the shape. In the case of this program each layer is the simplest shape possible: a triangle.


for Zsteps in range(30):
#Hop up to the next level, staying put
ThisGCode.Z = 0.4 * Zsteps
FILE.writelines(str(ThisGCode)+ "\n")

#Trace out the prism
ThisGCode.X = 0
ThisGCode.Y = 0
FILE.writelines(str(ThisGCode)+ "\n")
ThisGCode.X = 0
ThisGCode.Y = -10
FILE.writelines(str(ThisGCode)+ "\n")
ThisGCode.X = -10
ThisGCode.Y = 0
FILE.writelines(str(ThisGCode)+ "\n")

(Wordpress isn’t being friendly to my tabs, but they’re in the original file, and you do need them, because Python uses tabs instead of brackets to indicate loops and subroutines.)

Note that inside the loop there are four print commands.  The first one contains the value of the last GCode on the previous layer (or just zero if there is no previous layer) plus a slight vertical shift.  The other three move the print head first to the origin, then back ten milimeters, then diagonally down to a position ten milimeters left of the origin.  From that position, the next pass of the loop will move the print head up again, then around the triangle.

The print generated by this code isn’t very tall, or very large, or very tall, so you won’t waste a lot of plastic on messing around with the settings and trying new things.  Leave any questions in comments, and I’ll use that to gague whether the next one of these needs more or less of anything.

Leave a Comment

Skeinforge Quicktip: The Raft, Part II

untitled-1

For the last Skeinforge tip, I’m going to run over the temperature and support settings, which are part of the raft dialog.  (Presumably this made sense when the software was being written.)

Support material settings:

The inexpensive 3D printers with which Skeinforge is commonly used do not have a secondary support material.  However, using the very plastic to be printed *as* a support material can be marginally successful.  The raft option “support minimum angle” defines how steep an overhang can get before skeinforge automatically adds threads of support plastic.  By entering different temperatures for “temperature of support layers” and “temperature of supported layers”, you can have the two kinds of extrusion happen at different temperatures.  Plastic extruded at a relatively low temperature tends to turn out more brittle, so making the temperature of support layers close to the minimum working temp (this can vary from machine to machine) can result in some fairly easy to remove support structures.  Setting up temperature change times between these two (time before support, time before supported) can seriously slow down a build, though.

Temperature settings:

I’m currently working under the logic that the raft should be extruded pretty hot so that it will adhere reliably to the base, but I defer to Nophead beyond that.  Skeinforge offers temperature options both for the main object (the “supported layers” and “next shape layers”) and the raft, but also has separate temperatures for the first layer outline, and the first layer infill.  Although the properties of ABS are fixed, it’s hard to get a dead-on calibration of the thermistor, so odds are you’re going to have to experiment with temperature settings a bit.

One thing I’ve had happen is that one of my settings in here was too low, and the plastic froze, causing the pinch wheel to strip the filament.  If you have an extruder that stops extruding at the same point in the build twice with a stripped filament, make sure none of the temperatures in this box are low enough to freeze your plastic.

Leave a Comment

Skeinforge Quicktip: Fill

skienforge_quicktip_03_01

Fill is a script that handles the interior of a given layer sliced by the carve script.  Objects can be made hollow or filled, or as is most common, somewhere in between.  For these hybrid cases, wall thickness can be adjusted, as well as the density of the internal threading to trade off between speed and strength or between strength and plastic used.

The Extra Shells options create additional lines which trace the outline of each layer, just inside the outer one.  I was never sure which layers were which between “alternating solid layers”, “base layers”, and “sparse layers”, so I keep them at the same value.  Extra layers aren’t necessary for all cases, and in especially light builds, they can be left at zero to print only the outermost layer as a solid line, with the interior of each layer printing only as sparse or nonexistent infill.  (Such builds can be prone to collapse during printing or fragile though!)  Cranking this up to three or so is important to getting good water-tight seals.

Infill options: inside each layer, skeinforge lays down a pattern of lines to fill in the interior of a model with strands of plastic, which may be very light or very dense depending on the settings.  Dense models of course are heavier, sturdier, and take longer and use more plastic.  The Infill solidity ratio is the ratio between the infill pattern and a fully-solid object.  Set to 1, this would solidly fill the inside of the object completely.  I’ve had trouble with setting it to zero for fully-empty builds, so when I want empty builds I just set it to 0.01 or such, which is fairly negligible in terms of plastic inside.  A value of 0.3 or so is pretty good for large, sturdy builds.  The infill odd layer extra rotation rotates the infill pattern every other layer, which at 90 degrees creates a square pattern if line fill is used.

I think the interior infill density ratio is a feedrate setting which moves the print head faster during infill pattern drawing to get lighter strands than the outer wall.  Anyone got a better definition?

The solid surface thickness is similar to the extra shells settings, but for horizontal layers.  Skeinforge makes this distinction because it’s different to have a solid fill pattern than to trace an outline.  This setting should be the same as the extra shells settings for builds with uniform thickness on all surfaces, like dice.  Also, low values for this may result in builds with tops that don’t close up fully (because the fill on the top layers sag into the sparse infill) or bottoms that aren’t fully watertight.

Comments (2)

Skeinforge QuickTip: Tweaking the Speed Knob

skienforge_quicktip_01_02

Skeinforge: Too Many Options

Skeinforge is a pretty big bundle of scripts, and having a first flawed build as your only reference point for going in and fixing the settings can be a pretty daunting task.  Rather than try to provide a full manual, I’m going to present this the way I learned it: one feature at a time.

There are probably well over a hundred teeny tiny knobs you can turn on this beast, but the first one we’ll cover, and one of the more important ones to getting decent builds, is the Speed control:

skienforge_quicktip_01_01

The Speed dialog box controls both how quickly the XY CNC machine will move and how quickly the extruder will push the filament.  If your default settings are giving you messy or stringy builds, this dialog can probably help you.

Key vocabulary words here: Feedrate and Flowrate.  Feedrate is how fast the tool head moves (or in the case of the MakerBot and McWire, how fast the XY table moves) and the Flowrate is how fast the extruder is extruding.  For a clean build, both of these need to be about right with respect to each other, and unfortunately I’ve found it to be a bit of a trial and error process.  (MakerBot users: got a favorite setting for this?)

I like to start from the assumption that I want maximum flowrate (255 on PWM settings) and then set the Feedrate high enough that the bot moves so quickly that this is okay.  This can cause trouble if you’ve got a bot that stops at the end of a line segment in skeinforge, as your effective feedrate will be much slower in more polygon-dense areas.  However, I think the current firmware for the MakerBot and other Sanguino-based implementations has buffering which solves this problem, so going for a high feedrate/flowrate pair is probably ideal in most cases.

With the flowrate set where you like it, you’ll find higher feedrates result in stringy, sparse builds if it’s set too high, and gloppy, heavy builds which rip off the build base as the nozzle picks past dried plastic if it’s set too low.  (I find the latter is way more unpleasant than the former, so I shoot high on feedrate.)

More Skeinforge tips to follow: one bite at a time, it is learnable.

Comments (4)

Blender Select Modes

blender_quicktip_10_01

Today’s Tutorial is by Roger Waggener, professional Blender user!

You can save time editing meshes in Blender by using the different select modes.

When you enter edit mode (by hitting tab with an object selected in object mode) the header of the 3d viewport window changes. Some things disappear, some things appear. Among the things that appear are the select mode buttons. They are three buttons that choose which select mode(s) to use. The left-most one, the vertex select mode button, has three dots on it; the middle one, the edge select mode button, has a single diagonal line on it; and the right-most one, the face select mode button, has a triangle on it.

blender_quicktip_10_05

Vertex select mode is the default and the mode that is probably what you have been using if you aren’t already familiar with this topic. When vertex select mode is active, the button with three dots on it is highlighted and you can interact with individual vertices. Vertex select mode can be very useful when you need it, but it is frequently inefficient for complex selections or many selections of different parts of a mesh.

blender_quicktip_10_02

Edge select mode can save a lot of time when you have several faces to make. Click the edge select button (the one with the line on it) and you will see that the vertex dots disappear. You can now select edges. This makes it quick and easy to move sets of two vertices at once (two vertices make an edge), but also it can speed up creating faces since instead of selecting three or four vertices to make a face, you can simply select two edges. Not only have you saved two clicks, but since edges are larger on the screen than vertices, you have saved time targeting what you want to click. (see Fitts’s Law)

blender_quicktip_10_03

By now you can probably guess what face select mode does. Face select mode is not always as useful for basic mesh editing as vertex or edge mode, but can be very efficient for loop selections and extrusions.

blender_quicktip_10_04

An interesting thing to note about the selection mode buttons is that you can shift-click them to enable more than one mode at once. In fact, you can have all three active at the same time which can make modeling very speedy, but can sometimes make it a bit fiddly to select exactly what you want if you don’t place your clicks carefully.

Try using different select modes and see how much faster you can edit your meshes.

Comments (2)

Blender Quicktip: The Mirror Modifier

blender_quicktip_09_03

The mirror modifier operates in the same framework as the subsurface modifier from the previous tutorial: the modifier stack.  Blender keeps track of a wide variety of operations in this stack, allowing a user to perform transformations without making them permanent or removing the original information that defines the base object.

Let’s start with the output of one of the third-party scripts, the human head generator:

blender_quicktip_09_01

This isn’t much use as half a head, so we hit the same Add Modifier button from the subsurface tutorial:

blender_quicktip_09_06

With the mesh mirrored, we can edit it in edit mode and the edits get copied to the other side:

blender_quicktip_09_04

Hitting the apply button will save the mirrored mesh points into the mesh, which is useful if you want to start with something symmetrical and then begin modifying only one side:

blender_quicktip_09_05

Comments (2)

Blender Tutorial: Subsurface Modeling

blender_quicktip_07_09

(It’s not really fair to call something with this many steps a “quick tip”.)

Blender is capable of some pretty impressive feats of “organic object” modeling, but to do organic modeling easily requires unlocking a popular tool among the 3D animator crowd known as “subdivision modeling”.  The idea behind subdivision modeling is that although the computer needs to draw many, many polygons to approximate a smooth surface, rarely are those smooth surfaces so mathematically complex that they can’t be more easily defined by a set of control points.

Many ways of doing this exist in the field of 3D modeling software, but one of the most intuitive, and one that Blender handles very well, is breaking the mesh down into smaller polygons and twisting them so that they reduce the sharpness of the corners of the original mesh.

If that seems like a bunch of jargon, that’s only because it is– let’s just do it and see what happens.

If you select the default cube, you should see this panel on the lower right:

blender_quicktip_07_01

There’s a long list of options available when you click the “Add Modifier” button, but we’re just going to use “subsurf”.

If you select the default cube and then select subsurf from the Add Modifier menu, you should see the following appear under the Modifiers tab, in what is called the “modifier stack”:

blender_quicktip_07_02

The cube, as you will see, has had each of its six faces subdivided into four smaller ones.  This represents one level of subdivision.  The “levels” item in the subsurf panel shows how many times this subdivision process will be performed by Blender while you’re editing it.  (For solid modeling purposes, we can ignore the “Render Levels” item, which is there so you can have Blender subdivide a model more thoroughly for rendering.)

For every level up we bump the Levels item, every face is subdivided into four new ones.  Below are cubes subdivided one, two, and three times:

blender_quicktip_07_03

The first has 24 faces, the second has 96 faces, and the last one has 384.  As you can see, going much higher than this will start to tax system resources at comparatively little benefit, especially if you select “set smooth” for these objects.

This is an interesting way to turn a cube into a sphere, but so what, right?  Well, the usefulness of this doesn’t become obvious unless we hit tab to switch to Edit mode:

blender_quicktip_07_05

As you can see, Blender’s edit mode is only using the original points.  For this reason, you can now distort the sphere into a bunch of other shapes just by moving the original vertices, which in a subdivided mesh are sometimes called control points.  What’s more, if you use some of the techniques from previous tutorials on this mesh, you can quickly produce some very organic-looking shapes with comparatively few operations:

blender_quicktip_07_06

This nifty teardrop shape was made with just two extrude operations and some scaling.  Pretty neat, huh?

Of course, if you use this very long, you’ll start to get frustrated by the way you have to pull verts through each other to get some effects, as well as how cluttered the view gets when you have a large, complex shape.  This is why the Blender developers have included the following option, although I may never know why they hid it so well.

blender_quicktip_07_07

See that little unassuming circle?  Click it.

blender_quicktip_07_08

NOW we’re talking!  With the “true” position of the original control points hidden, the view of the model is drastically simplified, but all the operations of extrusion, twisting, scaling and so on still can be applied to it.  The model we saw at the beginning of this tutorial was done in maybe three minutes of fiddling around!

Comments (1)

Blender Quicktip: Wireframe Mode for Safety!

blender_quicktip_05_02

The Wireframe “Draw type” can be terribly useful for building complex objects, since it automatically culls all co-planar face edges, which is to say that flat areas are drawn as though they were single complex faces instead of the cluster of simple faces they really are.

This has one obvious benefit and one subtle one.  The obvious one is that you can see what the heck you’re doing when looking at a complex mechanical design.  The less obvious one is that when something is wrong with your mesh, wireframe mode will often draw a big bright white line where otherwise Blender might not give you any clue that skeinforge wouldn’t like a mesh.

Take these two objects:

blender_quicktip_05_01

One of them skins, one of them doesn’t.  Blender’s solid mesh vier renders them exactly the same.  However, switching to wireframe mode makes it pretty obvious

blender_quicktip_05_03

The cylinder on the left will not slice in skeinforge and in fact will spray errors like the dickens.  The one on the right will slice with no problems.  Both look identical in solid view, but here in wireframe, Blender knows that the top faces are not truly coplanar (they have infinitely thin slices in them) and so does not render them as a single face.  I purposefully generated this particular example by extruding the cylinder on the left with the “individual faces” option instead of the “region” option, but this and a number of other operations in Blender (including booleans on some kinds of meshes) can create invisible but lethal (to skeinforge anyway) kinks in the mesh topology.  In predominantly flat geometry, as is common with mechanical designs, the wireframe draw mode makes these errors stand out like a sore thumb!

Comments (2)

Blender Quicktip: Snap

blender_quicktip_04_01

Precision mechanical CAD tools come with a wide variety of snap tools.  Blender is relatively light in this department (its primary users are animators, not engineers) but there is a snap menu and it can be pretty useful.

The snap menu is in the object menu in object mode, and in the mesh menu in edit mode.  It can be summoned in either mode by pressing shift-s, however.  Here are your available functions:

Selection to Grid – In edit mode, each selected vertex will move to the nearest grid node.  In object mode, object pivots are positioned to the nearest grid node.  The grid in these matters is defined as whichever grid is visible in the current view.  This means that zoomed well away, the grid might be one meter spacing, and zoomed in it might be one millimeter spacing.  This can be irritating, but it’s better than nothing.

Selection to Cursor – In edit mode, selected vertices move to the cursor position.  In object mode, selected objects move so their pivots are centered on the cursor.  (The cursor is that little life-raft looking thing.)

Selection to Center – Again, affects vertices in edit mode, objects in object mode.  Moves all selected items to their geometric center.

Cursor to Selection – Moves the cursor to the center of the selected objects.  (If one object is selected, cursor moves to it.)

Cursor to Grid – Moves the cursor to the nearest available grid node, again dependent on which grid is the smallest visible.

Cursor to Active – Moves the cursor to the active object.  This is the most recently selected object in the case of multiple selections.

These snap commands are a lot more limited than many CAD tools, but they’re enough that an experienced user can recreate many of the more advanced functions with some slight of hand.  For a great example of that, see rab3D’s tutorials on Blender for Precision Modeling.

Leave a Comment