Advertisements

MPCNC: Spirograph Generator with Tool Changes

An improved version of my GCMC Spirograph pattern generator, now with better annotation and tool changes:

Spirograph pattern - overview

Spirograph pattern – overview

The GCMC code sets the stator and rotor gear tooth counts, the rotor diameter, and the pen offset using a pseudo-random number generator. This requires randomizing the PRNG seed, which I do in the calling script with the nanosecond of the current second: rnd=$(date +%N).

The G-Code file name also comes from the timestamp:

ts=$(date +%Y%m%d-%H%M%S)
fn='Spiro_'${ts}'.ngc'
# blank line to make the underscore visible

Which means you must call the Bash script slowly to generate a pile o’ plots:

for i in {1..60} ; do sh /mnt/bulkdata/Project\ Files/Mostly\ Printed\ CNC/Patterns/spiro.sh ; sleep 1 ; done

Sift through the heap with drag-n-drop action using an online G-Code previewer. There seems no clean way to convert G-Code to a bitmap on the command line, although you can do it manually, of course.

The GCMC program spits out the G-code for one plot at a time, so the Bash script calls it four times to fill a sheet of paper with random patterns:

for p in $(seq 4)
do
  rnd=$(date +%N)
  gcmc -D Pen=$p -D $Paper -D PRNG_Seed=$rnd $Flags $LibPath -q "$Spirograph" >> $fn
done

The -q parameter tells GCMC to not include the prolog and epilog files, because the calling script glues those onto the lump of G-Code for all four plots.

The -D Pen=$p parameter tells the GCMC program which “tool” to select with a Tn M6 tool change command before starting the plot. Although plotter pens have a well-defined position in the holder and a pretty nearly constant length, you must have a tool length probe installed and configured:

MPCNC Tool Length Probe - Plotter Pen

MPCNC Tool Length Probe – Plotter Pen

Set the overall sheet size in inches or millimeters to get a plot centered in the middle of the page with half-inch margins all around:

Paper='PaperSize=[16.5in,14in]

With all that in hand, those good old black ceramic-tip pens give impeccable results:

Spirograph pattern - black ceramic pen - detail

Spirograph pattern – black ceramic pen – detail

The surviving ones, anyhow. I must apply my collection of Sakura Micron pens to this task.

The other three colors come from fiber pens with reasonably good tips:

Spirograph pattern - central details

Spirograph pattern – central details

They’re a lot like diatoms: all different and all alike.

The GCMC and Bash source code as a GitHub Gist:

Advertisements

,