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.

Tag: M2

Using and tweaking a Makergear M2 3D printer

  • Tour Easy Daytime Running Light: Fairing Mount

    The fairing mount must aim the flashlight generally parallel to the ground and slightly toed-in toward the bike’s frame, ideally holding the ball more-or-less in the center of its adjustment range. I eyeballed a protractor for the initial estimates and got it reasonably close on the third try:

    Tour Easy - J5 Tactical V2 - front
    Tour Easy – J5 Tactical V2 – front

    One more skilled in math than I could define a matrix transformation between the solid model’s XYZ coordinate space and the fairing’s XYZ space, then figure the reverse transformation allowing you to convert real-world angles back to the model’s space. I winged it by setting up adjustments to rotate the ball clamp ring on all three axes around its center:

    translate([-BracketHoleOC,0,0])
    PlateBlank();
    translate([Shift,0,ClampOD/2])
    rotate([-Roll,ToeIn,Tilt])
    intersection() {
    translate([0,0,-ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    BallClamp();
    }

    Lifting the ring upward by half its OD leaves it tangent to the XY plane, firmly embedded in the blank fairing clamp plate, and, through the magic of 3D printing, looking like it grew there.

    In practice, aligning the ring isn’t too difficult. Align an eyeball along each of the mount’s axes, center a protractor on the ball with it perpendicular to the line of sight, rotate it so the baseline is level / straight-ahead / crosswise, read off the angle, then type it in. Of course you’ll get the sign wrong at least once.

    For a given set of those angles, the mount looks like this:

    Fairing Flashlight Mount - Mount - rear view - no support - solid model
    Fairing Flashlight Mount – Mount – rear view – no support – solid model

    You can determine by inspection there’s no way to orient the shape for E-Z building, although putting the plate flat on the platform has a lot to recommend it.

    The outside being a spherical section, the overhangs will curl upward, so (as with the ball around the flashlight) rows of fins anchor the perimeter threads:

    Fairing Flashlight Mount - Mount - rear view - solid model
    Fairing Flashlight Mount – Mount – rear view – solid model

    The fins are just under two threads wide to eliminate any possible infill, with a simple sphere chopping their tops to fit just inside the clamp:

    if (MountSupport) { // anchor outer corners during worst overhang
    RibWidth = 1.9*ThreadWidth;
    SupportOC = 0.1 * ClampLength;
    difference() {
    rotate([0,0,Tilt])
    translate([Shift + 0.3,0,0])
    for (i=[-4.5,-2.5,0,2.0,4.5])
    translate([i*SupportOC – 0.0,0,(ClampThick + Plate[2])/2])
    cube([RibWidth,0.8*ClampOD,(ClampThick + Plate[2])],center=true);
    # translate([Shift,0,ClampOD/2])
    rotate([-Roll,ToeIn,Tilt])
    sphere(d=ClampOD – 2*ThreadWidth,$fn=NumSides);
    }
    }

    Slic3r built support structures under the overhanging screw bosses:

    Fairing Flashlight Mount - Mount - rear view - Slic3r
    Fairing Flashlight Mount – Mount – rear view – Slic3r

    It also added weird little towers that don’t come close to touching the clamp’s lower surfaces, which is why I added those fins. The automatic support should extend to one thread thickness from the bottom surface, but that’s a hard calculation to make for a spherical section represented by tesselating triangles.

    After a few test rides, the whole affair seems to be both holding together and holding the flashlight, so it’s good enough for now. A twilight ride around the block may be needed for better aiming, though.

  • Tour Easy Daytime Running Light: Ball Clamp Ring

    With the flashlight firmly clamped inside its ball, a surrounding clamp ring holds the ball on the mount:

    Tour Easy - J5 Tactical V2 - front
    Tour Easy – J5 Tactical V2 – front

    The solid model chops a sphere to a completely empirical 70% of the inner ball’s length (which, itself, may be truncated to fit the flashlight grip) and glues on a hull containing the M3x50 mm screws:

    //- Clamp around flashlight ball
    module BallClamp() {
    BossLength = ClampScrew[LENGTH] – ClampScrewNut[LENGTH] – 2*ClampScrewWasher[LENGTH] – 4*ThreadThick;
    difference() {
    union() {
    intersection() {
    sphere(d=ClampOD,$fn=NumSides); // exterior ball blamp
    cube([ClampLength,2*ClampOD,2*ClampOD],center=true); // aiming allowance
    }
    for (i=[0])
    hull() {
    for (j=[-1,1])
    translate([i*(ClampLength/2 – ClampScrew[OD]),j*ClampScrewOC/2,-BossLength/2])
    rotate(180/8)
    cylinder(d=(ClampScrewWasher[OD] + 2*ThreadWidth),h=BossLength,$fn=8);
    }
    }
    sphere(d=(BallOD + 1*ThreadThick),$fn=NumSides); // interior ball
    for (i=[0] , j=[-1,1]) {
    translate([i*(ClampLength/2 – ClampScrew[OD]),j*ClampScrewOC/2,-ClampOD]) // screw clearance
    rotate(180/8)
    PolyCyl(ClampScrew[ID],2*ClampOD,8);
    }
    }
    color("Yellow")
    if (Support) { // ad-hoc supports for top half
    NumRibs = 6;
    RibLength = 0.5 * BallOD;
    RibWidth = 1.9*ThreadWidth;
    SupportOC = ClampLength / NumRibs;
    cube([ClampLength,RibLength,4*ThreadThick],center=true); // base plate for adhesion
    intersection() {
    sphere(d=BallOD – 0*ThreadWidth); // cut at inner sphere OD
    cube([ClampLength + 2*ThreadWidth,RibLength,BallOD],center=true);
    union() { // ribs for E-Z build
    for (j=[-1,0,1])
    translate([0,j*SupportOC,0])
    cube([ClampLength,RibWidth,1.0*BallOD],center=true);
    for (i=[0:NumRibs]) // allow +1 to fill the far end
    translate([i*SupportOC – ClampLength/2,0,0])
    rotate([0,90,0])
    cylinder(d=BallOD – 2*ThreadThick,
    h=RibWidth,$fn=NumSides,center=true);
    }
    }
    }
    }

    The complete ring looks about like you’d expect, although it’s never built like this:

    Fairing Flashlight Mount - Clamp - show view - solid model
    Fairing Flashlight Mount – Clamp – show view – solid model

    The top half builds as an arch on the platform:

    Fairing Flashlight Mount - Clamp - build view - solid model
    Fairing Flashlight Mount – Clamp – build view – solid model

    The uppermost layers on the inside of the arch have terrible overhang pulled upward by the cooling plastic, so the builtin support structure hold the layers downward. The preview shows they don’t quite touch, but in actual practice the support bonds to the arch and requires a bit of effort to crack off:

    Fairing Flashlight Mount - support structures
    Fairing Flashlight Mount – support structures

    The ones on the right come from my (failed) attempts to build the ball hemispheres in the obvious orientation. It’s worth noting that my built-in “support” both bonds to the part and breaks off in one piece, quite unlike the pitched battle required to separate Slic3r’s automatic support structures; I think that’s the difference between the minimum feasible and maximum possible support.

    Anyhow, the inside of the arch requires only a bit of cleanup with a ball mill before it clamps firmly around the flashlight ball. In the normal orientation, the space over the missing ball cap snuggles into the cleaned-up part of the arch and there’s enough friction on the remaining ball to hold it in place. If it does joggle loose, a wrap of tape should provide enough griptivity.

    I started by assuming socket-head cap screws and brass inserts embedded in the clamp ring could provide enough force to hold everything together:

    Fairing Flashlight Mount - Clamp - screw inserts - solid model
    Fairing Flashlight Mount – Clamp – screw inserts – solid model

    The head recesses into the top opening and the insert sits just below the split line on the XY plane. That turned out to be asking a lot from a pair of 3 mm knurled brass inserts, even with JB Weld in full effect, and I wasn’t at all confident they wouldn’t pop out under duress and fling the flashlight away.

    Each screw now compresses the entire boss between a pair of washers and the nyloc nut won’t vibrate loose. The screws also serve to stiffen the clamp ring front-to-back, although I’m not convinced it needs any reinforcement.

    I also considered splitting the ring parallel to the front, right down the middle, with screws extending through both halves:

    Fairing Flashlight Mount - Clamp - Front Back split - solid model
    Fairing Flashlight Mount – Clamp – Front Back split – solid model

    It’d be trivially easy to build the front half face-down on the platform, but the rear would have only half the surface area bonded to the plate against the fairing, which seemed like a Bad Idea. Worse, I couldn’t figure out how to align the rear half on the plate with enough room for the nuts / inserts / whatever and alignment space around the front half.

  • Tour Easy Daytime Running Light: Flashlight Ball

    A flashlight used as a daytime running light must point generally forward and an actual bike headlight must light up the road, so it must sit on an az-el mount. My old bike helmet mirror mount had actual vertical and horizontal joints:

    Helmet mirror mount - El slide in place
    Helmet mirror mount – El slide in place

    Every doodle along those lines seemed too big, too fragile, too fiddly, or all at once.

    Living here in the future, though, we can produce (crude) ball joints to order:

    Flashlight Ball Mount
    Flashlight Ball Mount

    That’s an early version of the outer mount using threaded brass inserts.

    The ball around the flashlight separates along the obvious plane of symmetry, with a 2 mm socket-head cap screw and brass insert on each side. I tried printing the hemispheres convex-side-up with hand-hewn support structures inside:

    Flashlight Ball Mount - support structure - on platform
    Flashlight Ball Mount – support structure – on platform

    The huge overhanging sections parallel to the axis didn’t bond to the supports, curled upward, and began nudging the dangling Z-axis homing switch actuator. This wasn’t a completely wasted effort, though, as similar support structures came in handy for the outer clamp ring.

    Flipping the hemispheres over so they printed U-channel upward didn’t work much better, even sitting on a flat section to eliminate the absurd part of the overhang. This view shows one hemisphere with the missing cap:

    Fairing Flashlight Mount - Ball - solid model
    Fairing Flashlight Mount – Ball – solid model

    Flipped over, the flat surface bonded perfectly to the platform, but the overhang still warped as the upper layers cooled and pulled the perimeter upward:

    Flashlight Ball Mount - warped section
    Flashlight Ball Mount – warped section

    Because normal support structures don’t contact the outer surface, I added fins to the model to hold the perimeter (almost) flat until the outer walls became sufficiently vertical to stop warping:

    Fairing Flashlight Mount - Ball - build view - solid model
    Fairing Flashlight Mount – Ball – build view – solid model

    They’re fearsome hedgehogs in person:

    Flashlight Ball Mount - flattening fins
    Flashlight Ball Mount – flattening fins

    The grip diameter determines the sphere diameter, as the sphere must have enough meat next to the grip to hold the screws and inserts. Rather than have the diameter different for every flashlight, I set it to the maximum of 45 mm or the actual diameter, which means all the flashlights in my collection have a common ball size. The hemispheres on the right have flattened ends to accommodate flashlight grips shorter than the sphere’s final diameter, achieved with a pair of intersection() operations lopping off the protruding bits:

    //- Ball around flashlight
    // Must print two!
    module BodyBall() {
    difference() {
    intersection() {
    sphere(d=BallOD,$fn=2*NumSides); // basic ball
    cube([BallLength,2*BallOD,2*BallOD],center=true); // max of flashlight grip length
    }
    translate([-LightBodies[FlashIndex][F_GRIPOD],0,0])
    rotate([0,90,0]) rotate(180/NumSides)
    PolyCyl(LightBodies[FlashIndex][F_GRIPOD],2*BallOD,NumSides); // flashlight body
    for (j=[-1,1])
    translate([0,j*BallScrewOC/2,0]) // commmon screw offset
    translate([0,0,-BallOD])
    PolyCyl(BallInsert[ID],2*BallOD,6); // punch screw shaft through everything
    translate([0,BallScrewOC/2,-Protrusion])
    PolyCyl(BallInsert[OD],(BallInsert[LENGTH] + 3*ThreadThick + Protrusion),6); // threaded insert
    translate([0,-BallScrewOC/2,BallThick])
    PolyCyl(BallScrew[OD],BallOD,6); // screw head clearance
    translate([0,0,-BallOD/2]) // remove bottom half
    cube(BallOD,center=true);
    translate([0,0,BallOD – BallThick/2]) // slice off top = bottom for E-Z build
    cube(BallOD,center=true);
    }
    if (Support) {
    NumRibs = 24;
    RibHeight = (BallOD – LightBodies[FlashIndex][F_GRIPOD]/cos(180/NumSides) – BallThick) / 2;
    ChordC = 2*sqrt(BallThick*BallOD/2 – pow(BallThick/2,2));
    intersection() {
    cube([BallLength,2*BallOD,2*BallOD],center=true); // max of flashlight grip length
    translate([0,0,BallOD/2 – BallThick/2])
    for (i=[0:NumRibs – 1])
    rotate(i*360/NumRibs + 180/NumRibs) // avoid screw holes
    translate([ChordC/2 + BallOD/8,0,-RibHeight/2])
    cube([BallOD/4,2*ThreadWidth,RibHeight],center=true);
    }
    }
    }

    Because the fins extend from resolutely convex surfaces, I snipped them off with flush-cutting pliers, reamed out the holes, epoxied the inserts in place, assembled the ball, and introduced it to Mr Belt Sander.

    Protip: don’t hold the ball with your finger through the hole. It will eventually fly off under the workbench and it’s better if it doesn’t break your finger in the process.

    A somewhat rough outer surface turns out to be an advantage, not a liability, as the clamp ring around the ball must hold it against the normal (and unusually severe) vibrations found on a bike.

    The inner cylindrical section is smooth enough to require a wrap of tape around the flashlight grip to anchor it in position. The tape adheres to the flashlight and squishes into the ball’s layer lines, even under mild pressure from the 2 mm screws. The outer clamp ring applies compression to the ball, so the tiny screws need not withstand much force at all, which is a good thing.

  • Tour Easy Daytime Running Light: Fairing Clamp Plates

    For reasons obvious to any cyclist, we must improve the forward conspicuity of our Tour Easy recumbents with a white daytime running light; a near-miss boosted this to the front of the project queue. While you can outfit a standard bike with a handlebar-mounted headlight (*), at any price from the sublime to the ridiculous, the smooth snout of a fully faired recumbent covers all the usual attachment points.

    A small LED flashlight tacked onto the fairing support bracket seems workable enough to make up for a significant case of ugly:

    Tour Easy - J5 Tactical V2 - front
    Tour Easy – J5 Tactical V2 – front

    That’s a J5 Tactical V2 flashlight on my bike.

    Mary’s bike has a tidier Anker LC40 in an earlier mount version:

    Tour Easy - Anker LC40 - front
    Tour Easy – Anker LC40 – front

    The Anker required an adapter to hold an 18650 cell in its 3xAAA-size body. The J5 V2 is resolutely 18650-only, which is fine with me.

    The intent here is to find out whether this works, figure out the proper aiming point(s), then de-bulk the mount.

    The next few posts will cover various bits & pieces of the design, because I must remember why I did things the way they turned out: sometimes the obvious choices didn’t work.

    The Zzipper fairing originally mounted to the strut across the handlebars with a single 1/4-20 nylon screw on each side. Even with a nylon washer on the outside, the stress concentration cracked the polycarbonate sheet around the screws and brackets, so I designed & printed flat ABS plates to spread the stress over a larger area:

    Fairing mount - inside
    Fairing mount – inside

    The tapered edges were supposed to be flexible, but the foam sheets sandwiched on both sides of the fairing actually provided most of the compliance. There’s another screw in the open hole binding the inner & outer plates together.

    The mounts worked perfectly, even as they faded over the years. The fairings became quite scuffed during the course of our near-daily rides, but, heck, we’re also a bit scuffed and it’s still all good.

    The new PETG inner plates seat on the bracket to nearly its full thickness:

    Tour Easy - Zipper fairing plate - inside
    Tour Easy – Zipper fairing plate – inside

    The flashlight on the outer plate applies torque around the bolt which (I hope) the sides of the recess can resist. This is the absolutely key part of the design and, I’m somewhat ashamed to admit, took me far too long to figure out. What you don’t want: weird & fragile gimcrackery clamped onto the strut extending under the fairing’s edge, with the flashlight hanging far off to the side.

    I modeled the fairing strut’s aluminum bracket as a 2D rectangle, plus a pair of chords, embiggened by a thread around the outside edge, minus the hole, then extruded to the proper height:

    //- Fairing Bracket
    // Magic numbers taken from the actual fairing mount
    // Centered on screw hole
    /* [Hidden] */
    inch = 25.4;
    BracketHoleOD = 0.25 * inch; // 1/4-20 bolt holes
    BracketHoleOC = 1.0 * inch; // fairing hole spacing
    // usually 1 inch, but 15/16 on one fairing
    Bracket = [48.0,16.3,3.6 – 0.6]; // fairing bracket end plate overall size
    BracketHoleOffset = (3/8) * inch; // end to hole center
    BracketM = 3.0; // endcap arc height
    BracketR = (pow(BracketM,2) + pow(Bracket[1],2)/4) / (2*BracketM); // … radius
    module Bracket() {
    linear_extrude(height=Bracket[2],convexity=2)
    difference() {
    translate([(Bracket[0]/2 – BracketHoleOffset),0,0])
    offset(delta=ThreadWidth)
    intersection() {
    square([Bracket[0],Bracket[1]],center=true);
    union() {
    for (i=[-1,0,1]) // middle circle fills gap
    translate([i*(Bracket[0]/2 – BracketR),0])
    circle(r=BracketR);
    }
    }
    circle(d=BracketHoleOD/cos(180/8),$fn=8); // dead center at the origin
    }
    }

    The hole isn’t strictly necessary, as I punch out both screw holes as part of the plate assemblies.

    The overall plate shape comes from the top half of a hull() wrapped around four squashed spheres:

    //- General plate shape
    // Centered on the hole for the fairing bracket
    Plate = [100.0,30.0,6*ThreadThick + Bracket[2]];
    PlateRad = Plate[1]/4;
    echo(str("Base plate thick: ",Plate[2]));
    module PlateBlank() {
    difference() {
    translate([BracketHoleOC,0,0])
    intersection() {
    translate([0,0,Plate[2]/2]) // select upper half of spheres
    cube(Plate,center=true);
    hull()
    for (i=[-1,1], j=[-1,1])
    translate([i*(Plate[0]/2 – PlateRad),j*(Plate[1]/2 – PlateRad),0])
    resize([2*PlateRad,2*PlateRad,2*Plate[2]])
    sphere(r=PlateRad); // nice rounded corners!
    }
    translate([2*BracketHoleOC,0,-Protrusion]) // screw holes
    PolyCyl(BracketHoleOD,2*Plate[2],8);
    translate([0,0,-Protrusion])
    PolyCyl(BracketHoleOD,2*Plate[2],8);
    }
    }

    Then the inner plate is just a plate blank stamped with the bracket:

    //- Inner plate
    module InnerPlate() {
    difference() {
    PlateBlank();
    translate([0,0,Plate[2] – Bracket[2] + Protrusion]) // punch out fairing bracket
    Bracket();
    }
    }

    You’ll need a set for the side of the fairing without the running light:

    Fairing Flashlight Mount - Plates - solid model
    Fairing Flashlight Mount – Plates – solid model

    The outer plate looks reasonably sleek in real life, although that’s not the primary consideration:

    Tour Easy - Zipper fairing plate - outside
    Tour Easy – Zipper fairing plate – outside

    You could replace the squared-off ends with simple half-circles, maybe stretched into stylin’ ellipse shapes, without too much effort.

    I got out the screws, set up to cut them with a pull saw and miter box, then realized they are plastic. Put away the saw, got out the utility knife, and cut them to length with one firm push. No distorted threads, no dust, no muss, no fuss.

    (*) Opinion: any headlight with non-replaceable, USB-chargeable cells is a toy. I can replace a discharged (or failed) 18650 cell in the middle of a ride, where a dead battery inside a spendy headlight would leave me in the dark. Might not matter for a DRL, but seems absolutely critical on night rides. ‘Nuff said.

  • Layout Pen For Black Objects

    This worked surprisingly well to lay out black foam gaskets for new fairing mounting plates:

    Black foam layout with ceramic fabric pen
    Black foam layout with ceramic fabric pen

    Mary uses the Fons & Porter Mechanical Pencil to mark quilting patterns on fabric. It has, they say, a “strong ceramic 0.9MM white lead” with “water-soluble dyes” capable of both laying down a durable mark and washing out without leaving a trace. I don’t care about the latter, of course, but it did brush off reasonably well.

    The next step involved running an X-Acto knife around the perimeter of the plate and punching the holes.

    You can get colored ceramic leads (for small values of color) for use on other backgrounds.

  • Cylindrical Cell Adapter: 18650 to 3xAAA

    Anker LC40 flashlights can use either one lithium 18650 cell or an adapter holding three AAA cells. I now prefer 18650 cells, but they’re nigh onto 4 mm smaller than the flashlight ID and rattle around something awful.

    I can fix that:

    Anker LC40 with 18650 cell adapter
    Anker LC40 with 18650 cell adapter

    Three new entries appear in the cell dimension table of my OpenSCAD inter-series battery adapter program:

    NAME = 0;
    ID = 0;       // for non-cell cylinders
    OD = 1;
    LENGTH = 2;
    
    Cells = [
      ["AAAA",8.3,42.5],
      ["AAA",10.5,44.5],
      ["AA",14.5,50.5],
      ["C",26.2,50],
      ["D",34.2,61.5],
      ["A23",10.3,28.5],
      ["CR123A",17.0,34.5],
      ["18650",18.8,65.2],
      ["3xAAA",21.2,56.0],
      ["AnkerLC40",23.0,55.0]           // Flashlight tube loose-fit for 3xAAA adapter
    ];
    

    I took the opportunity of adding OpenSCAD Customizer comments, which means this now works:

    OpenSCAD Customizer - dropdown selections
    OpenSCAD Customizer – dropdown selections

    The model looks about the same as before, although with a few more sides just for pretty:

    AnkerLC40 vs. 18650 Sleeve - Slic3r
    AnkerLC40 vs. 18650 Sleeve – Slic3r

    That was easy …

  • Mailing Tube End Caps: Screw-in Version

    The mailing tube arrived with contents intact, although the USPS inlet scanning didn’t work and the tube pretty much teleported across several states without leaving any tracking data behind. The recipient suggested several modifications to the caps:

    Review of user experience of tube end:
    The ribs on the endcap are very good at holding the cap on, so much so that I had to use a prying implement to remove it, which cracked the flange.
    Would consider less depth on the cap, and possibly another layer on the flange.

    Some continuous process improvement (a.k.a OpenSCAD hackage) produced a swoopy threaded cap with thumb-and-finger grips:

    Mailing Tube Screw Cap - top - Slic3r
    Mailing Tube Screw Cap – top – Slic3r

    The finger grips are what’s left after stepping a sphere out of the cap while rotating it around the middle:

    Mailing Tube Cap - finger grip construction
    Mailing Tube Cap – finger grip construction

    That worked out surprisingly well, with the deep end providing enough of a vertical-ish surface to push against.

    The two hex holes fit a pin wrench, because the grips twist only one way: outward. The wrench eliminates the need for a flange, as you can now adjust the cap insertion before slathering packing tape over the ends. Man, I loves me some good late binding action!

    A three-start thread seemed like overkill, but was quick & easy. The “thread form” consists of square rods sunk into the cap perimeter, with one edge sticking out:

    Mailing Tube Cap - thread detail
    Mailing Tube Cap – thread detail

    They’re 1.05 times longer than the cap perimeter facets to make their ends overlap, although they’re not tapered like the ones in the broom handle dingus, because it didn’t (seem to) make any difference to the model’s manifoldhood.

    Not needing any endcaps right now, I built one for show-n-tell:

    Threaded mailing tube end cap - installed
    Threaded mailing tube end cap – installed

    The OpenSCAD source code as a GitHub Gist:

    // Mailing tube end cap
    // Ed Nisley KE4ZNU – June 2017
    Layout = "Build";
    Model = "Screw";
    //- Extrusion parameters – must match reality!
    ThreadThick = 0.25;
    ThreadWidth = 0.40;
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    Protrusion = 0.1;
    HoleWindage = 0.2;
    //- Screw sizes
    inch = 25.4;
    TubeID = 2 * inch;
    TubeWall = 0.1 * inch;
    CapInsert = 15.0;
    CapRim = 6*ThreadThick;
    CapWall = 3*ThreadWidth;
    NumFlanges = 3;
    FlangeHeight = 3*ThreadThick;
    FlangeWidth = ThreadWidth/2;
    FlangeSpace = CapInsert / (NumFlanges + 1);
    ThumbHoleOD = 20.0;
    ThumbHoleAngle = 100;
    ThumbHoleSteps = 10;
    SpannerPinOD = 5.0;
    HelixOD = 4*ThreadThick;
    HelixHeight = 0.75*CapInsert;
    HelixAngle = atan(HelixHeight/(PI*TubeID));
    HelixStarts = 3;
    OAHeight = CapInsert + CapRim;
    NumRibs = 3*4;
    NumSides = 3*NumRibs;
    //- Adjust hole diameter to make the size come out right
    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);
    }
    module ScrewCap() {
    union() {
    difference() {
    cylinder(d=TubeID,h=OAHeight,$fn=NumSides);
    for (a=[0,180])
    for (i=[0:ThumbHoleSteps-1])
    rotate(a + i*ThumbHoleAngle/ThumbHoleSteps)
    translate([TubeID/4,0,-i*ThumbHoleOD/(2*ThumbHoleSteps)])
    sphere(d=ThumbHoleOD);
    for (a=[0,180])
    rotate(a – 60)
    translate([0.75*TubeID/2,0,-Protrusion])
    rotate(0*180/6)
    PolyCyl(SpannerPinOD,0.75*CapInsert,6);
    }
    for (s=[0:HelixStarts-1])
    for (i=[0:NumSides-1])
    rotate(i*360/NumSides + 180/NumSides + s*360/HelixStarts)
    translate([TubeID/2 – 0.25*HelixOD,0,i*HelixHeight/NumSides + HelixOD])
    rotate([90 + HelixAngle,0,0])
    cylinder(d=HelixOD,h=1.05*PI*TubeID/NumSides,center=true,$fn=4);
    }
    }
    module PushCap() {
    difference() {
    cylinder(d=TubeID,h=OAHeight,$fn=NumSides);
    translate([0,0,CapWall])
    cylinder(d=TubeID – 2*CapWall,h=OAHeight,$fn=NumSides);
    }
    for (i=[1:NumFlanges])
    translate([0,0,i*FlangeSpace])
    difference() {
    cylinder(d=TubeID + 2*FlangeWidth,h=FlangeHeight,$fn=NumSides);
    translate([0,0,-Protrusion])
    cylinder(d=TubeID – 2*CapWall,h=FlangeHeight + 2*Protrusion,$fn=NumSides);
    }
    for (i=[0:NumRibs-1])
    rotate(i*360/NumRibs)
    translate([0,-ThreadWidth,CapWall + ThreadThick])
    cube([TubeID/2 – CapWall/2,2*ThreadWidth,CapInsert + CapRim – CapWall – ThreadThick],center=false);
    translate([0,0,CapInsert]) {
    difference() {
    cylinder(d=TubeID + 2*TubeWall,h=CapRim,$fn=NumSides);
    translate([0,0,-Protrusion])
    cylinder(d=TubeID – 3*2*CapWall,h=2*CapRim,$fn=NumSides);
    }
    }
    }
    //- Build things
    if (Model == "Push")
    if (Layout == "Show")
    PushCap();
    else if (Layout == "Build")
    translate([0,0,OAHeight])
    rotate([180,0,0])
    PushCap();
    if (Model == "Screw")
    if (Layout == "Show")
    ScrewCap();
    else if (Layout == "Build")
    translate([0,0,OAHeight])
    rotate([180,0,0])
    ScrewCap();