Archive for category Software

MPCNC: Pen Holder Crunch

A few tweaks to the Customizable MPCNC Mount for Round Tools produces a Sakura Micron pen holder:

MPCNC - Sakura Pen Holder - Slic3r preview

MPCNC – Sakura Pen Holder – Slic3r preview

The pen body seats atop the holder, with its narrower snout inside the clamp, giving positive control of the point position:

MPCNC - Sakura in pen adapter

MPCNC – Sakura in pen adapter

Unfortunately, should one forget to zero the pen tip to the paper surface before starting a plot, Bad Things happen to good tips:

MPCNC - Sakura pen - crushed tip

MPCNC – Sakura pen – crushed tip

The holder really needs at least a few millimeters of compliance, as a fiber-tip pen makes a fairly delicate tool not intended for applying much force at all to anything.

But the holder might make a Z axis probe …


, ,


MPCNC: Rail Height Measurements and Plot Effects

After once again figuring out how to read a vernier height gage, I measured the height of each end of the MPCNC rails:

Brown and Sharpe 585 Height Gage

Brown and Sharpe 585 Height Gage

The process:

  • Position the gage near the end of the gantry’s travel
  • Twiddle the knurled ring to lower the probe (a.k.a. lathe bit) until …
  • It firmly captures the paper slip, then …
  • Twiddle the ring the other way until …
  • The paper barely moves
  • Read the vernier and take a picture

So the numbers come out one paper thickness higher than the actual rail height; subtract 0.1 mm = 4 mil to get the true height:

MPCNC Rail Height - 2017-12-23

MPCNC Rail Height – 2017-12-23

In round numbers, the difference is under 0.3 mm along each rail.

The outer numbers on the lower sketch show the difference between each reading and the lowest value along that axis: the left rear corner is (roughly) 0.5 mm higher than the right front. The numbers inside the square give the additional height, rounded to sensible values, required to raise the low corners.

Which means you can’t plot at, say, Z=-0.2 mm to reduce the pen loading, because the pen doesn’t uniformly touch the paper across the entire plot:

MPCNC - Unlevel Z -0.2 plot

MPCNC – Unlevel Z -0.2 plot

These images have been perspective & aspect ratio corrected, then ruthlessly contrast-stretched to make the traces visible; the lighting isn’t that awful in person!

With the plot at Z=-0.2, the legends toward the front came out OK, but they’re missing along the far edge. The Spirograph traces go completely missing toward the left rear as the pen rises away from the paper, although I think we’re also seeing some ripples in the paper sheet.

Although such a small error probably makes no difference to a wood router, let’s see what we can do.

Manually editing the G-Code to put successive traces at 0.1 mm increments from Z=-0.3 to Z=-0.6 mm, then replotting on the same piece of paper, shows the problem a bit better:

MPCNC - Unlevel plot - multiple Z

MPCNC – Unlevel plot – multiple Z

All of the legends remain at Z=-0.2, because I wasn’t up for editing every pen-down command.

Even at Z=-0.6 mm, the pen doesn’t quite touch in the left rear corner. Previously, I’d been plotting at a nice, round Z=-1.0 mm, which worked fine. I didn’t run any tests below Z=-0.6, but I think Z=-0.8 would draw a complete plot.

That agrees reasonably well with the height gage measurements.

It’s obviously impossible to re-level the rails by dinking around with the corner post lengths, because I can’t move the EMT in precise increments and it’d never stay in that position anyway. Instead, I should slide shims under the three lowest corner feet to raise them enough to match the left rear corner.



MPCNC: Plotter Pen Holder Spring Constant

Watching the MPCNC plot Spirograph patterns led me to wonder about how much force the printed drag knife holder applies to the pen:

Spirograph - liquid ink pen - detail

Spirograph – liquid ink pen – detail

The HP 7475A plotter spec calls for 19 g = 0.67 oz of downward force on the pen, so, in an ideal world, one might want to use one’s collection of aging plotter pens in a similar manner.

Plotter pen, meet digital scale:

MPCNC - Plotter pen force test

MPCNC – Plotter pen force test

Stepping the pen downward in 0.1 mm increments produced a set of numbers and a tidy linear fit graph:

MPCNC Plotter Pen Holder - Spring Constant

MPCNC Plotter Pen Holder – Spring Constant

I hereby swear I’m not making things up: the spring constant really is a nice, round 100 g/mm!

I set plot_z = -1.0 in the GCMC program, with Z=0.5 touched off atop a defunct ID card on the paper surface to compensate for any tabletop warp / bow / misalignment, plus any errors from the tool length probe. An eyeballometric scan against a straightedge shows pretty nearly no misalignment, which means the holder mashes the pen against the paper with about 100 g of force, five times the HP spec.

A distinct case of pen abuse rears its ugly head.

It’s time to conjure a height probe for the tool holder.


Spirograph Random Numbers: What Are The Odds?

The GCMC Spirograph Generator program chooses parameters using pseudo-random numbers based on a seed fed in from the Bash script, so I was surprised to see two plots overlap exactly:

Overlaid pattern - G-Code simulator

Overlaid pattern – G-Code simulator

The two overlapping traces are the 15 inward-pointing wedges around the central rosette.

The first one:

(PRNG seed: 38140045)
(Paper size: [16.50in,14in])
(PlotSize: [15.50in,13.00in])
(Stator 3: 150)
(Rotor  4: 40)
(GCD: 10)
(Offset: -0.94)
(Dia ratio: -0.27)
(Lobes: 15)
(Turns: 4)
(Plot scale: [5.11in,4.29in])
(Tool change: 1)

The second one:

(PRNG seed: 74359295)
(Paper size: [16.50in,14in])
(PlotSize: [15.50in,13.00in])
(Stator 3: 150)
(Rotor  4: 40)
(GCD: 10)
(Offset: -0.93)
(Dia ratio: -0.27)
(Lobes: 15)
(Turns: 4)
(Plot scale: [5.12in,4.30in])
(Tool change: 3)

The Offset isn’t quite the same, but the pen width covers up the difference.

With only four Stators and 17 Rotors, the probability of picking the same pair works out to 0.25 × 0.059 = 1.4%. You can sometimes get the same number of Lobes and Turns from several different Stator + Rotor combinations, but these were exact matchs with the same indices.

The Pen Offset within the Rotor comes from a fraction computed with ten bit resolution, so each Offset value represents slightly under 0.1% of the choices. If any four adjacent values look about the same, then it’s only eight bits of resolution and each represents 0.4%.

The Rotor and Stator set the Diameter ratio, but the sign comes from what’s basically a coin flip based on the sign of a fraction drawn from 256 possibilities; call it 50%.

Overall, you’re looking at a probability of 28 ppm = 0.0028%, so I (uh, probably) won’t see another overlay for a while …

I don’t know how to factor the PRNG sequence into those numbers, although it surely affects the probability. In this case, two different seeds produced nearly the same sequence of output values, within the resolution of my hack-job calculations.

Whatever. It’s good enough for my simple purposes!


Leave a comment

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)
# 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/ ; 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)
  rnd=$(date +%N)
  gcmc -D Pen=$p -D $Paper -D PRNG_Seed=$rnd $Flags $LibPath -q "$Spirograph" >> $fn

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:


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:


1 Comment

MPCNC: GCMC Text vs. Speed

GCMC includes single-stroke fonts derived from Hershey fonts, so I added a legend to the Spirograph Shakedown generator:

MPCNC - GCMC Text - 3000 mm-min

MPCNC – GCMC Text – 3000 mm-min

Obviously, plotting 2.5 mm tall characters at 3000 mm/min = 50 mm/s isn’t a Good Idea on a less-than-absolutely-rigid CNC machine.

Slowing down to 250 mm/min = 4.2 mm/s produces much better results:

MPCNC - GCMC Text - 250 mm-min

MPCNC – GCMC Text – 250 mm-min

A closer look, albeit with less-than-crisp focus:

MPCNC - GCMC Text - 250 mm-min - detail

MPCNC – GCMC Text – 250 mm-min – detail

This isn’t a conclusive test, but it reminds me that Speed Kills.

The green plotter pen started life with a standard 0.3 mm felt nib, but it’s worn somewhat wider over the intervening years decades. Those 2.5 mm characters would look better coming from a narrow ceramic pen, which would require a pen change before doing the legend; using 4 mm characters would produce better results.

The line spacing is 110% of the font X height, which obviously isn’t quite enough. Something on the order of 150% should look better.

This GCMC code (including those mods) produces the legend:


textsize = [4.0mm,4.0mm];
textat = [0.5*PlotSize.x/2,-PlotSize.y/2 + 2*textsize.y];

textpath = typeset("Seed: " + PRNG_Seed + "  Stator: " + StatorTeeth + "  Rotor: " + RotorTeeth,FONT_HSANS_1);
scalepath = scale(textpath,textsize);
placepath = scalepath + textat;

textpath = typeset("Offset: " + L + "  Lobes: " + Lobes + "  Turns: " + Turns,FONT_HSANS_1);
scalepath = scale(textpath,textsize);
placepath = scalepath + textat + [-,-1.5*textsize.y];



MPCNC: Spirograph Exerciser

Both bCNC and GCMC include Spirograph generators with more-or-less fixed patterns and sizes, because the code serves to illustrate the software’s capabilities:

MPCNC - bCNC Spirograph patterns

MPCNC – bCNC Spirograph patterns

GGMC Cycloids test patterns

GGMC Cycloids test patterns

I wanted to exercise my MPCNC’s entire range of travel, familiarize myself with some new GCMC features, and, en passant, mimic the actual gears in a classic Spirograph, so, of course, I had to write a Spirograph emulator from scratch:

MPCNC - Full-platform Spirograph - multicolor

MPCNC – Full-platform Spirograph – multicolor

The perspective makes a 29×19 inch sheet of paper (made from three B sheets and one A sheet) look not much larger than the 17×11 inch B size sheets in the first two pictures. IRL, it’s a billboard!

My GCMC code uses notation and formulas from a paper (tidy PDF) on a Gnuplot spirograph generator, with a dash of error checking from the GCMC source.

The code enumerates the possible gear tooth counts in a pair of vectors from which you select the desired stator and rotor gears using integer subscripts. Because I eventually scale the results to fit the plot area, there’s no need to keep track of actual gear pitch diameters.

Similarly, the pen offset from the center of the rotor gear is a pure number, which you can think of as the ratio of the offset to the rotor diameter. It can have either sign and may exceed unity, as needed, either of which would be difficult with a physical gear.

Figuring the number of rotor turns required to complete the pattern requires reducing the gear ratio to a fraction with no common factors, so I wrote a Greatest Common Divisor function using Euclid’s algorithm adapted for GCMC’s bitwise tests and shifts.

With those values in hand, a loop iterates around the entire pattern to produce a list of XY coordinates in normalized space. Because the formula doesn’t have the weird properties of the Superformula I used with the HP 7475 plotter, I think there’s no need to prune the list to eliminate tiny moves.

Scaling the entire plot requires keeping track of the actual extents along both axes, which happens in the loop generating the normalized coordinates. A pair of gears producing an odd number of lobes can have different extents in the positive and negative directions, particularly with only a few lobes (3, 5, 7 …):

Spirograph - 3 lobes - QnD Simulator

Spirograph – 3 lobes – QnD Simulator

So I accumulate all four, then scale based on the absolute maximum; I added scalar min() and max() functions.

Converting the list of scaled points into G-Code turns out to be a one-liner using GCMC’s tracepath() library function. Previewing the results in a Web-based simulator helps weed out the duds.

The code needs cleanup, in particular to let a Bash script set various parameters, but it’s a good start.

The GCMC source code as a GitHub Gist:

, ,