Fighting with computers

Computers are not always friendly.

Sunday, February 22, 2015

3D Tool path generation

I needed for a project to create a parallel finishing tool path similar what many CAM software does. There is nothing wrong with existing CAM software but what fun would be to just buy and use the software.

The basic idea is that you can use a swipe plane across the mesh representing your volume and get the top part of each slice to be the tool path. A similar idea is used for 3D printing, but there the swipe plane is an horizontal one and object is built from the bottom up.

The problem is that you cannot use the slice you just obtain from the mesh as milling bit (or extruded filament if 3D printing) has a non-null dimension. Because of that, just following the contour of the object will create a smaller result than the model.

For 2.5D milling you can do a waterline finishing, doing flat passes on XY-plane. Thus a simple polygon offsetting operation can help you get the part dimensions right. But for 3D milling, the tool compensation becomes more difficult.

The solution I opted for was to perform a mesh offsetting. Three different ideas can be used for the operation:

  1. Facets can be offset following the normal direction.  Mesh becomes full of gaps
  2. Edges can be offset following the a combination of the two normals of the two triangles sharing that edge.
  3. Vertices can be offset too. The question is that what is the better way of combining the normals of the three triangles each vertex shares. 
A quick look at the vertex normals calculation available in Meshlab gives four different methods. Before committing to code anything, a quick test would be welcome. 

I have done a simple test, that proved useful: after calculating vertex normals, I can export the file from Meshlab. Using PLY format instead of STL allows me to output each vertex's normal. If now I do some math with a script I can do the offset and test the result. 

Most time was lost due to a particular "feature" of awk in OSX. Once this was fixed I was able to offset the vertices of the mesh and prepare the correct tool path.

Friday, February 13, 2015

Barcode listings with data

A few weeks ago I mentioned a new tool I created for (allegedly) making my life easier when delivering marked exams to my students. Then I covered the process that happens after the exam. But one key element it was not mentioned is what it needs to do in advance.

For my system I needed a set of labels. My prototype used Code-128 barcode that can handle ASCII code to encode each student email using barcode command-line program for Linux. The only problem with that was the lack of additional information being added to the label, such as the student name.

Looking around I found a very handy tool by AVERY company, that helps you creating labels on-line for all their range of labels. What is even better is the tool will allow you to upload an excel file with data columns, like names and addresses to create a custom listing you designed and export it as PDF (they offer to print it for you to and deliver the labels to your office too).

After some tweaks and, the most difficult part, discovering the reference of my European A4 labels on their site, I get a set of working labels but this time using 2D QR codes that are a bit more reliable than 1D barcodes.

But I was left with a bit of an itch that I should be looking for a way of solving the problem entirely with my own software instead of using an online application, as importing a new list of students required a bit of touching here and there.

Not knowing what could do the job more easily, I turned to the ZXing library I am already using for decoding and I saw there is an encoder too. And given that creating a PDF output seemed to work well for AVERY I decided to do the same, this time using Processing, as it tends to make my life easier than when using Java.


The function above will create a QR code as an image you can later place inside a PDF page following the pattern you want. Going from BufferedImage to PImage took me like one hour to get right, as it seems Processing has been going through different solutions to that in the past, most of them no longer working.

So now I do have a tool that creates the labels from a CSV files with students name and addresses. I am looking forward to use these tools in the coming months.

Saturday, February 07, 2015

Maple Mini looking good

This week I received a real bargain I wanted to test as a better candidate to be able to control several DC motors in closed loop.

I have already tested the STM Nucleo 401 board and I get one 32 bit, signed, hardware encoder input on timer 2 and three more unsigned, 16-bit hardware encoder inputs on other timers. Unfortunately timer 5 was taken by the mbed library I was using. Nucleo is a solid platform and using the cloud IDE actually is not big deal for me.

But now I have got a Maple Mini for $4 and I have to tell you I am totally sold. It is so much faster compared to an ATMega Arduino that I am positive it can do the work for controlling two DC motors closed-loop and most likely it can do four or more.

The board can handle up to 16 external interrupts, enough for 8 encoders, and it can produce 12 PWM 16-bit resolution outputs (a far cry from 8 bit PWM from Arduino, though I am not sure that will have any impact on the system performance) plus plenty of memory (128K flash, 20K RAM), serial ports and other nice touches.

Like any other Cortex-3 it runs off 3.3V power, which I thought it will be a pain as encoder circuit is rated at 5V, but a quick test revealed encoder seems to be working happily when powered at 3.3V too. That saves me some trouble with interface and gives me more freedom as not all the input pins are 5V tolerant.

Though the Maple family has been around for quite a while (2009) I have never used it before. And my first experience has been a blast too, because the Arduino IDE clone is what they use, so it all seems pretty familiar for long-time Arduino users.

I guess that sooner or later I will need to venture in some of these detailed user manuals for setting some feature on, but for the moment the sample programs and online help are being good enough.