← Work / Projects

First-year design project · 2013

LEGO CNC mill

A first-semester LEGO Mindstorms assignment we finished in a day, so a partner and I kept going and built a CNC mill that reads industry-standard G-code and carves clean 3D shapes out of foam.

Role
Co-designer, with a partner
When
Fall 2013, first semester of Mechatronics
Hardware
LEGO Mindstorms NXT · 1/16″ drill bit
Software
G-code interpreter · feedforward + PD control · Python server
The LEGO CNC mill cutting foam
The mill cutting foam
~0.001″
Motion per encoder tick after gearing
< 1 tick
Average position error from the axis controllers
3.5 h
To carve an Iron Man head from floral foam
G-code
Industry-standard input, like a real CNC machine

The build

At the end of my first semester of Mechatronics at the University of Waterloo, we were assigned a LEGO Mindstorms NXT design project. We met the requirements in a day, so a partner and I decided to build a LEGO CNC mill, inspired by one on YouTube.

Three motors drive the X, Y and Z axes, each with a touch-sensor limit switch for homing. A separate high-speed LEGO motor spins a 1/16-inch drill bit through floral foam, which is soft enough to cut like butter.

Control

LEGO motors have built-in encoders, and with our gearing one tick was about a thousandth of an inch. After testing several approaches, a feedforward plus PD controller held the average error under one tick. Cutting forces in foam are tiny, so a simple controller worked well.

G-code, and running out of memory

G-code is well documented and straightforward to interpret, but files for complex parts were far too large for the NXT’s memory, even with custom compression. So we ran a Python server on a laptop that fed the NXT file chunks one at a time, watching for each chunk to be consumed and keeping one buffered.

Control path

  1. Input
    G-code file
  2. Streaming
    Python serverOn a laptop, streams file chunks as the NXT needs them
  3. Interpreter
    NXT interpreterDecodes G-code moves
  4. Control
    Feedforward + PDOne loop per axis
  5. Axes
    X · Y · Z motorsPlus a high-speed spindle
G-code to cutting motionSimplified

Mechanics

We shimmed the linear rails to take up slack, used chain in the gear reductions for lower backlash, and built the frame rigidly to avoid low-frequency vibration. The finished machine carved an Iron Man head in about three and a half hours.

The LEGO mill built into an open-fronted black box, its gantry and drill above two carved foam pieces, one an Iron Man helmet
The finished mill with two carvings
An Iron Man helmet carved in relief from green floral foam, with lettering above and below, held in a hand
Iron Man head, about 3.5 hours of cutting

Related