The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Category: Software

General-purpose computers doing something specific

  • CNC Kitchen Sink Strainer

    CNC Kitchen Sink Strainer

    Our Young Engineer recently rented a house, now knows why our sinks have CNC-machined strainers, and asked for something better than the disgusting stainless mesh strainer in the kitchen sink.

    Being a doting father, I turned out a pair to get a pretty one:

    CNC Sink Strainer - overview
    CNC Sink Strainer – overview

    They’re made from the same scrap smoked acrylic as the ones in our sinks:

    CNC Sink Strainer
    CNC Sink Strainer

    They’re definitely upscale from the (not watertight!) 3D printed version I built for a Digital Machinist column to explain OpenSCAD modeling:

    Strainer plate fill
    Strainer plate fill

    This time around, though, I rewrote the subtractive design in GCMC, with helical milling for all the holes to eliminate the need to change tools:

    Sink Strainer - tool path simulation - CAMotics
    Sink Strainer – tool path simulation – CAMotics

    They’re done on the Sherline, because it has real clamps:

    CNC Sink Strainer - on Sherline
    CNC Sink Strainer – on Sherline

    Four tabs eliminated the need to reclamp the stock before cutting the perimeter, but I should have ramped, not plunged, through the final cut between the tabs:

    CNC Sink Strainer - tab surface fracture
    CNC Sink Strainer – tab surface fracture

    The handles come from the same chunk of hex acrylic as before, eyeballed to length, tapped 8-32, and secured with acrylic adhesive.

    The GCMC source code as a GitHub Gist:

    // Drill & mill sink drain strainer
    // Ed Nisley KE4ZNU — Digital Machinist 15.2 Spring 2020
    // polycarbonate or acrylic sheet
    // External clamps at corners
    // Origin at center of sheet
    //—–
    // Dimensions
    DiskOD = 80.0mm; // usual kitchen drain = 3-1/4 inch
    DiskRad = DiskOD/2;
    PlateThick = 6.0mm; // stock thickness
    MillOD = 3.170mm; // measured end mill OD
    HoleDia = 4.75mm; // 3/16 inch drain holes
    ScrewOD = 0.18in; // knob screw clearance
    NumRings = 3; // rings of drain holes
    RingSpace = 1.5 * HoleDia; // .. between rings
    MaxZCut = 0.25 * MillOD; // max cut depth
    MillSpeed = 1000mm; // horizontal feedrate
    NumTabs = 4;
    TabTilt = 45deg;
    TabLength = 5.0mm;
    TabThick = 0.5mm;
    SafeZ = 10.0mm; // above all obstructions
    TravelZ = 1.0mm; // within engraving / milling area
    MillZ = -(PlateThick + 0.5mm); // through disk into spoil board
    TwoPi = 2*pi();
    //—–
    // Mill one hole
    function MillHole(ctr,radius,turns) {
    goto([-,-,TravelZ]);
    goto(head(ctr,2) + [radius,-,-]);
    goto([-,-,0]); // kiss surface
    circle_cw(ctr,turns); // helix downward
    circle_cw(head(ctr,2)); // remove last ramp
    goto(ctr); // get elbow room
    goto([-,-,TravelZ]);
    }
    //—–
    // Start cutting!
    goto([-,-,SafeZ]);
    goto([0,0,-]);
    goto([-,-,TravelZ]);
    feedrate(MillSpeed);
    // Mill center screw hole
    comment("– Center hole");
    ctr = [0,0,MillZ];
    MillHole(ctr,(ScrewOD – MillOD) / 2,ceil(abs(ctr.z) / MaxZCut));
    // Mill hole rings
    comment("– Drain hole rings");
    repeat (NumRings; ri) {
    comment("Ring: ",ri);
    rr = DiskRad – ri*RingSpace; // ring radius
    comment(" radius: ",rr);
    nh = to_int(floor(TwoPi*rr / (2*HoleDia))); // number of holes
    comment(" holes: ",nh);
    repeat(nh; h) {
    a = (h – 1) * TwoPi / nh; // angle of hole
    ctr = [rr*cos(a),rr*sin(a),MillZ]; // center point at ending Z
    MillHole(ctr,(HoleDia – MillOD)/2,ceil(abs(ctr.z) / MaxZCut));
    }
    }
    // Mill perimeter
    comment("– Perimeter");
    r = DiskRad + MillOD/2;
    goto([r,0,-]);
    goto([-,-,0]);
    ctr = [0,0,-(PlateThick – TabThick)];
    circle_ccw(ctr,ceil(abs(ctr.z) / MaxZCut)); // ramp downward
    circle_ccw(ctr,1); // remove last ramp
    goto([-,-,TravelZ]);
    comment("– Tabs");
    ta = 360deg / NumTabs; // between tabs
    tsa = to_rad(TwoPi*((TabLength + MillOD) / (TwoPi * r))); // subtended tab angle
    repeat (NumTabs; i) {
    comment(" # ",i);
    a = TabTilt + (i – 1)*ta; // tab center angle
    p0 = [r*cos(a + tsa/2),r*sin(a + tsa/2),MillZ]; // entry on ccw side
    p1 = [r*cos(a + ta – tsa/2),r*sin(a + ta – tsa/2),MillZ]; // exit at next tab
    if (0) {
    comment(" angle: ",a);
    comment(" entry: ",p0);
    comment(" exit: ",p1);
    }
    goto(head(p0,2)); // to entry point
    move(p0); // plunge through
    arc_ccw(p1,r);
    goto([-,-,TravelZ]);
    }
    goto([-,-,SafeZ]);
    goto([0,0,-]);

    All in all, a pleasant diversion from contemporary events …

  • GRBL Error 33: Arc Coordinates vs. Decimal Places

    GRBL Error 33: Arc Coordinates vs. Decimal Places

    The LinuxCNC G2/G3 arc command doc has this to say about numerical precision:

    When programming arcs an error due to rounding can result from using a precision of less than 4 decimal places (0.0000) for inch and less than 3 decimal places (0.000) for millimeters.

    So I normally set GCMC to produce three decimal digits, because its default of eight digits seems excessive for my usual millimeter measurements, and assume whatever G-Code sender I use won’t chop digits off the end in passing. Mistakenly setting bCNC to round at two decimal places showed what happens with fewer digits, as bCNC’s default is four decimal digits.

    A closer look at the coordinates in the lower right part of the spreadsheets (from yesterday) shows the limited accuracy with two decimal digits:

    Spreadsheet - GCMC 2 digit - full path - detail
    Spreadsheet – GCMC 2 digit – full path – detail

    The red blocks mark the first failing arc, where the relative error falls out of tolerance. If GRBL were less fussy (which it should not be), then the next arcs would proceed as shown.

    Rounding to three decimal digits pushes the errors into to the third place, with the yellow highlight marking the worst errors:

    Spreadsheet - GCMC 3 digit - detail
    Spreadsheet – GCMC 3 digit – detail

    As you should expect, the smallest arcs have the largest relative errors, although they’re now well within GRBL’s (and LinuxCNC’s, for that matter) limits.

    Rounding to four decimal digits makes the errors vanishingly small:

    Spreadsheet - GCMC 4 digit - detail
    Spreadsheet – GCMC 4 digit – detail

    So, by and large, don’t scrimp on the decimal digits … but we knew that already.

    I’d been setting GRBL to produce three decimal places, but now I’m using four. Adding a few characters to each G-Code command reduces the number of commands fitting into GRBL’s buffer space, but bCNC normally keeps it around 90% full, so the path planner should remain perfectly happy.

  • GRBL Error 33: G-Code Arc Tolerances

    GRBL Error 33: G-Code Arc Tolerances

    After figuring out how two-place decimal fractions caused this blooper, I had to poke into the debris field surrounding the crash:

    Tek CC - top deck - failed arcs
    Tek CC – top deck – failed arcs

    The bCNC Terminal trace stops at the first failure, so I set GCMC to produce two-place fractions (“Number of decimals less than 3 severely limits accuracy”), then rammed the NGC file’s G-Code into a spreadsheet:

    Spreadsheet - GCMC 2 digit - full path
    Spreadsheet – GCMC 2 digit – full path

    The last two columns (perhaps you must open the image in a new tab to see the whole thing) compute the GRBL error values: the absolute difference between the two radii and that difference as a fraction of the radius. The R Error header under Start should be X, of course; I’ll regenerate the images for the DM column.

    The reduced accuracy of the two-digit fractions triggers the error marked by the red cells, where the radii differ by 0.0082 mm (>0.005) and the relative error is 0.17% (>0.1%).

    Suppressing the first failed arc by passing the same starting point to the next arc simulates the second failure:

    Spreadsheet - GCMC 2 digit - suppress first failed arc
    Spreadsheet – GCMC 2 digit – suppress first failed arc

    Similarly, the third arc from the same point fails:

    Spreadsheet - GCMC 2 digit - suppress second failed arc
    Spreadsheet – GCMC 2 digit – suppress second failed arc

    The fourth arc becomes a full circle and produces the circular gash across the deck:

    Spreadsheet - GCMC 2 digit - suppress third failed arc
    Spreadsheet – GCMC 2 digit – suppress third failed arc

    Two digits definitely aren’t enough!

  • bCNC Rounding vs. G-Code Arcs: GRBL Error 33

    bCNC Rounding vs. G-Code Arcs: GRBL Error 33

    While cutting the top deck of the Pickett-flavored Tek Circuit Computer on the MPCNC, this happened:

    Tek CC - top deck - failed arcs
    Tek CC – top deck – failed arcs

    I traced the off-center circle with a marker to make it more visible, as it’s the drag knife cut that should have been the exit move after completing the window.

    Huh. It never did that before …

    The bCNC plot looked fine, but the Terminal log showed three Error 33 reports:

    Failed arc command - bCNC screen - terminal and plot
    Failed arc command – bCNC screen – terminal and plot

    The GRBL doc has this to say about Error 33:

    The motion command has an invalid target. G2, G3, and G38.2 generates this error, if the arc is impossible to generate or if the probe target is the current position.

    The error messages don’t occur immediately after the failing G2/G3 command, because bCNC sends enough commands to keep the GRBL serial input buffer topped off. After GRBL sends the error message, it continues chewing its way through the buffer and, when bCNC notices the first error, it stops sending more G-Code commands and shudders to a stop.

    The great thing about Free Software is that when it breaks, you have all the pieces. Looking into the GRBL source code provides a definition of Error 33:

    // [G2/3 Offset-Mode Errors]: No axis words and/or offsets in selected plane. The radius to the current
    //   point and the radius to the target point differs more than 0.002mm (EMC def. 0.5mm OR 0.005mm and 0.1% radius).

    Which doesn’t quite match the code, but it’s close enough:

    // Compute difference between current location and target radii for final error-checks.
                float delta_r = fabs(target_r-gc_block.values.r);
                if (delta_r > 0.005) {
                  if (delta_r > 0.5) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Arc definition error] > 0.5mm
                  if (delta_r > (0.001*gc_block.values.r)) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Arc definition error] > 0.005mm AND 0.1% radius
                }

    I’ve drag-knifed maybe a dozen top decks with no problem, so figuring out what broke took a while.

    The key turned out to be in the Terminal log, where all coordinates in the G-Code commands had, at most, two decimal places. The GCMC program producing the G-Code emits three decimal places, so bCNC rounded off a digit before squirting commands to GRBL.

    After more searching, it seems I’d told bCNC to do exactly that:

    bCNC Config - Round 2 digits - highlighted
    bCNC Config – Round 2 digits – highlighted

    Perhaps I’d mistakenly set “Decimal digits” instead of “DRO Zero padding” when I reduced the DRO resolution from three decimals to two? It’s set to “2” in the CNC 3018XL configuration, so this seems like a typical one-off brain fade.

    GRBL doesn’t execute invalid commands, so the tool position remains at the end of the window’s outer perimeter while the next two arc commands fail, because their center offsets produced completely invalid radii.

    The three failed arc commands should have cut the right end of the window, the inner side, and the left end, but left the tool position unchanged. The final arc command should have withdrawn the blade along the outer side of the window, but became a complete circle, with the commanded end point equal to the leftover starting point at the same radius from the deck center.

    The same G-Code file fails consistently with Decimal digits = 2 and runs perfectly with Decimal digits = 3, so at least I know a good fix.

    Protip: Keep your hands away from moving machinery, because you never know what might happen!

    This seems sufficiently obscure to merit becoming a Digital Machinist column. More analysis is in order …

  • Natural Enemies

    Natural Enemies

    I couldn’t resist setting this up for my next Digital Machinist column on logarithmic scales:

    Homage Tektronix Circuit Computer with HP 50g calculator
    Homage Tektronix Circuit Computer with HP 50g calculator

    The caption will read “Photo 1: A replica Tektronix Circuit Computer shown with its natural enemy, an HP 50g Graphing Calculator.”

    It’s my desk calculator. In the Basement Laboratory, I use the HP 48 calculator app, with a couple of $10 Sharp calculators in harm’s way.

  • HON Lateral File: Shelf Rebuild

    HON Lateral File: Shelf Rebuild

    After sliding the HON Lateral File Cabinet shelf into place and installing the bumpers, it seemed rather loose and floppy. Comparing the situation with the other file cabinet showed it had a missing glide button in the rear and two missing slides at the front.

    A replacement button emerged from the end of a Delrin rod:

    HON Lateral File - shelf button - parting off
    HON Lateral File – shelf button – parting off

    The original buttons had an expanding stem, which is easy to do with an injection-molded part. I opted for simple adhesive, with enough of a blob underneath the shelf to (presumably) lock it in place forevermore:

    HON Lateral File - shelf button - installed
    HON Lateral File – shelf button – installed

    The slides required an iterative design technique (pronounced “fumbling around”), because nothing on either side remained square / plumb / true / unbent. I hacked the first version from scrap acrylic, broke off anything that didn’t fit, and got better measurements from what remained:

    HON Lateral File - shelf front guide - size test
    HON Lateral File – shelf front guide – size test

    With those measurements in hand, the second version used a pair of weird flat-head shoulder screws (probably from a hard drive) to anchor 3D printed angle brackets into the frame:

    HON Lateral File - shelf slides - version 2
    HON Lateral File – shelf slides – version 2

    Those worked reasonably well, but PETG doesn’t produce a nice sliding surface, so the final version has flat-head Delrin studs in slightly tweaked brackets:

    HON Lateral File - shelf slides - version 3
    HON Lateral File – shelf slides – version 3

    As with the buttons in the back, the original slides had expanding studs holding them in place, but glue works fine here, too:

    HON Lateral File - shelf slides - version 3 - installed
    HON Lateral File – shelf slides – version 3 – installed

    The button isn’t quite square to the surface and the slide isn’t quite flush with the bent metal in the frame, but it’s Good Enough™ for a shelf that won’t get lots of mileage.

    For reference, the brackets should print vertically to wrap the plastic threads around the upright for better strength:

    HON Lateral File Shelf Slide - Slic3r
    HON Lateral File Shelf Slide – Slic3r

    If you did it the obvious way, the upright side would break right off at the first insult from the hulking shelf, although they’re basically a solid chip of plastic, with a little infill inside the bottom slab.

    While I was at it, I pulled the springs to make them a bit longer, so they touch the back of the frame when the shelf is half an inch behind the front face of the drawers. A firm push and those Delrin contact points let the shelf pop out an inch or so, with plenty of room for fingers underneath the front edge.

    Some drawer slide stops near the back needed attention, too:

    HON Lateral File - slide stop bumper - bent
    HON Lateral File – slide stop bumper – bent

    I cannot imagine how hard somebody slammed the drawers, because bending the stops back to a right angle required a Vise-Grip and some muttering:

    HON Lateral File - slide stop bumper
    HON Lateral File – slide stop bumper

    Oddly, the cushiony hollow side faces away from the drawer, toward the back of the frame, because putting it forward holds the drawer front proud of the front frame face. Maybe HON cost-reduced the steel slides by making them just slightly shorter and using the same bumpers?

    The drawers have begun filling up from boxes scattered around the house:

    HON Lateral File - fabric stash
    HON Lateral File – fabric stash

    That’s the “orange” part of Mary’s collection, now with plenty of room to grow!

    The OpenSCAD source code as a GitHub Gist:

    // HON Lateral File Cabinet
    // Shelf slides
    // Ed Nisley KE4ZNU 2020-02-25
    //- Extrusion parameters must match reality!
    // Print with 3 shells and 3 solid layers
    ThreadThick = 0.25;
    ThreadWidth = 0.40;
    HoleWindage = 0.2;
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    Protrusion = 0.1; // make holes end cleanly
    inch = 25.4;
    ID = 0;
    OD = 1;
    LENGTH = 2;
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,h=Height,$fn=Sides);
    }
    //———————-
    // Dimensions
    SlideBlock = [18.0,25.0,12.0]; // across, along, height of left shelf bracket
    SlideWalls = [1.0,-SlideBlock.y/2,2.0]; // wall thicknesses, dummy Y
    HoleOffset = [8.4,7.0,0]; // hole center from left, front, dummy Z
    HoleOD = 4.0;
    Screw = [4.0,10,0.8]; // weird flat-head shoulder screw
    ScrewRecess = Screw.z + 2*ThreadThick; // depth to keep head below slide surface
    echo(str("Head base: ",SlideWalls.z – ScrewRecess));
    $fn = 12*4;
    //——————-
    // Single slide
    module Slide() {
    difference() {
    cube(SlideBlock,center=false);
    translate(SlideWalls)
    cube(SlideBlock * 2,center=false);
    translate(HoleOffset – [0,0,SlideBlock.z/2])
    rotate(180/8)
    PolyCyl(HoleOD,2*SlideBlock.z,8);
    translate(HoleOffset + [0,0,SlideWalls.z] – [0,0,ScrewRecess])
    rotate(180/12)
    PolyCyl(Screw[OD],3*Screw[LENGTH],12);
    }
    }
    //——————-
    // Build them
    Gap = 5.0/2;
    translate([0,-Gap,0])
    rotate([90,0,0])
    Slide();
    translate([0,Gap,0])
    rotate([-90,0,0])
    mirror([0,1,0])
    Slide();

  • Homage Tek CC: Subscripts & Superscripts

    The GCMC typeset() function converts UTF-8 text into a vector list, with Hershey vector fonts sufficing for most CNC projects. The fonts date back to the late 1960s and lack niceties such as superscripts, so the Homage Tektronix Circuit Computer scale legends have a simpler powers-of-ten notation:

    Tek CC - Pilot V5 - plain paper - red blue
    Tek CC – Pilot V5 – plain paper – red blue

    Techies understand upward-pointing carets, but … ick.

    After thinking it over, poking around in the GCMC source code, and sketching alternatives, I ruled out:

    • Adding superscript glyphs to the font tables
    • Writing a text parser with various formatting commands
    • Doing anything smart

    Because I don’t need very many superscripts, a trivial approach seemed feasible. Start by defining the size & position of the superscript characters:

    SuperScale = 0.75;                                       // superscript text size ratio
    SuperOffset = [0mm,0.75 * LegendTextSize.y];            //  ... baseline offset
    

    Half-size characters came out barely readable with 0.5 mm Pilot pens:

    Tek CC - Superscript test - 0.5x
    Tek CC – Superscript test – 0.5x

    They’re legible and might be OK with a diamond drag point.

    They work better at 3/4 scale:

    Tek CC - Superscript test - 0.75x
    Tek CC – Superscript test – 0.75x

    Because superscripts only occur at the end of the scale legends, a truly nasty hack suffices:

    function ArcLegendSuper(Text,Super,Radius,Angle,Orient) {
    
      local tp = scale(typeset(Text,TextFont),LegendTextSize);
    
      tp += scale(typeset(Super,TextFont),LegendTextSize * SuperScale) + SuperOffset + [tp[-1].x,0mm];
    
      local tpa = ArcText(tp,[0mm,0mm],Radius,Angle,TEXT_CENTERED,Orient);
    
      feedrate(TextSpeed);
      engrave(tpa,TravelZ,EngraveZ);
    }
    

    The SuperScale constant shrinks the superscript vectorlist, SuperOffset shifts it upward, and adding [tp[-1].x,0mm] glues it to the end of the normal-size vectorlist.

    Yup, that nasty.

    Creating the legends goes about like you’d expect:

      ArcLegendSuper("pF - picofarad  x10","-12",r,a,INWARD);
    

    Presenting “numeric” superscripts as text keeps the option open for putting non-numeric stuff up there, which seemed easier than guaranteeing YAGNI.

    A similar hack works for subscripts:

    Tek CC - Subscript test - 0.75x
    Tek CC – Subscript test – 0.75x

    With even more brutal code:

      Sub_C = scale(typeset("C",TextFont),LegendTextSize * SubScale) + SubOffset;
    
    <<< snippage >>>
    
        tp = scale(typeset("←----- τ",TextFont),LegendTextSize);
        tp += Sub_C + [tp[-1].x,0mm];
        tp += scale(typeset(" Scale -----→",TextFont),LegendTextSize) + [tp[-1].x,0mm];
    

    The hackage satisfied the Pareto Principle, so I’ll declare victory and move on.