Friday, July 22, 2011

OpenSCAD Tip: Scan into SCAD

Making complex geometry with OpenSCAD can be a painful but there are some tricks to making the process easier. This tutorial will show you how to use a scanner to build speaker mounts for a TurtleBot.

We selected the Logitech Z110 Stereo Speakers for affordability and aesthetics, however one issue that was quickly noticed is the lack of screws.


Therefore we are going to build an adapter to attach to the bottom of the speaker that will provide a mounting point. The adapter will need to fit into the curved groove that previously held a foam pad. One option for making a plastic part that fits into the groove would be to make several measurements and attempt to reproduce the curve. Another approach would be to take a photo and model the curve with the photo as a reference. The easiest approach however is to use a regular flatbed scanner to scan the bottom and then vectorize the scan.

The speaker is placed on top of the scanner and scanned into GIMP. Once imported, the select tool can be used to extract the needed curve data. The levels can then be adjusted to produce a crisp outline.

Once a clean raster outline of the needed curve has been obtained, we can save the image and proceed to vectorization.

Next, import the image into Inkscape.

Select the bitmap object and select 'Path > Trace Bitmap...' from the menu.

Adjust the options if needed and execute the tracing operation.

After tracing is completed there will be both a raster version and a vector version, separate the objects a delete the raster version.

Select the nodes of the object and select 'Path > Simplify...' from the menu.This will smooth out the rough edges. At this point you can manually edit the curves if desired.

Since the DXF export in Inkscape is limited and support for DXF in OpenSCAD is limited, the normals of the curve data are not preserved and the curves must be converted into a series of straight line segments.

Select the nodes and press the 'Insert new nodes into selected segments' button on the toolbar. This tutorial might also be helpful for the rest of the process of getting the curves into OpenSCAD. Press the button a few more times until the curves have plenty of points.

Next, press the 'Make selected segments lines' button on the toolbar.

Now rotate and rescale the curves until they are 1:1 scale. It might be useful here to print out a copy and compare it to the actual part.

Next open the document properties and select 'Fit page to selection'. Once that is done, save the document as a 'Desktop Cutting Plotter (R13) (*.dxf)' file.

For this project we also created a version of the curve data with the center filled in to use as a base. This data is also saved in DXF format.

Now it's time to start up OpenSCAD!
translate(v = [0,248,0]) {
linear_extrude(file = "edge.dxf", height = 1.5, center = false, convexity = 10, twist = 0);
}

Importing the DXF file is fairly straightforward however there are a few things to keep in mind. First, the curves may be extruded in an unexpected position of oritentation, so you may need to zoom out or rotate the view to find them, and it will take a little experimentation to move the curves where you want them. Next, If you edit your curves in imperial units in Inkscape they will automatically be converted to metric in OpenSCAD.


As usual, the source files for this project can be found on Thingiverse.

The results with #6-32 nuts installed.

Snap fit tolerance on the first try! The center hole provides a point to fill with hot glue to attach the part more securely.

More details and pictures of it in action here.

No comments: