nut-data: add NutKnurlM3_5_46

nut-data: add NutKnurlM3_5_46

// THIS FILE HAS BEEN GENERATED
// DO NOT MODIFY DIRECTLY

include <units.scad>
include <thread-data.scad>

NutHoleDia = 0;
NutWidthMin = 1;
NutThickness = 2;
NutWidthMax = 3;
NutThread = 4;
NutFacets = 5;

NutHexM1_2 = [
    [NutHoleDia, 1.2*mm],
    [NutWidthMin, 3*mm],
    [NutThickness, 1*mm],
    [NutWidthMax, 3.28*mm],
    [NutThread, ThreadM1_2],
    [NutFacets, 6],
];

NutHexM1_4 = [
    [NutHoleDia, 1.4*mm],
    [NutWidthMin, 3*mm],
    [NutThickness, 1.2*mm],
    [NutWidthMax, 3.28*mm],
    [NutThread, ThreadM1_4],
    [NutFacets, 6],
];

NutHexM1_6 = [
    [NutHoleDia, 1.6*mm],
    [NutWidthMin, 3.2*mm],
    [NutThickness, 1.3*mm],
    [NutWidthMax, 3.48*mm],
    [NutThread, ThreadM1_6],
    [NutFacets, 6],
];

NutHexM1_8 = [
    [NutHoleDia, 1.8*mm],
    [NutWidthMin, 3.5*mm],
    [NutThickness, 1.4*mm],
    [NutWidthMax, 3.82*mm],
    [NutThread, ThreadM1_8],
    [NutFacets, 6],
];

NutHexM2 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 4*mm],
    [NutThickness, 1.6*mm],
    [NutWidthMax, 4.32*mm],
    [NutThread, ThreadM2],
    [NutFacets, 6],
];

NutHexM2_5 = [
    [NutHoleDia, 2.5*mm],
    [NutWidthMin, 5*mm],
    [NutThickness, 2*mm],
    [NutWidthMax, 5.45*mm],
    [NutThread, ThreadM2_5],
    [NutFacets, 6],
];

NutHexM3 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 5.5*mm],
    [NutThickness, 2.4*mm],
    [NutWidthMax, 6.01*mm],
    [NutThread, ThreadM3],
    [NutFacets, 6],
];

NutHexM3_5 = [
    [NutHoleDia, 3.5*mm],
    [NutWidthMin, 6*mm],
    [NutThickness, 2.8*mm],
    [NutWidthMax, 6.58*mm],
    [NutThread, ThreadM3_5],
    [NutFacets, 6],
];

NutHexM4 = [
    [NutHoleDia, 4*mm],
    [NutWidthMin, 7*mm],
    [NutThickness, 3.2*mm],
    [NutWidthMax, 7.66*mm],
    [NutThread, ThreadM4],
    [NutFacets, 6],
];

NutHexM5 = [
    [NutHoleDia, 5*mm],
    [NutWidthMin, 8*mm],
    [NutThickness, 4.7*mm],
    [NutWidthMax, 8.79*mm],
    [NutThread, ThreadM5],
    [NutFacets, 6],
];

NutHexM6 = [
    [NutHoleDia, 6*mm],
    [NutWidthMin, 10*mm],
    [NutThickness, 5.2*mm],
    [NutWidthMax, 11.05*mm],
    [NutThread, ThreadM6],
    [NutFacets, 6],
];

NutHexM7 = [
    [NutHoleDia, 7*mm],
    [NutWidthMin, 11*mm],
    [NutThickness, 5.5*mm],
    [NutWidthMax, 12.12*mm],
    [NutThread, ThreadM7],
    [NutFacets, 6],
];

NutHexM8 = [
    [NutHoleDia, 8*mm],
    [NutWidthMin, 13*mm],
    [NutThickness, 6.8*mm],
    [NutWidthMax, 14.38*mm],
    [NutThread, ThreadM8],
    [NutFacets, 6],
];

NutHexM10 = [
    [NutHoleDia, 10*mm],
    [NutWidthMin, 16*mm],
    [NutThickness, 8.4*mm],
    [NutWidthMax, 17.77*mm],
    [NutThread, ThreadM10],
    [NutFacets, 6],
];

NutHexM12 = [
    [NutHoleDia, 12*mm],
    [NutWidthMin, 18*mm],
    [NutThickness, 10.8*mm],
    [NutWidthMax, 20.03*mm],
    [NutThread, ThreadM12],
    [NutFacets, 6],
];

NutHexM14 = [
    [NutHoleDia, 14*mm],
    [NutWidthMin, 21*mm],
    [NutThickness, 12.8*mm],
    [NutWidthMax, 23.35*mm],
    [NutThread, ThreadM14],
    [NutFacets, 6],
];

NutHexM16 = [
    [NutHoleDia, 16*mm],
    [NutWidthMin, 24*mm],
    [NutThickness, 14.8*mm],
    [NutWidthMax, 26.75*mm],
    [NutThread, ThreadM16],
    [NutFacets, 6],
];

NutHexM18 = [
    [NutHoleDia, 18*mm],
    [NutWidthMin, 27*mm],
    [NutThickness, 15.8*mm],
    [NutWidthMax, 29.56*mm],
    [NutThread, ThreadM18],
    [NutFacets, 6],
];

NutHexM20 = [
    [NutHoleDia, 20*mm],
    [NutWidthMin, 30*mm],
    [NutThickness, 18*mm],
    [NutWidthMax, 32.95*mm],
    [NutThread, ThreadM20],
    [NutFacets, 6],
];

NutHexM22 = [
    [NutHoleDia, 22*mm],
    [NutWidthMin, 34*mm],
    [NutThickness, 19.4*mm],
    [NutWidthMax, 37.29*mm],
    [NutThread, ThreadM22],
    [NutFacets, 6],
];

NutHexM24 = [
    [NutHoleDia, 24*mm],
    [NutWidthMin, 36*mm],
    [NutThickness, 21.5*mm],
    [NutWidthMax, 39.55*mm],
    [NutThread, ThreadM24],
    [NutFacets, 6],
];

NutHexM27 = [
    [NutHoleDia, 27*mm],
    [NutWidthMin, 41*mm],
    [NutThickness, 23.8*mm],
    [NutWidthMax, 45.29*mm],
    [NutThread, ThreadM27],
    [NutFacets, 6],
];

NutHexM30 = [
    [NutHoleDia, 30*mm],
    [NutWidthMin, 46*mm],
    [NutThickness, 25.6*mm],
    [NutWidthMax, 50.85*mm],
    [NutThread, ThreadM30],
    [NutFacets, 6],
];

NutHexM33 = [
    [NutHoleDia, 33*mm],
    [NutWidthMin, 50*mm],
    [NutThickness, 28.7*mm],
    [NutWidthMax, 55.37*mm],
    [NutThread, ThreadM33],
    [NutFacets, 6],
];

NutHexM36 = [
    [NutHoleDia, 36*mm],
    [NutWidthMin, 55*mm],
    [NutThickness, 31*mm],
    [NutWidthMax, 60.79*mm],
    [NutThread, ThreadM36],
    [NutFacets, 6],
];

NutHexM39 = [
    [NutHoleDia, 39*mm],
    [NutWidthMin, 60*mm],
    [NutThickness, 33.4*mm],
    [NutWidthMax, 66.44*mm],
    [NutThread, ThreadM39],
    [NutFacets, 6],
];

NutHexM42 = [
    [NutHoleDia, 42*mm],
    [NutWidthMin, 65*mm],
    [NutThickness, 34*mm],
    [NutWidthMax, 71.3*mm],
    [NutThread, ThreadM42],
    [NutFacets, 6],
];

NutHexM45 = [
    [NutHoleDia, 45*mm],
    [NutWidthMin, 70*mm],
    [NutThickness, 36*mm],
    [NutWidthMax, 76.95*mm],
    [NutThread, ThreadM45],
    [NutFacets, 6],
];

NutHexM48 = [
    [NutHoleDia, 48*mm],
    [NutWidthMin, 75*mm],
    [NutThickness, 38*mm],
    [NutWidthMax, 82.6*mm],
    [NutThread, ThreadM48],
    [NutFacets, 6],
];

NutHexM52 = [
    [NutHoleDia, 52*mm],
    [NutWidthMin, 80*mm],
    [NutThickness, 42*mm],
    [NutWidthMax, 88.25*mm],
    [NutThread, ThreadM52],
    [NutFacets, 6],
];

NutHexM56 = [
    [NutHoleDia, 56*mm],
    [NutWidthMin, 85*mm],
    [NutThickness, 45*mm],
    [NutWidthMax, 93.56*mm],
    [NutThread, ThreadM56],
    [NutFacets, 6],
];

NutHexM60 = [
    [NutHoleDia, 60*mm],
    [NutWidthMin, 90*mm],
    [NutThickness, 48*mm],
    [NutWidthMax, 99.21*mm],
    [NutThread, ThreadM60],
    [NutFacets, 6],
];

NutHexM64 = [
    [NutHoleDia, 64*mm],
    [NutWidthMin, 95*mm],
    [NutThickness, 51*mm],
    [NutWidthMax, 104.86*mm],
    [NutThread, ThreadM64],
    [NutFacets, 6],
];

NutHexThinM2 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 4*mm],
    [NutThickness, 1.2*mm],
    [NutWidthMax, 4.32*mm],
    [NutThread, ThreadM2],
    [NutFacets, 6],
];

NutHexThinM2_5 = [
    [NutHoleDia, 2.5*mm],
    [NutWidthMin, 5*mm],
    [NutThickness, 1.6*mm],
    [NutWidthMax, 5.45*mm],
    [NutThread, ThreadM2_5],
    [NutFacets, 6],
];

NutHexThinM3 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 5.5*mm],
    [NutThickness, 1.8*mm],
    [NutWidthMax, 6.01*mm],
    [NutThread, ThreadM3],
    [NutFacets, 6],
];

NutHexThinM3_5 = [
    [NutHoleDia, 3.5*mm],
    [NutWidthMin, 6*mm],
    [NutThickness, 2*mm],
    [NutWidthMax, 6.58*mm],
    [NutThread, ThreadM3_5],
    [NutFacets, 6],
];

NutHexThinM4 = [
    [NutHoleDia, 4*mm],
    [NutWidthMin, 7*mm],
    [NutThickness, 2.2*mm],
    [NutWidthMax, 7.66*mm],
    [NutThread, ThreadM4],
    [NutFacets, 6],
];

NutHexThinM5 = [
    [NutHoleDia, 5*mm],
    [NutWidthMin, 8*mm],
    [NutThickness, 2.7*mm],
    [NutWidthMax, 8.79*mm],
    [NutThread, ThreadM5],
    [NutFacets, 6],
];

NutHexThinM6 = [
    [NutHoleDia, 6*mm],
    [NutWidthMin, 10*mm],
    [NutThickness, 3.2*mm],
    [NutWidthMax, 11.05*mm],
    [NutThread, ThreadM6],
    [NutFacets, 6],
];

NutHexThinM8 = [
    [NutHoleDia, 8*mm],
    [NutWidthMin, 13*mm],
    [NutThickness, 4*mm],
    [NutWidthMax, 14.38*mm],
    [NutThread, ThreadM8],
    [NutFacets, 6],
];

NutHexThinM10 = [
    [NutHoleDia, 10*mm],
    [NutWidthMin, 16*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 17.77*mm],
    [NutThread, ThreadM10],
    [NutFacets, 6],
];

NutHexThinM12 = [
    [NutHoleDia, 12*mm],
    [NutWidthMin, 18*mm],
    [NutThickness, 6*mm],
    [NutWidthMax, 20.03*mm],
    [NutThread, ThreadM12],
    [NutFacets, 6],
];

NutHexThinM14 = [
    [NutHoleDia, 14*mm],
    [NutWidthMin, 21*mm],
    [NutThickness, 7*mm],
    [NutWidthMax, 23.35*mm],
    [NutThread, ThreadM14],
    [NutFacets, 6],
];

NutHexThinM16 = [
    [NutHoleDia, 16*mm],
    [NutWidthMin, 24*mm],
    [NutThickness, 8*mm],
    [NutWidthMax, 26.75*mm],
    [NutThread, ThreadM16],
    [NutFacets, 6],
];

NutHexThinM18 = [
    [NutHoleDia, 18*mm],
    [NutWidthMin, 27*mm],
    [NutThickness, 9*mm],
    [NutWidthMax, 29.56*mm],
    [NutThread, ThreadM18],
    [NutFacets, 6],
];

NutHexThinM20 = [
    [NutHoleDia, 20*mm],
    [NutWidthMin, 30*mm],
    [NutThickness, 10*mm],
    [NutWidthMax, 32.95*mm],
    [NutThread, ThreadM20],
    [NutFacets, 6],
];

NutHexThinM22 = [
    [NutHoleDia, 22*mm],
    [NutWidthMin, 34*mm],
    [NutThickness, 11*mm],
    [NutWidthMax, 37.29*mm],
    [NutThread, ThreadM22],
    [NutFacets, 6],
];

NutHexThinM24 = [
    [NutHoleDia, 24*mm],
    [NutWidthMin, 36*mm],
    [NutThickness, 12*mm],
    [NutWidthMax, 39.55*mm],
    [NutThread, ThreadM24],
    [NutFacets, 6],
];

NutHexThinM27 = [
    [NutHoleDia, 27*mm],
    [NutWidthMin, 41*mm],
    [NutThickness, 13.5*mm],
    [NutWidthMax, 45.2*mm],
    [NutThread, ThreadM27],
    [NutFacets, 6],
];

NutHexThinM30 = [
    [NutHoleDia, 20*mm],
    [NutWidthMin, 46*mm],
    [NutThickness, 15*mm],
    [NutWidthMax, 50.85*mm],
    [NutThread, ThreadM30],
    [NutFacets, 6],
];

NutHexThinM33 = [
    [NutHoleDia, 33*mm],
    [NutWidthMin, 50*mm],
    [NutThickness, 16.5*mm],
    [NutWidthMax, 55.37*mm],
    [NutThread, ThreadM33],
    [NutFacets, 6],
];

NutHexThinM36 = [
    [NutHoleDia, 36*mm],
    [NutWidthMin, 55*mm],
    [NutThickness, 18*mm],
    [NutWidthMax, 60.79*mm],
    [NutThread, ThreadM36],
    [NutFacets, 6],
];

NutHexThinM39 = [
    [NutHoleDia, 39*mm],
    [NutWidthMin, 60*mm],
    [NutThickness, 19.5*mm],
    [NutWidthMax, 66.44*mm],
    [NutThread, ThreadM39],
    [NutFacets, 6],
];

NutHexThinM42 = [
    [NutHoleDia, 42*mm],
    [NutWidthMin, 65*mm],
    [NutThickness, 21*mm],
    [NutWidthMax, 71.3*mm],
    [NutThread, ThreadM42],
    [NutFacets, 6],
];

NutHexThinM45 = [
    [NutHoleDia, 45*mm],
    [NutWidthMin, 70*mm],
    [NutThickness, 22.5*mm],
    [NutWidthMax, 76.95*mm],
    [NutThread, ThreadM45],
    [NutFacets, 6],
];

NutHexThinM48 = [
    [NutHoleDia, 48*mm],
    [NutWidthMin, 75*mm],
    [NutThickness, 24*mm],
    [NutWidthMax, 82.6*mm],
    [NutThread, ThreadM48],
    [NutFacets, 6],
];

NutHexThinM52 = [
    [NutHoleDia, 42*mm],
    [NutWidthMin, 80*mm],
    [NutThickness, 26*mm],
    [NutWidthMax, 88.25*mm],
    [NutThread, ThreadM52],
    [NutFacets, 6],
];

NutHexThinM56 = [
    [NutHoleDia, 56*mm],
    [NutWidthMin, 85*mm],
    [NutThickness, 28*mm],
    [NutWidthMax, 93.56*mm],
    [NutThread, ThreadM56],
    [NutFacets, 6],
];

NutHexThinM60 = [
    [NutHoleDia, 60*mm],
    [NutWidthMin, 90*mm],
    [NutThickness, 30*mm],
    [NutWidthMax, 99.21*mm],
    [NutThread, ThreadM60],
    [NutFacets, 6],
];

NutHexThinM64 = [
    [NutHoleDia, 64*mm],
    [NutWidthMin, 95*mm],
    [NutThickness, 32*mm],
    [NutWidthMax, 104.86*mm],
    [NutThread, ThreadM64],
    [NutFacets, 6],
];

NutKnurlM2_4_42 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 3.25*mm],
    [NutThickness, 4*mm],
    [NutWidthMax, 3.25*mm],
    [NutThread, ThreadM2],
    [NutFacets, 20],
];

NutKnurlM2_6_42 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 3.25*mm],
    [NutThickness, 6*mm],
    [NutWidthMax, 3.25*mm],
    [NutThread, ThreadM2],
    [NutFacets, 20],
];

NutKnurlM3_8_42 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.1*mm],
    [NutThickness, 8*mm],
    [NutWidthMax, 4.1*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

NutKnurlM3_5_42 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.1*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 4.1*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

NutKnurlM3_3_42 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.1*mm],
    [NutThickness, 3*mm],
    [NutWidthMax, 4.1*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

NutKnurlM5_5_42 = [
    [NutHoleDia, 5*mm],
    [NutWidthMin, 6.7*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 7.25*mm],
    [NutThread, ThreadM5],
    [NutFacets, 20],
];

NutKnurlM3_5_46 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.5*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 4.5*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

AllNut = [NutHexM1_2,
NutHexM1_4,
NutHexM1_6,
NutHexM1_8,
NutHexM2,
NutHexM2_5,
NutHexM3,
NutHexM3_5,
NutHexM4,
NutHexM5,
NutHexM6,
NutHexM7,
NutHexM8,
NutHexM10,
NutHexM12,
NutHexM14,
NutHexM16,
NutHexM18,
NutHexM20,
NutHexM22,
NutHexM24,
NutHexM27,
NutHexM30,
NutHexM33,
NutHexM36,
NutHexM39,
NutHexM42,
NutHexM45,
NutHexM48,
NutHexM52,
NutHexM56,
NutHexM60,
NutHexM64,
NutHexThinM2,
NutHexThinM2_5,
NutHexThinM3,
NutHexThinM3_5,
NutHexThinM4,
NutHexThinM5,
NutHexThinM6,
NutHexThinM8,
NutHexThinM10,
NutHexThinM12,
NutHexThinM14,
NutHexThinM16,
NutHexThinM18,
NutHexThinM20,
NutHexThinM22,
NutHexThinM24,
NutHexThinM27,
NutHexThinM30,
NutHexThinM33,
NutHexThinM36,
NutHexThinM39,
NutHexThinM42,
NutHexThinM45,
NutHexThinM48,
NutHexThinM52,
NutHexThinM56,
NutHexThinM60,
NutHexThinM64,
NutKnurlM2_4_42,
NutKnurlM2_6_42,
NutKnurlM3_5_42,
NutKnurlM3_3_42,
NutKnurlM5_5_42,
];

// THIS FILE HAS BEEN GENERATED
// DO NOT MODIFY DIRECTLY

include <units.scad>
include <thread-data.scad>

NutHoleDia = 0;
NutWidthMin = 1;
NutThickness = 2;
NutWidthMax = 3;
NutThread = 4;
NutFacets = 5;

NutHexM1_2 = [
    [NutHoleDia, 1.2*mm],
    [NutWidthMin, 3*mm],
    [NutThickness, 1*mm],
    [NutWidthMax, 3.28*mm],
    [NutThread, ThreadM1_2],
    [NutFacets, 6],
];

NutHexM1_4 = [
    [NutHoleDia, 1.4*mm],
    [NutWidthMin, 3*mm],
    [NutThickness, 1.2*mm],
    [NutWidthMax, 3.28*mm],
    [NutThread, ThreadM1_4],
    [NutFacets, 6],
];

NutHexM1_6 = [
    [NutHoleDia, 1.6*mm],
    [NutWidthMin, 3.2*mm],
    [NutThickness, 1.3*mm],
    [NutWidthMax, 3.48*mm],
    [NutThread, ThreadM1_6],
    [NutFacets, 6],
];

NutHexM1_8 = [
    [NutHoleDia, 1.8*mm],
    [NutWidthMin, 3.5*mm],
    [NutThickness, 1.4*mm],
    [NutWidthMax, 3.82*mm],
    [NutThread, ThreadM1_8],
    [NutFacets, 6],
];

NutHexM2 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 4*mm],
    [NutThickness, 1.6*mm],
    [NutWidthMax, 4.32*mm],
    [NutThread, ThreadM2],
    [NutFacets, 6],
];

NutHexM2_5 = [
    [NutHoleDia, 2.5*mm],
    [NutWidthMin, 5*mm],
    [NutThickness, 2*mm],
    [NutWidthMax, 5.45*mm],
    [NutThread, ThreadM2_5],
    [NutFacets, 6],
];

NutHexM3 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 5.5*mm],
    [NutThickness, 2.4*mm],
    [NutWidthMax, 6.01*mm],
    [NutThread, ThreadM3],
    [NutFacets, 6],
];

NutHexM3_5 = [
    [NutHoleDia, 3.5*mm],
    [NutWidthMin, 6*mm],
    [NutThickness, 2.8*mm],
    [NutWidthMax, 6.58*mm],
    [NutThread, ThreadM3_5],
    [NutFacets, 6],
];

NutHexM4 = [
    [NutHoleDia, 4*mm],
    [NutWidthMin, 7*mm],
    [NutThickness, 3.2*mm],
    [NutWidthMax, 7.66*mm],
    [NutThread, ThreadM4],
    [NutFacets, 6],
];

NutHexM5 = [
    [NutHoleDia, 5*mm],
    [NutWidthMin, 8*mm],
    [NutThickness, 4.7*mm],
    [NutWidthMax, 8.79*mm],
    [NutThread, ThreadM5],
    [NutFacets, 6],
];

NutHexM6 = [
    [NutHoleDia, 6*mm],
    [NutWidthMin, 10*mm],
    [NutThickness, 5.2*mm],
    [NutWidthMax, 11.05*mm],
    [NutThread, ThreadM6],
    [NutFacets, 6],
];

NutHexM7 = [
    [NutHoleDia, 7*mm],
    [NutWidthMin, 11*mm],
    [NutThickness, 5.5*mm],
    [NutWidthMax, 12.12*mm],
    [NutThread, ThreadM7],
    [NutFacets, 6],
];

NutHexM8 = [
    [NutHoleDia, 8*mm],
    [NutWidthMin, 13*mm],
    [NutThickness, 6.8*mm],
    [NutWidthMax, 14.38*mm],
    [NutThread, ThreadM8],
    [NutFacets, 6],
];

NutHexM10 = [
    [NutHoleDia, 10*mm],
    [NutWidthMin, 16*mm],
    [NutThickness, 8.4*mm],
    [NutWidthMax, 17.77*mm],
    [NutThread, ThreadM10],
    [NutFacets, 6],
];

NutHexM12 = [
    [NutHoleDia, 12*mm],
    [NutWidthMin, 18*mm],
    [NutThickness, 10.8*mm],
    [NutWidthMax, 20.03*mm],
    [NutThread, ThreadM12],
    [NutFacets, 6],
];

NutHexM14 = [
    [NutHoleDia, 14*mm],
    [NutWidthMin, 21*mm],
    [NutThickness, 12.8*mm],
    [NutWidthMax, 23.35*mm],
    [NutThread, ThreadM14],
    [NutFacets, 6],
];

NutHexM16 = [
    [NutHoleDia, 16*mm],
    [NutWidthMin, 24*mm],
    [NutThickness, 14.8*mm],
    [NutWidthMax, 26.75*mm],
    [NutThread, ThreadM16],
    [NutFacets, 6],
];

NutHexM18 = [
    [NutHoleDia, 18*mm],
    [NutWidthMin, 27*mm],
    [NutThickness, 15.8*mm],
    [NutWidthMax, 29.56*mm],
    [NutThread, ThreadM18],
    [NutFacets, 6],
];

NutHexM20 = [
    [NutHoleDia, 20*mm],
    [NutWidthMin, 30*mm],
    [NutThickness, 18*mm],
    [NutWidthMax, 32.95*mm],
    [NutThread, ThreadM20],
    [NutFacets, 6],
];

NutHexM22 = [
    [NutHoleDia, 22*mm],
    [NutWidthMin, 34*mm],
    [NutThickness, 19.4*mm],
    [NutWidthMax, 37.29*mm],
    [NutThread, ThreadM22],
    [NutFacets, 6],
];

NutHexM24 = [
    [NutHoleDia, 24*mm],
    [NutWidthMin, 36*mm],
    [NutThickness, 21.5*mm],
    [NutWidthMax, 39.55*mm],
    [NutThread, ThreadM24],
    [NutFacets, 6],
];

NutHexM27 = [
    [NutHoleDia, 27*mm],
    [NutWidthMin, 41*mm],
    [NutThickness, 23.8*mm],
    [NutWidthMax, 45.29*mm],
    [NutThread, ThreadM27],
    [NutFacets, 6],
];

NutHexM30 = [
    [NutHoleDia, 30*mm],
    [NutWidthMin, 46*mm],
    [NutThickness, 25.6*mm],
    [NutWidthMax, 50.85*mm],
    [NutThread, ThreadM30],
    [NutFacets, 6],
];

NutHexM33 = [
    [NutHoleDia, 33*mm],
    [NutWidthMin, 50*mm],
    [NutThickness, 28.7*mm],
    [NutWidthMax, 55.37*mm],
    [NutThread, ThreadM33],
    [NutFacets, 6],
];

NutHexM36 = [
    [NutHoleDia, 36*mm],
    [NutWidthMin, 55*mm],
    [NutThickness, 31*mm],
    [NutWidthMax, 60.79*mm],
    [NutThread, ThreadM36],
    [NutFacets, 6],
];

NutHexM39 = [
    [NutHoleDia, 39*mm],
    [NutWidthMin, 60*mm],
    [NutThickness, 33.4*mm],
    [NutWidthMax, 66.44*mm],
    [NutThread, ThreadM39],
    [NutFacets, 6],
];

NutHexM42 = [
    [NutHoleDia, 42*mm],
    [NutWidthMin, 65*mm],
    [NutThickness, 34*mm],
    [NutWidthMax, 71.3*mm],
    [NutThread, ThreadM42],
    [NutFacets, 6],
];

NutHexM45 = [
    [NutHoleDia, 45*mm],
    [NutWidthMin, 70*mm],
    [NutThickness, 36*mm],
    [NutWidthMax, 76.95*mm],
    [NutThread, ThreadM45],
    [NutFacets, 6],
];

NutHexM48 = [
    [NutHoleDia, 48*mm],
    [NutWidthMin, 75*mm],
    [NutThickness, 38*mm],
    [NutWidthMax, 82.6*mm],
    [NutThread, ThreadM48],
    [NutFacets, 6],
];

NutHexM52 = [
    [NutHoleDia, 52*mm],
    [NutWidthMin, 80*mm],
    [NutThickness, 42*mm],
    [NutWidthMax, 88.25*mm],
    [NutThread, ThreadM52],
    [NutFacets, 6],
];

NutHexM56 = [
    [NutHoleDia, 56*mm],
    [NutWidthMin, 85*mm],
    [NutThickness, 45*mm],
    [NutWidthMax, 93.56*mm],
    [NutThread, ThreadM56],
    [NutFacets, 6],
];

NutHexM60 = [
    [NutHoleDia, 60*mm],
    [NutWidthMin, 90*mm],
    [NutThickness, 48*mm],
    [NutWidthMax, 99.21*mm],
    [NutThread, ThreadM60],
    [NutFacets, 6],
];

NutHexM64 = [
    [NutHoleDia, 64*mm],
    [NutWidthMin, 95*mm],
    [NutThickness, 51*mm],
    [NutWidthMax, 104.86*mm],
    [NutThread, ThreadM64],
    [NutFacets, 6],
];

NutHexThinM2 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 4*mm],
    [NutThickness, 1.2*mm],
    [NutWidthMax, 4.32*mm],
    [NutThread, ThreadM2],
    [NutFacets, 6],
];

NutHexThinM2_5 = [
    [NutHoleDia, 2.5*mm],
    [NutWidthMin, 5*mm],
    [NutThickness, 1.6*mm],
    [NutWidthMax, 5.45*mm],
    [NutThread, ThreadM2_5],
    [NutFacets, 6],
];

NutHexThinM3 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 5.5*mm],
    [NutThickness, 1.8*mm],
    [NutWidthMax, 6.01*mm],
    [NutThread, ThreadM3],
    [NutFacets, 6],
];

NutHexThinM3_5 = [
    [NutHoleDia, 3.5*mm],
    [NutWidthMin, 6*mm],
    [NutThickness, 2*mm],
    [NutWidthMax, 6.58*mm],
    [NutThread, ThreadM3_5],
    [NutFacets, 6],
];

NutHexThinM4 = [
    [NutHoleDia, 4*mm],
    [NutWidthMin, 7*mm],
    [NutThickness, 2.2*mm],
    [NutWidthMax, 7.66*mm],
    [NutThread, ThreadM4],
    [NutFacets, 6],
];

NutHexThinM5 = [
    [NutHoleDia, 5*mm],
    [NutWidthMin, 8*mm],
    [NutThickness, 2.7*mm],
    [NutWidthMax, 8.79*mm],
    [NutThread, ThreadM5],
    [NutFacets, 6],
];

NutHexThinM6 = [
    [NutHoleDia, 6*mm],
    [NutWidthMin, 10*mm],
    [NutThickness, 3.2*mm],
    [NutWidthMax, 11.05*mm],
    [NutThread, ThreadM6],
    [NutFacets, 6],
];

NutHexThinM8 = [
    [NutHoleDia, 8*mm],
    [NutWidthMin, 13*mm],
    [NutThickness, 4*mm],
    [NutWidthMax, 14.38*mm],
    [NutThread, ThreadM8],
    [NutFacets, 6],
];

NutHexThinM10 = [
    [NutHoleDia, 10*mm],
    [NutWidthMin, 16*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 17.77*mm],
    [NutThread, ThreadM10],
    [NutFacets, 6],
];

NutHexThinM12 = [
    [NutHoleDia, 12*mm],
    [NutWidthMin, 18*mm],
    [NutThickness, 6*mm],
    [NutWidthMax, 20.03*mm],
    [NutThread, ThreadM12],
    [NutFacets, 6],
];

NutHexThinM14 = [
    [NutHoleDia, 14*mm],
    [NutWidthMin, 21*mm],
    [NutThickness, 7*mm],
    [NutWidthMax, 23.35*mm],
    [NutThread, ThreadM14],
    [NutFacets, 6],
];

NutHexThinM16 = [
    [NutHoleDia, 16*mm],
    [NutWidthMin, 24*mm],
    [NutThickness, 8*mm],
    [NutWidthMax, 26.75*mm],
    [NutThread, ThreadM16],
    [NutFacets, 6],
];

NutHexThinM18 = [
    [NutHoleDia, 18*mm],
    [NutWidthMin, 27*mm],
    [NutThickness, 9*mm],
    [NutWidthMax, 29.56*mm],
    [NutThread, ThreadM18],
    [NutFacets, 6],
];

NutHexThinM20 = [
    [NutHoleDia, 20*mm],
    [NutWidthMin, 30*mm],
    [NutThickness, 10*mm],
    [NutWidthMax, 32.95*mm],
    [NutThread, ThreadM20],
    [NutFacets, 6],
];

NutHexThinM22 = [
    [NutHoleDia, 22*mm],
    [NutWidthMin, 34*mm],
    [NutThickness, 11*mm],
    [NutWidthMax, 37.29*mm],
    [NutThread, ThreadM22],
    [NutFacets, 6],
];

NutHexThinM24 = [
    [NutHoleDia, 24*mm],
    [NutWidthMin, 36*mm],
    [NutThickness, 12*mm],
    [NutWidthMax, 39.55*mm],
    [NutThread, ThreadM24],
    [NutFacets, 6],
];

NutHexThinM27 = [
    [NutHoleDia, 27*mm],
    [NutWidthMin, 41*mm],
    [NutThickness, 13.5*mm],
    [NutWidthMax, 45.2*mm],
    [NutThread, ThreadM27],
    [NutFacets, 6],
];

NutHexThinM30 = [
    [NutHoleDia, 20*mm],
    [NutWidthMin, 46*mm],
    [NutThickness, 15*mm],
    [NutWidthMax, 50.85*mm],
    [NutThread, ThreadM30],
    [NutFacets, 6],
];

NutHexThinM33 = [
    [NutHoleDia, 33*mm],
    [NutWidthMin, 50*mm],
    [NutThickness, 16.5*mm],
    [NutWidthMax, 55.37*mm],
    [NutThread, ThreadM33],
    [NutFacets, 6],
];

NutHexThinM36 = [
    [NutHoleDia, 36*mm],
    [NutWidthMin, 55*mm],
    [NutThickness, 18*mm],
    [NutWidthMax, 60.79*mm],
    [NutThread, ThreadM36],
    [NutFacets, 6],
];

NutHexThinM39 = [
    [NutHoleDia, 39*mm],
    [NutWidthMin, 60*mm],
    [NutThickness, 19.5*mm],
    [NutWidthMax, 66.44*mm],
    [NutThread, ThreadM39],
    [NutFacets, 6],
];

NutHexThinM42 = [
    [NutHoleDia, 42*mm],
    [NutWidthMin, 65*mm],
    [NutThickness, 21*mm],
    [NutWidthMax, 71.3*mm],
    [NutThread, ThreadM42],
    [NutFacets, 6],
];

NutHexThinM45 = [
    [NutHoleDia, 45*mm],
    [NutWidthMin, 70*mm],
    [NutThickness, 22.5*mm],
    [NutWidthMax, 76.95*mm],
    [NutThread, ThreadM45],
    [NutFacets, 6],
];

NutHexThinM48 = [
    [NutHoleDia, 48*mm],
    [NutWidthMin, 75*mm],
    [NutThickness, 24*mm],
    [NutWidthMax, 82.6*mm],
    [NutThread, ThreadM48],
    [NutFacets, 6],
];

NutHexThinM52 = [
    [NutHoleDia, 42*mm],
    [NutWidthMin, 80*mm],
    [NutThickness, 26*mm],
    [NutWidthMax, 88.25*mm],
    [NutThread, ThreadM52],
    [NutFacets, 6],
];

NutHexThinM56 = [
    [NutHoleDia, 56*mm],
    [NutWidthMin, 85*mm],
    [NutThickness, 28*mm],
    [NutWidthMax, 93.56*mm],
    [NutThread, ThreadM56],
    [NutFacets, 6],
];

NutHexThinM60 = [
    [NutHoleDia, 60*mm],
    [NutWidthMin, 90*mm],
    [NutThickness, 30*mm],
    [NutWidthMax, 99.21*mm],
    [NutThread, ThreadM60],
    [NutFacets, 6],
];

NutHexThinM64 = [
    [NutHoleDia, 64*mm],
    [NutWidthMin, 95*mm],
    [NutThickness, 32*mm],
    [NutWidthMax, 104.86*mm],
    [NutThread, ThreadM64],
    [NutFacets, 6],
];

NutKnurlM2_4_42 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 3.25*mm],
    [NutThickness, 4*mm],
    [NutWidthMax, 3.25*mm],
    [NutThread, ThreadM2],
    [NutFacets, 20],
];

NutKnurlM2_6_42 = [
    [NutHoleDia, 2*mm],
    [NutWidthMin, 3.25*mm],
    [NutThickness, 6*mm],
    [NutWidthMax, 3.25*mm],
    [NutThread, ThreadM2],
    [NutFacets, 20],
];

NutKnurlM3_8_42 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.1*mm],
    [NutThickness, 8*mm],
    [NutWidthMax, 4.1*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

NutKnurlM3_5_42 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.1*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 4.1*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

NutKnurlM3_3_42 = [
    [NutHoleDia, 3*mm],
    [NutWidthMin, 4.1*mm],
    [NutThickness, 3*mm],
    [NutWidthMax, 4.1*mm],
    [NutThread, ThreadM3],
    [NutFacets, 20],
];

NutKnurlM5_5_42 = [
    [NutHoleDia, 5*mm],
    [NutWidthMin, 6.7*mm],
    [NutThickness, 5*mm],
    [NutWidthMax, 7.25*mm],
    [NutThread, ThreadM5],
    [NutFacets, 20],
];

AllNut = [NutHexM1_2,
NutHexM1_4,
NutHexM1_6,
NutHexM1_8,
NutHexM2,
NutHexM2_5,
NutHexM3,
NutHexM3_5,
NutHexM4,
NutHexM5,
NutHexM6,
NutHexM7,
NutHexM8,
NutHexM10,
NutHexM12,
NutHexM14,
NutHexM16,
NutHexM18,
NutHexM20,
NutHexM22,
NutHexM24,
NutHexM27,
NutHexM30,
NutHexM33,
NutHexM36,
NutHexM39,
NutHexM42,
NutHexM45,
NutHexM48,
NutHexM52,
NutHexM56,
NutHexM60,
NutHexM64,
NutHexThinM2,
NutHexThinM2_5,
NutHexThinM3,
NutHexThinM3_5,
NutHexThinM4,
NutHexThinM5,
NutHexThinM6,
NutHexThinM8,
NutHexThinM10,
NutHexThinM12,
NutHexThinM14,
NutHexThinM16,
NutHexThinM18,
NutHexThinM20,
NutHexThinM22,
NutHexThinM24,
NutHexThinM27,
NutHexThinM30,
NutHexThinM33,
NutHexThinM36,
NutHexThinM39,
NutHexThinM42,
NutHexThinM45,
NutHexThinM48,
NutHexThinM52,
NutHexThinM56,
NutHexThinM60,
NutHexThinM64,
NutKnurlM2_4_42,
NutKnurlM2_6_42,
NutKnurlM3_5_42,
NutKnurlM3_3_42,
NutKnurlM5_5_42,
];


guanin

guanin


fix: properly position the sample

fix: properly position the sample

/**
 * @license
 * MIT License
 *
 * Copyright (c) 2017 Jean-Sebastien CONAN
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * Part of the camelSCAD library.
 *
 * Takes a sample of the scene.
 *
 * @package operator
 * @author jsconan
 */

/**
 * Takes a sample of the scene and place it at the origin.
 * @param Number|Vector [size] - The size of sample.
 * @param Number|Vector [offset] - The position of the sample center. Will be the on the bottom face if center=false,
                                   and on the actual center if center=true.
 * @param Number [l] - The overall length.
 * @param Number [w] - The overall width.
 * @param Number [h] - The overall height.
 * @param Number [x] - The horizontal offset.
 * @param Number [y] - The depth offset.
 * @param Number [z] - The vertical offset.
 * @param Boolean [center] - Whether or not center the sample on all axis.
 */
module sample(size, offset, l, w, h, x, y, z, center) {
    size = apply3D(size, l, w, h);
    offset = apply3D(offset, x, y, z) / (center ? 2 : 1);

    translate(-offset) {
        intersection() {
            translate(offset) {
                cube(size, center=center);
            }
            children();
        }
    }
}

/**
 * @license
 * MIT License
 *
 * Copyright (c) 2017 Jean-Sebastien CONAN
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * Part of the camelSCAD library.
 *
 * Takes a sample of the scene.
 *
 * @package operator
 * @author jsconan
 */

/**
 * Takes a sample of the scene and place it at the origin.
 * @param Number|Vector [size] - The size of sample.
 * @param Number|Vector [offset] - The position of the sample center. Will be the on the bottom face if center=false,
                                   and on the actual center if center=true.
 * @param Number [l] - The overall length.
 * @param Number [w] - The overall width.
 * @param Number [h] - The overall height.
 * @param Number [x] - The horizontal offset.
 * @param Number [y] - The depth offset.
 * @param Number [z] - The vertical offset.
 * @param Boolean [center] - Whether or not center the sample on the vertical axis.
 */
module sample(size, offset, l, w, h, x, y, z, center) {
    size = apply3D(size, l, w, h);
    offset = apply3D(offset, x, y, z);

    translate(-offset) {
        intersection() {
            translate(offset) {
                box(size, center=center);
            }
            children();
        }
    }
}


fixed hole sizes and its locations

fixed hole sizes and its locations

span=172;
dia=18;
h=60+dia;
$fn=100;

module _handle_main()
{
  difference()
  {
    union()
    {
      // side blocks
      for(dx=[0, span])
        translate(dx*[1,0,0])
          cube([dia, h, dia/2]);
      // top holder
      translate([dia, h, 0])
        cube([span-dia, dia, dia/2]);
      // rounded edges
      for(dx=[0, span-dia])
        translate([dia+dx, h,0])
          cylinder(r=dia, h=dia/2);
    }
    for(dx=[0, span-3*dia])
      translate([2*dia+dx, h-dia, -1])
        cylinder(r=dia, h=dia/2+2);
  }
}

module _hole()
{
  hull()
    for(dx=[-0.5, 0.5])
      translate([dx, 0, -1])
        cylinder(r=(3.8+0.5)/2, h=dia/2+2, $fn=20);
}

module _handle()
{
  difference()
  {
    _handle_main();
    // left cut in
    translate([0, 0, -1])
      rotate(-45*[0, 0, 1])
        cube(dia*[1,2,1]+[0,0,2]);
    // right cut it
    translate([span+dia, 0, dia+1])
      rotate([0, 180, 45])
        cube(dia*[1,2,1]+[0,0,2]);
    // screw holes
    for(dx=[0, span])
      translate([dx+dia/2, dia-2, 0])
        _hole();
  }
}

_handle();
//_hole();

span=172;
dia=18;
h=60+dia;
$fn=100;

module _handle_main()
{
  difference()
  {
    union()
    {
      // side blocks
      for(dx=[0, span])
        translate(dx*[1,0,0])
          cube([dia, h, dia/2]);
      // top holder
      translate([dia, h, 0])
        cube([span-dia, dia, dia/2]);
      // rounded edges
      for(dx=[0, span-dia])
        translate([dia+dx, h,0])
          cylinder(r=dia, h=dia/2);
    }
    for(dx=[0, span-3*dia])
      translate([2*dia+dx, h-dia, -1])
        cylinder(r=dia, h=dia/2+2);
  }
}

module _hole()
{
  hull()
    for(dx=[-0.5, 0.5])
      translate([dx, 0, -1])
        cylinder(r=3.8+0.5/2, h=dia/2+2, $fn=20);
}

module _handle()
{
  difference()
  {
    _handle_main();
    // left cut in
    translate([0, 0, -1])
      rotate(-45*[0, 0, 1])
        cube(dia*[1,2,1]+[0,0,2]);
    // right cut it
    translate([span+dia, 0, dia+1])
      rotate([0, 180, 45])
        cube(dia*[1,2,1]+[0,0,2]);
    // screw holes
    for(dx=[0, span])
      translate([dx+dia/2, dia, 0])
        _hole();
  }
}

_handle();
//_hole();


Small fixes after test print and also added to comments and some cleanup

//
// Enclosure for the larger limit switch, specifically this one:
// "Cylewet V-154-1C25 Micro Limit Switch"
//
use <../common/extrusions.scad>

LARGE = 100;
EPSILON = 0.1;

module switch_cover() {
    base_thick = 1; // Thickness of "base" plate
    base_ro = 2; // Outer radii of base plate
    switch_thick = 8;

    // Switch dimensions
    switch_w = 28 + 0.2;
    switch_d = 16 + 0.2;
    switch_h = 10 + 0.5; // for sticky tape or wire

    // Nominal offset in y and x of the lower-left-corner
    // of the switch well.
    switch_off_d0 = 8;
    switch_off_w = 12;

    switch_r = 3; // inner radius of switch well
    top_gap_w = 18.5; // width of gap on the top, from LHS
    top_gap_d = 5; // depth (in y) of the top gap, from the top
    top_wall_thick = 3.5; // thickness (y) of top wall
    right_wall_thick = 3; // thickness (x) of right wall

    bottom_gap_w = 14; // width of bottom gap, from RHS
    bottom_gap_d = 11; // depth (in y) of bottom gap, from bottom

    // These are for screw holes
    hole_dist_x = 16; //Distance of screw holes in x == Tetrix spacing
    hole_dist_y = 8;  // Distance of scew holes in y == Lego spacing
    hole_wall_thick = 3; // Min thickness of walls around a hole
    hole_r = 2.05; // Just enough for 3/32 (imperial) screws to slip through easily

    // These are minimum distances to check against when computing
    // how much deep (in y) to start the well for the switch - so that there is
    // enough space around each hole in the y-direction
    bot_hole_check = 2*hole_wall_thick + 2*hole_r;
    top_of_top_hole = 2*hole_wall_thick + hole_r + hole_dist_y + hole_r;
    top_hole_check = top_of_top_hole - (switch_d  - top_gap_d);
    switch_off_d = max(switch_off_d0, bot_hole_check, top_hole_check);

    top_gap_end_x = switch_off_w + top_gap_w;
    bottom_gap_end_x = switch_off_w + bottom_gap_w;
    bottom_gap_end_y = switch_off_d + bottom_gap_d;
    base_d = switch_off_d + switch_d + top_wall_thick;
    tot_thick = base_thick + switch_thick;
    hole_x = hole_wall_thick + hole_r;
    hole_y = hole_wall_thick + hole_r;
    base_w = switch_off_w + switch_w + right_wall_thick; // thickness of base

    difference() {
        oblong(base_w, base_d, base_ro, tot_thick);
        translate([switch_off_w, switch_off_d, base_thick])
            oblong(switch_w, switch_d, switch_r, LARGE);
        translate([-EPSILON, switch_off_d + switch_d - top_gap_d, base_thick])
            cube([top_gap_end_x+EPSILON, LARGE, LARGE]);
        translate([bottom_gap_end_x, -EPSILON, base_thick])
            cube([LARGE, bottom_gap_end_y + 2*EPSILON, LARGE]);
        translate([hole_x, hole_y, -EPSILON])
            cylinder(r=hole_r, h=LARGE);
        translate([hole_x, hole_y + hole_dist_y, -EPSILON])
            cylinder(r=hole_r, h=LARGE);
        translate([hole_x  + hole_dist_x, hole_y, -EPSILON])
            cylinder(r=hole_r, h=LARGE);
    }
}

module trial1() {
    difference() {
        switch_cover();
        translate([-EPSILON, -EPSILON, -EPSILON]) cube([LARGE, 18, LARGE]);
        translate([-EPSILON, -EPSILON, 6]) cube([LARGE, LARGE, LARGE]);
    }
}

module trial2() {
    difference() {
        switch_cover();
        translate([-EPSILON, -EPSILON, -EPSILON]) cube([30, LARGE, LARGE]);
        translate([35, -EPSILON, -EPSILON]) cube([35, LARGE, LARGE]);
        translate([-EPSILON, -EPSILON, 6]) cube([LARGE, LARGE, LARGE]);
    }
}

$fn = 50;
//switch_cover();
translate([60, 0, 0]) trial1();
translate([80, 0, 0]) trial2();

//
// Enclosure for the larger limit switch, such as this one:
// "Cylewet V-154-1C25 Micro Limit Switch"
//
use <../common/extrusions.scad>
base_thick = 1;
switch_thick = 8;
LARGE = 100;
EPSILON = 0.1;

module switch_base() {
    base_w = 50;
    switch_w = 28 + 0.2;
    switch_d = 16 + 0.2;
    switch_h = 10 + 0.5; // for sticky tape or wire
    switch_off_d0 = 8;
    switch_off_w = 12;
    switch_r = 3;
    top_gap_w = switch_off_w + 18.5;
    top_gap_d = 5;
    top_wall_thick = 3.5;
    hole_dist_x = 16;
    hole_dist_y = 8;
    hole_wall_thick = 3;
    hole_r = 2; // enough for 3/32 (imperial) screws
    top_of_top_hole = 2*hole_wall_thick + hole_r + hole_dist_y + hole_r;
    bot_hole_check = 2*hole_wall_thick + 2*hole_r;
    top_hole_check = top_of_top_hole - (switch_d  - top_gap_d);
    //switch_off_d = max(switch_off_d0, bot_hole_check, top_hole_check);
    switch_off_d = max(switch_off_d0, bot_hole_check);

    bottom_gap_w = switch_off_w + 14;
    bottom_gap_d = switch_off_d + 11;
    base_d = switch_off_d + switch_d + top_wall_thick;
    tot_thick = base_thick + switch_thick;
    hole1_x = hole_wall_thick + hole_r;
    hole1_y = hole_wall_thick + hole_r;

    ro = 2;
    difference() {
        oblong(base_w, base_d, ro, tot_thick);
        translate([switch_off_w, switch_off_d, base_thick])
            oblong(switch_w, switch_d, switch_r, LARGE);
        translate([-EPSILON, switch_off_d + switch_d - top_gap_d, base_thick])
            cube([top_gap_w+EPSILON, LARGE, LARGE]);
        translate([bottom_gap_w, -EPSILON, base_thick])
            cube([LARGE, bottom_gap_d + 2*EPSILON, LARGE]);
        translate([hole1_x, hole1_y, -EPSILON])
            cylinder(r=hole_r, h=LARGE);
        translate([hole1_x, hole1_y + hole_dist_y, -EPSILON])
            cylinder(r=hole_r, h=LARGE);
        translate([hole1_x  + hole_dist_x, hole1_y, -EPSILON])
            cylinder(r=hole_r, h=LARGE);
    }
}

module trial() {
    difference() {
        switch_base();
        translate([25, -EPSILON, -EPSILON]) cube([LARGE, LARGE, LARGE]);
        translate([-EPSILON, -EPSILON, base_thick + 5]) cube([LARGE, LARGE, LARGE]);
    }
}

$fn = 50;
//switch_base();
trial();


Adding updates for switchover

Adding updates for switchover

// www.github.com/agupta231

// user set variables
initial_side_length = 100;
initial_side_height = 30;
padding_ratio = .07;

knob_ratio = .2;

max_iterations = 3;

top_opening_ratio = .3;
bottom_opening_ratio = .7;

echo(version());

module shelf(length, depth, height) {
    difference() {
        cube([length, depth, height], center = true);

        translate([0, 0, length * padding_ratio]) {
            cube([(1 - padding_ratio) * length, depth - length * padding_ratio, height], center = true);
        }
    }

    translate([0, (1 + knob_ratio / 2) * depth / 2 ,0])
    cube([length * knob_ratio, depth * knob_ratio / 2, height * knob_ratio], center = true);
}

module pattern(current_iteration, starting_pos, length, depth, height) {
    len_padding = length * padding_ratio;
    height_padding = height * padding_ratio;

    length_new = length / 2 - len_padding;
    height_new = (height - 3 * height_padding) / 2;

    echo(height);
    echo(height_new);

    if(current_iteration % 2 == 0) {
        echo(starting_pos + [0, depth / 2, 0]);

        translate(starting_pos + [0, (length_new * top_opening_ratio) / 2, (height_new + 3/2 * height_padding) / 2]) {
            shelf(length_new, length_new * top_opening_ratio, height_new);
        }

        translate(starting_pos + [0, (length_new * bottom_opening_ratio) / 2, -(height_new + 3/2 * height_padding) / 2]) {
            shelf(length_new, length_new * bottom_opening_ratio, height_new);
        }
    }
    else if(current_iteration % 2 == 1) {

    }
}

#shelf(initial_side_length, initial_side_length * bottom_opening_ratio, initial_side_height);

pattern(0, [0, 35, 0], initial_side_length, initial_side_length, initial_side_height);

// www.github.com/agupta231

// user set variables
initial_side_length = 100;
initial_side_height = 30;
padding_ratio = .05;

knob_ratio = .2;

max_iterations = 3;

top_opening_ratio = .3;
bottom_opening_ratio = .7;

echo(version());

module shelf(length, depth, height) {
    difference() {
        cube([length, depth, height], center = true);

        translate([0, 0, length * padding_ratio]) {
            cube([(1 - padding_ratio) * length, depth - length * padding_ratio, height], center = true);
        }
    }

    translate([0, (1 + knob_ratio / 2) * depth / 2 ,0])
    cube([length * knob_ratio, depth * knob_ratio / 2, height * knob_ratio], center = true);
}

module pattern(current_iteration, starting_pos, length, depth, height) {
    padding = length * padding_ratio;

    length_new = length / 2 - padding;
    height_new = (height - padding * 3) / 2;

    if(current_iteration % 2 == 0) {
        echo(starting_pos + [0, depth / 2, 0]);

        translate(starting_pos + [0, (length_new * top_opening_ratio) / 2, 0]) {
            shelf(length_new, length_new * top_opening_ratio, height_new);
        }
    }
    else if(current_iteration % 2 == 1) {

    }
}

#shelf(initial_side_length, initial_side_length * bottom_opening_ratio, initial_side_height);

pattern(0, [0, 35, 0], initial_side_length, initial_side_length, initial_side_height);


Updated enclosure demo for UseSTL

Updated enclosure demo for UseSTL

/*

	File: LogoBotInAnEnclosure.scad

	Example to show how to use the complete robot within a more complex model.
	This example models a basic tabletop enclosure, with the robot positioned inside.

	This kind of technique is useful for creating various visualisations of the design.

*/

// Master include statement, causes everything else for the model to be included
include <config/config.scad>

STLPath = "stl/";

EnclosureWidth 		= 500;
EnclosureDepth 		= 500;
EnclosureThickness 	= 1;
EnclosureWallHeight = 30;
EnclosureWallWidth 	= 10;

BotPosition 		= [50, 30];
BotRotation 		= 30;

// Enclosure / Pen
// ---------------

// Pen
//
module EnclosureBase() {

	// base
	color(White)
		translate([0,0, EnclosureThickness/2])
		cube([EnclosureWidth, EnclosureDepth, EnclosureThickness], center=true);

	// walls
	color(Grey50)
		translate([0,0, EnclosureThickness])
		linear_extrude(EnclosureWallHeight - EnclosureThickness)
		difference() {
			// outer-edge of wall
			square([EnclosureWidth, EnclosureDepth], center=true);

			// hollow out the inside
			square([EnclosureWidth - 2*EnclosureWallWidth, EnclosureDepth - 2*EnclosureWallWidth], center=true);
		}

}

// Draw the enclosure
EnclosureBase();

// Position LogoBot inside it
translate([ BotPosition[0], BotPosition[1], EnclosureThickness])
	rotate(BotRotation)
	LogoBotAssembly();

/*

	File: LogoBotInAnEnclosure.scad

	Example to show how to use the complete robot within a more complex model.
	This example models a basic tabletop enclosure, with the robot positioned inside.

	This kind of technique is useful for creating various visualisations of the design.

*/

// Master include statement, causes everything else for the model to be included
include <config/config.scad>

EnclosureWidth 		= 500;
EnclosureDepth 		= 500;
EnclosureThickness 	= 1;
EnclosureWallHeight = 30;
EnclosureWallWidth 	= 10;

BotPosition 		= [50, 30];
BotRotation 		= 30;

// Enclosure / Pen
// ---------------

// Pen
//
module EnclosureBase() {

	// base
	color(White)
		translate([0,0, EnclosureThickness/2])
		cube([EnclosureWidth, EnclosureDepth, EnclosureThickness], center=true);

	// walls
	color(Grey50)
		translate([0,0, EnclosureThickness])
		linear_extrude(EnclosureWallHeight - EnclosureThickness)
		difference() {
			// outer-edge of wall
			square([EnclosureWidth, EnclosureDepth], center=true);

			// hollow out the inside
			square([EnclosureWidth - 2*EnclosureWallWidth, EnclosureDepth - 2*EnclosureWallWidth], center=true);
		}

}

// Draw the enclosure
EnclosureBase();

// Position LogoBot inside it
translate([ BotPosition[0], BotPosition[1], EnclosureThickness])
	rotate(BotRotation)
	LogoBotAssembly();


minor bug fixes and details.

minor bug fixes and details.

// try to draw Jansen linkage leg assembly as it might appear in steel

// these are for configuration "E" as referenced in other drawings
AC=17.5;
Ay =  3.318; Bx = 53.833;
BD = 48.020; BE = 46.977; BH = 40.359;
CD = 59.635; CH = 71.441; DE = 66.437;
EF = 47.467; FG = 75.792;
FH = 40.843; GH = 55.790;

DEleft = (DE*DE + BD*BD - BE*BE)/(2*DE);
FGleft = (FG*FG + FH*FH - GH*GH)/(2*FG);
DEperp = sqrt(BD*BD - DEleft*DEleft);
FGperp = sqrt(FH*FH - FGleft*FGleft);

echo(str("DEleft=",DEleft,"   DEperp=",DEperp));
echo(str("FGleft=",FGleft,"   FGperp=",FGperp));

a=44;
legAssembly(a,0);
mirror([1,0,0]) legAssembly(180-a,1.2);
//legAssembly(100);

%translate([0,-93,0]) cube([200,2,2],center=true);

// -----------------------------------------------------------------

// plot a link shadow, a different way, to check kinematic correctness
module checkLink(xa,ya,xb,yb,ab) {
  *translate([(xa+xb)/2,(ya+yb)/2,-9])
    rotate([0,0,atan2(yb-ya,xb-xa)]) cube([ab,1,1],center=true);
}

function triK1(ax,ay,ca,bx,by,cb) = (cb*cb - ca*ca + ax*ax -bx*bx +ay*ay -by*by)/(2*(ax-bx));

// ===================================================================

module legAssembly(ang=0,linkOffset=0) {

// solve kinematics for given crank angle
xC = AC*cos(ang);
yC = AC*sin(ang)+Ay;
echo("C",xC,yC);

k1=(yC*yC - Bx*Bx + BD*BD - CD*CD + xC*xC)/(2*yC);
k2=(xC+Bx)/yC;
c=k1*k1-BD*BD+Bx*Bx;
b=2*(Bx-k1*k2);
a=k2*k2+1;
sgnD=(yC<0)?1:-1;
xD=(-b+sgnD*sqrt(b*b-4*a*c))/(2*a);
yD=sqrt(BD*BD - pow(xD+Bx,2));
echo("D",xD,yD,"CD err",sqrt(pow(xC-xD,2)+pow(yC-yD,2))-CD);

hipRot = atan2(yD,Bx+xD)-atan2(DEperp,DEleft);
echo("hipRot",hipRot);
xE = cos(hipRot) * (DEleft-DE) - sin(hipRot) * DEperp - Bx;
yE = sin(hipRot) * (DEleft-DE) + cos(hipRot) * DEperp;
/*
ke1=(yD*yD + xD*xD + DE*DE + BE*BE)/(2*yD);
ke2=(xD+Bx)/yD;
ae=2+ke2*ke2;
be=2*(Bx-ke1*ke2);
ce=ke1*ke1 - BE*BE +Bx*Bx;
echo("E abc:",ae,be,ce);
xE=(-be+sqrt(be*be-4*ae*ce))/(2*ae);
yE=sqrt(BE*BE - pow(xE+Bx,2));
*/
echo("E",xE,yE);

// this initial soln. seems wrong.
//xH=(BH*BH + xC*xC - CH*CH - Bx*Bx)/(2*(xC+Bx));
//yH=-sqrt(CH*CH - xC*xC + 2*xC*xH - xH*xH);
k1h=(xC*xC + yC*yC + BH*BH - CH*CH - Bx*Bx)/(2*yC);
k2h=-(xC+Bx)/yC;
ah=k2h*k2h+1;
bh=2*(k1h*k2h + Bx);
ch=k1h*k1h + Bx*Bx - BH*BH;
sgnH=(yC>0)?1:-1;
xH=(-bh+sgnH*sqrt(bh*bh-4*ah*ch))/(2*ah);
yH=-sqrt(BH*BH - pow(xH+Bx,2));
bhRot=atan2(yH,xH+Bx);
echo("H",xH,yH,"rot",bhRot,"CH err",sqrt(pow(xH-xC,2)+pow(yH-yC,2))-CH);

/*
k1f=(FH*FH - EF*EF - yE*yE - yH*yH + xE*xE - xH*xH) / (2*(yE-yH));
k2f=(xH-xE)/(yE-yH);
af=k2f*k2f+1;
bf=2*(k1f*k2f - xH - k2f*yH);
cf=xH*xH + yH*yH - 2*k1f*yH + k1f*k1f - FH*FH;
xF=(-bf-sqrt(bf*bf - 4*af*cf))/(2*af);
yF=k1f+k2f*xF;
*/
k2f = (yE-yH)/(xE-xH);
k1f = triK1(xE,yE,EF,xH,yH,FH);
af=k2f*k2f+1;
bf=2*(k2f*xE - k1f*k2f -yE);
cf=k1f*k1f - 2*k1f*xE + xE*xE + yE*yE - EF*EF;
yF=(-bf-sqrt(bf*bf - 4*af*cf))/(2*af);
xF=k1f-k2f*yF;
echo("F",xF,yF,"EF err",sqrt(pow(xF-xE,2)+pow(yF-yE,2))-EF);
echo("FH err",sqrt(pow(xF-xH,2)+pow(yF-yH,2))-FH);

//  -------------------------- crank-arm circle reference
%translate([0,Ay,0]) difference() {
  cylinder(r=AC,h=1,$fn=48,center=true);
  cylinder(r=2,h=2,center=true);
}

// draw the hip so that the main "plane", the ED centerline plane, is at z=0
translate([-Bx,0,0]) rotate([0,0,hipRot])
    translate([DEleft-DE,DEperp,0]) hip();
//translate([-Bx,0,2.5]) rotate([0,0,12.5]) translate([-DEleft,DEperp,0]) hip();
//translate([ Bx,0,0]) rotate([0,0,-20]) translate([DE-DEleft,DEperp,0]) mirror([1,0,0])
//  hip();
checkLink(-Bx,0,xD,yD,BD);
checkLink(-Bx,0,xE,yE,BE);
checkLink(xD,yD,xE,yE,DE);

translate([-Bx,0,0]) rotate([0,0,bhRot])
   BHlinks();
checkLink(-Bx,0,xH,yH,BH);

//translate([xC,yC,2]) rotate([0,0,142])
//   CDlink();
translate([0,0,linkOffset-.5]) CDlink(xC,yC,xD,yD);
checkLink(xC,yC,xD,yD,CD);

//%EFlink1(xE,yE,xF,yF);
translate([xF,yF,0]) rotate([0,0,atan2(yE-yF,xE-xF)]) EFlink();
checkLink(xE,yE,xF,yF,EF);

translate([0,0,linkOffset+1.8]) CDlink(xC,yC,xH,yH);
checkLink(xC,yC,xH,yH,CH);

footRot = atan2(yH-yF,xH-xF)-atan2(FGperp,FGleft);
translate([xF,yF,0]) rotate([0,0,footRot])
   foot();
checkLink(xF,yF,xH,yH,FH);

} // end module legAssembly()

// -----------------------------------------------------------------

module foot() difference() {
  union() {
    hull() {  // FG
      cube([4,2.6,2.6],center=true);
      translate([FG-1.3,0,0]) cylinder(r=1.3,h=2.6,$fn=24,center=true);
    }
    for (z=[-1,1]) hull() {
      translate([-5,2,1.5*z])scale([3,5,1])cylinder(r=1,h=.4,$fn=64,center=true);
      translate([ 8,0,1.5*z])cylinder(r=.3,h=.4,center=true);
    }
    translate([FGleft,FGperp-5,0]) cube([2.6,6,2.6],center=true);
    translate([FGleft,FGperp-5,4.8]) cube([2.6,6,2.6],center=true);
    translate([FGleft,FGperp-5,2.5]) cube([2.6,2.6,7],center=true);
    color([.3,.3,.4,.8]) {
      translate([FGleft,FGperp-.5, 0 ]) cube([3.5,5,2.2],center=true);
      translate([FGleft,FGperp-.5,4.8]) cube([3.5,5,2.2],center=true);
    }
    hull() {
      translate([6,0,0]) sphere(.8);
      translate([FGleft,FGperp-5,0]) sphere(.8);
    }
    hull() {
      translate([FG-6,0,0]) sphere(.8);
      translate([FGleft,FGperp-6,0]) sphere(.8);
    }
    hull() {
      translate([FGleft,FGperp-5,5]) sphere(.8);
      translate([FGleft,0,0]) sphere(.8);
    }
  }

  cylinder(r=.3,h=4,center=true);
  cube([4.4,3,2],center=true);
  translate([FGleft,FGperp,0]) cylinder(r=.7,h=33,center=true);
}
$fn=12;

module hip() {
  //color("Black") cube([3,3,2.5],center=true);
  difference() {
    translate([DE/2,0,0]) cube([DE+3,2.6,2.6],center=true);
    #cylinder(r=.5,h=6,center=true);
    cube([7,3,2],center=true);

    translate([DE,0,0]) {
      #cylinder(r=.25,h=8,center=true);
      cube([5,3,2],center=true);
    }
  }
  translate([DE-DEleft,-DEperp,-1.5]) cylinder(r=1.4,h=8,$fn=36);
  hull() {
    translate([DE-DEleft,-DEperp,0]) sphere(.8);
    translate([8,0,0]) sphere(.8);
  }
  hull() {
    translate([DE-DEleft,-DEperp,0]) sphere(.8);
    translate([DE-8,0,0]) sphere(.8);
  }
  translate([DE/2,-20,0]) rotate([0,90,0]) cylinder(r=.8,h=20,center=true);
  translate([DE-DEleft,-DEperp,4]) rotate([-105,0,0]) cylinder(r=.8,h=14);
}

module CDlink(cx=0,cy=0,dx=CD,dy=0) {
echo("CD",cx,cy,dx,dy);
  translate([dx,dy,0]) cylinder(r=1.4,h=.7,$fn=24,center=true);
  translate([cx,cy,0]) cylinder(r=1.4,h=.7,$fn=24,center=true);
  hull() {
    translate([dx,dy,0]) cylinder(r=.65,h=1.3,$fn=24,center=true);
    translate([cx,cy,0]) cylinder(r=.65,h=1.3,$fn=24,center=true);
  }
}

module EFlink() {
  difference() {
     union() {
       color([.3,.3,.4,.9]) {
         translate([   2,0,0]) cube([7,3,2],center=true);
         translate([EF-2,0,0]) cube([7,3,2],center=true);
       }
       translate([EF/2,0,0]) cube([EF-6,2.6,2.6],center=true);
     }

     translate([EF,0,0]) cylinder(r=.7,h=3,center=true);
                         cylinder(r=.7,h=3,center=true);
  }
}

module EFlink1(ex=0,ey=0,fx=EF,fy=0) {
echo("EF",ex,ey,fx,fy);
  difference() {
     union() {
       color([.3,.3,.4,.9]) {
         translate([ex,ey,0]) cube([4,3,2],center=true);
         translate([fx,fy,0]) cube([4,3,2],center=true);
       }
       hull() {
         translate([ex,ey,0]) cylinder(r=1.3,h=2.6,center=true);
         translate([fx,fy,0]) cylinder(r=1.3,h=2.6,center=true);
       }
     }

     translate([ex,ey,0]) cylinder(r=.7,h=3,center=true);
     translate([fx,fy,0]) cylinder(r=.7,h=3,center=true);
  }
}

// this link drawn with B axle at origin, always.
module BHlinks() {
  translate([0,0, 6.8])                 BHlink();
  translate([0,0,-2  ]) mirror([0,0,1]) BHlink();
}
module BHlink() {
  cylinder(r=1.4,h=6,$fn=24);

  //%translate([BH/2-1,0,1.3]) cube([BH-2,2.5,2.5],center=true);
  for (q=[-1,1]) hull() {
    translate([  0 ,1.5*q,1]) sphere(0.8);
    translate([BH-3,1  *q,1]) sphere(0.8);
  }
  hull() {
    translate([  0 ,0,5]) sphere(0.8);
    translate([BH-3,0,1]) sphere(0.8);
  }

  translate([BH,0,-.3]) difference() {
     hull() {
       cylinder(r=3,h=.33,$fn=36);
       translate([-8,0,0]) cylinder(r=1,h=.33);
     }
     cylinder(r=.7,h=2,center=true);
  }
}

// try to draw Jansen linkage leg assembly as it might appear in steel

// these are for configuration "E" as referenced in other drawings
AC=17.5;
Ay =  3.318; Bx = 53.833;
BD = 48.020; BE = 46.977; BH = 40.359;
CD = 59.635; CH = 71.441; DE = 66.437;
EF = 47.467; FG = 75.792;
FH = 40.843; GH = 55.790;

DEleft = (DE*DE + BD*BD - BE*BE)/(2*DE);
FGleft = (FG*FG + FH*FH - GH*GH)/(2*FG);
DEperp = sqrt(BD*BD - DEleft*DEleft);
FGperp = sqrt(FH*FH - FGleft*FGleft);

echo(str("DEleft=",DEleft,"   DEperp=",DEperp));
echo(str("FGleft=",FGleft,"   FGperp=",FGperp));

//a=0;
//legAssembly(a,0);
//mirror([1,0,0]) legAssembly(180-a,1.2);
legAssembly(0);

function triK1(ax,ay,ca,bx,by,cb) = (cb*cb - ca*ca + ax*ax -bx*bx +ay*ay -by*by)/(2*(ax-bx));

module legAssembly(ang=0,linkOffset=0) {

// solve kinematics for given crank angle
xC = AC*cos(ang);
yC = AC*sin(ang)+Ay;
echo("C",xC,yC);

k1=(yC*yC - Bx*Bx + BD*BD - CD*CD + xC*xC)/(2*yC);
k2=(xC+Bx)/yC;
c=k1*k1-BD*BD+Bx*Bx;
b=2*(Bx-k1*k2);
a=k2*k2+1;
sgnD=(yC<0)?1:-1;
xD=(-b+sgnD*sqrt(b*b-4*a*c))/(2*a);
yD=sqrt(BD*BD - pow(xD+Bx,2));
echo("D",xD,yD,"CD err",sqrt(pow(xC-xD,2)+pow(yC-yD,2))-CD);

hipRot = atan2(yD,Bx+xD)-atan2(DEperp,DEleft);
echo("hipRot",hipRot);
xE = cos(hipRot) * (DEleft-DE) - sin(hipRot) * DEperp - Bx;
yE = sin(hipRot) * (DEleft-DE) + cos(hipRot) * DEperp;
/*
ke1=(yD*yD + xD*xD + DE*DE + BE*BE)/(2*yD);
ke2=(xD+Bx)/yD;
ae=2+ke2*ke2;
be=2*(Bx-ke1*ke2);
ce=ke1*ke1 - BE*BE +Bx*Bx;
echo("E abc:",ae,be,ce);
xE=(-be+sqrt(be*be-4*ae*ce))/(2*ae);
yE=sqrt(BE*BE - pow(xE+Bx,2));
*/
echo("E",xE,yE);

// this initial soln. seems wrong.
//xH=(BH*BH + xC*xC - CH*CH - Bx*Bx)/(2*(xC+Bx));
//yH=-sqrt(CH*CH - xC*xC + 2*xC*xH - xH*xH);
k1h=(xC*xC + yC*yC + BH*BH - CH*CH - Bx*Bx)/(2*yC);
k2h=-(xC+Bx)/yC;
ah=k2h*k2h+1;
bh=2*(k1h*k2h + Bx);
ch=k1h*k1h + Bx*Bx - BH*BH;
sgnH=(yC>0)?1:-1;
xH=(-bh+sgnH*sqrt(bh*bh-4*ah*ch))/(2*ah);
yH=-sqrt(BH*BH - pow(xH+Bx,2));
bhRot=atan2(yH,xH+Bx);
echo("H",xH,yH,"rot",bhRot,"CH err",sqrt(pow(xH-xC,2)+pow(yH-yC,2))-CH);

/*
k1f=(FH*FH - EF*EF - yE*yE - yH*yH + xE*xE - xH*xH) / (2*(yE-yH));
k2f=(xH-xE)/(yE-yH);
af=k2f*k2f+1;
bf=2*(k1f*k2f - xH - k2f*yH);
cf=xH*xH + yH*yH - 2*k1f*yH + k1f*k1f - FH*FH;
xF=(-bf-sqrt(bf*bf - 4*af*cf))/(2*af);
yF=k1f+k2f*xF;
*/
k2f = (yE-yH)/(xE-xH);
k1f = triK1(xE,yE,EF,xH,yH,FH);
af=k2f*k2f+1;
bf=2*(k2f*xE - k1f*k2f -yE);
cf=k1f*k1f - 2*k1f*xE + xE*xE + yE*yE - EF*EF;
yF=(-bf-sqrt(bf*bf - 4*af*cf))/(2*af);
xF=k1f-k2f*yF;
echo("F",xF,yF,"EF err",sqrt(pow(xF-xE,2)+pow(yF-yE,2))-EF);
echo("FH err",sqrt(pow(xF-xH,2)+pow(yF-yH,2))-FH);

//  -------------------------- crank-arm circle reference
%translate([0,Ay,0]) difference() {
  cylinder(r=AC,h=1,$fn=48,center=true);
  cylinder(r=2,h=2,center=true);
}

// draw the hip so that the main "plane", the ED centerline plane, is at z=0
translate([-Bx,0,0]) rotate([0,0,hipRot])
    translate([DEleft-DE,DEperp,0]) hip();
//translate([-Bx,0,2.5]) rotate([0,0,12.5]) translate([-DEleft,DEperp,0]) hip();
//translate([ Bx,0,0]) rotate([0,0,-20]) translate([DE-DEleft,DEperp,0]) mirror([1,0,0])
//  hip();
checkLink(-Bx,0,xD,yD,BD);
checkLink(-Bx,0,xE,yE,BE);
checkLink(xD,yD,xE,yE,DE);

translate([-Bx,0,0]) rotate([0,0,bhRot])
   BHlinks();
checkLink(-Bx,0,xH,yH,BH);

//translate([xC,yC,2]) rotate([0,0,142])
//   CDlink();
translate([0,0,linkOffset-.5]) CDlink(xC,yC,xD,yD);
checkLink(xC,yC,xD,yD,CD);

EFlink(xE,yE,xF,yF);
//EFlink();
checkLink(xE,yE,xF,yF,EF);

translate([0,0,linkOffset+1.8]) CDlink(xC,yC,xH,yH);
checkLink(xC,yC,xH,yH,CH);

footRot = atan2(yH-yF,xH-xF)-atan2(FGperp,FGleft);
translate([xF,yF,0]) rotate([0,0,footRot])
   foot();
checkLink(xF,yF,xH,yH,FH);

} // end module legAssembly()

// plot a link shadow, a different way, to check kinematic correctness
module checkLink(xa,ya,xb,yb,ab) {
  %translate([(xa+xb)/2,(ya+yb)/2,-9])
    rotate([0,0,atan2(yb-ya,xb-xa)]) cube([ab,1,1],center=true);
}

module foot() difference() {
  union() {
    hull() {
      cube([4,2.6,2.6],center=true);
      translate([FG-1.3,0,0]) cylinder(r=1.3,h=2.6,$fn=24,center=true);
    }
    translate([FGleft,FGperp-5,0]) cube([2.6,6,2.6],center=true);
    translate([FGleft,FGperp-5,4.8]) cube([2.6,6,2.6],center=true);
    translate([FGleft,FGperp-5,2.5]) cube([2.6,2.6,7],center=true);
    color([.3,.3,.4,.8]) {
      translate([FGleft,FGperp-.5, 0 ]) cube([3.5,5,2.2],center=true);
      translate([FGleft,FGperp-.5,4.8]) cube([3.5,5,2.2],center=true);
    }
    hull() {
      translate([6,0,0]) sphere(.8);
      translate([FGleft,FGperp-5,0]) sphere(.8);
    }
    hull() {
      translate([FG-6,0,0]) sphere(.8);
      translate([FGleft,FGperp-6,0]) sphere(.8);
    }
    hull() {
      translate([FGleft,FGperp-5,5]) sphere(.8);
      translate([FGleft,0,0]) sphere(.8);
    }
  }

  cylinder(r=.3,h=4,center=true);
  cube([4.4,3,2],center=true);
  translate([FGleft,FGperp,0]) cylinder(r=.7,h=33,center=true);
}
$fn=12;

module hip() {
  //color("Black") cube([3,3,2.5],center=true);
  difference() {
    translate([DE/2,0,0]) cube([DE+4,2.6,2.6],center=true);
    #cylinder(r=.5,h=4,center=true);
    cube([5,3,2],center=true);

    translate([DE,0,0]) {
      #cylinder(r=.25,h=8,center=true);
      cube([5,3,2],center=true);
    }
  }
  translate([DE-DEleft,-DEperp,-1.5]) cylinder(r=1.4,h=8,$fn=36);
  hull() {
    translate([DE-DEleft,-DEperp,0]) sphere(.8);
    translate([8,0,0]) sphere(.8);
  }
  hull() {
    translate([DE-DEleft,-DEperp,0]) sphere(.8);
    translate([DE-8,0,0]) sphere(.8);
  }
  translate([DE/2,-20,0]) rotate([0,90,0]) cylinder(r=.8,h=20,center=true);
  translate([DE-DEleft,-DEperp,4]) rotate([-105,0,0]) cylinder(r=.8,h=14);
}

module CDlink(cx=0,cy=0,dx=CD,dy=0) {
echo("CD",cx,cy,dx,dy);
  translate([dx,dy,0]) cylinder(r=1.4,h=.7,$fn=24,center=true);
  translate([cx,cy,0]) cylinder(r=1.4,h=.7,$fn=24,center=true);
  hull() {
    translate([dx,dy,0]) cylinder(r=.7,h=.7,$fn=24,center=true);
    translate([cx,cy,0]) cylinder(r=.7,h=.7,$fn=24,center=true);
  }
  //%translate([CD/2,0,0]) cube([CD-2,1.4,1.4],center=true);
}

module EFlink(ex=0,ey=0,fx=EF,fy=0) {
echo("EF",ex,ey,fx,fy);
  difference() {
     union() {
       color([.3,.3,.4,1]) {
         translate([ex,ey,0]) cube([4,3,3],center=true);
         translate([fx,fy,0]) cube([4,3,3],center=true);
       }
       hull() {
         translate([ex,ey,0]) cylinder(r=1.3,h=2.6,center=true);
         translate([fx,fy,0]) cylinder(r=1.3,h=2.6,center=true);
       }
     }

     translate([ex,ey,0]) cylinder(r=.7,h=3,center=true);
     translate([fx,fy,0]) cylinder(r=.7,h=3,center=true);
  }
}

// this link drawn with B axle at origin, always.
module BHlinks() {
  translate([0,0, 6.8])                 BHlink();
  translate([0,0,-2  ]) mirror([0,0,1]) BHlink();
}
module BHlink() {
  cylinder(r=1.4,h=6,$fn=24);
  translate([BH/2-1,0,1.3]) cube([BH-2,2.5,2.5],center=true);
  translate([BH,0,-.3]) difference() {
     hull() {
       cylinder(r=3,h=.33,$fn=36);
       translate([-8,0,0]) cylinder(r=1,h=.33);
     }
     cylinder(r=.7,h=2,center=true);
  }
}


/ ‘Impression 3D/2016 - Trocar/trocar-test1.scad’


config: Increase ziptie thickness

config: Increase ziptie thickness

include <MCAD/stepper.scad>
include <thing_libutils/pulley.scad>
include <thing_libutils/bearing_data.scad>
include <thing_libutils/thread-data.scad>
include <thing_libutils/nut-data.scad>
include <thing_libutils/misc.scad>
include <thing_libutils/timing-belts-data.scad>

e=0.01*mm;

// high quality etc
is_build = false;

// minimum size of a fragment
// resolution of any round object (segment length)
// Because of this variable very small circles have a smaller number of fragments than specified using $fa.
// The default value is 2.
$fs = is_build ? 0.5 : 2;

// minimum angle for a fragment.
// The default value is 12 (i.e. 30 fragments for a full circle)
$fa = is_build ? 4 : 12;

$show_vit = is_build ? false : true;

// enable preview model (faster openscad)
$preview_mode = is_build ? false : true;

extrusion_height            = 0.4*mm;

// width of a single wall, should match your slicer settings
extrusion_width             = 0.4*mm;

// how many lines should a normal wall have (i.e. 0.6(extrusion_width)*6(normal_wall_factor)= 3.6mm wall width)
normal_wall_factor          = 3;

thick_wall_factor           = 4;

// diameter of your filament.
filament_d                  = 1.75*mm;
filament_r                  = filament_d/2;

main_width = 420*mm;
main_depth = 420*mm;
main_height = 400*mm;
main_upper_width = 500*mm;

extrusion_size = 20*mm;
extrusion_thread = ThreadM5;
extrusion_thread_dia = lookup(ThreadSize, extrusion_thread);
extrusion_nut = NutHexM5;
extrusion_nut_dia = lookup(NutWidthMax, extrusion_nut);

extrusion_mount_thread = ThreadM4;

// for tapped ends
extrusion_end_nut = NutHexM6;

main_lower_dist_z = 80*mm;
main_upper_dist_y = 160*mm;

gantry_connector_thickness = 5;

rod_fit_tolerance=1.01;

ziptie_type = [2.5*mm, 3*mm];
ziptie_thickness = ziptie_type[0];
ziptie_width = ziptie_type[1]+0.6*mm;
ziptie_bearing_distance = 3*mm;

xaxis_rod_distance = 65*mm;
xaxis_rod_d = 9.975*mm;
xaxis_rod_l = 500*mm;
// relative to entire machine
xaxis_rod_offset_x = 0*mm;
xaxis_bearings_top=2;
xaxis_bearings_bottom=1;
xaxis_bearing=bearing_bronze_10_16_12;
xaxis_bearing_bottom=bearing_bronze_10_16_18;
/*xaxis_bearing=bearing_igus_rj4jp_01_10;*/

xaxis_pulley = pulley_2GT_20T;
xaxis_pulley_inner_d = xaxis_pulley[2];
xaxis_pulley_outer_d = xaxis_pulley[3];
xaxis_idler_pulley = pulley_2GT_20T_idler;
xaxis_idler_pulley_inner_d = xaxis_idler_pulley[2];
xaxis_idler_pulley_outer_d = xaxis_idler_pulley[3];

xaxis_belt = TimingBelt_GT2_2;
xaxis_belt_width = 6*mm;
xaxis_beltpath_width = max(xaxis_belt_width+3*mm, xaxis_pulley[0]+2*mm);
xaxis_beltpath_z_offset_pulley = xaxis_pulley_inner_d/2;
/*xaxis_beltpath_z_offsets = [xaxis_beltpath_z_offset_pulley];*/
xaxis_beltpath_z_offsets = [-3*mm-xaxis_beltpath_z_offset_pulley, 3*mm+xaxis_beltpath_z_offset_pulley];
xaxis_beltpath_height_body = xaxis_pulley_outer_d/2+3*mm+v_sum(v_abs(xaxis_beltpath_z_offsets))+5*mm;
xaxis_beltpath_height_holders = max(xaxis_pulley_outer_d+2*mm, xaxis_pulley_inner_d+xaxis_beltpath_z_offsets[0]+3*mm);

xaxis_carriage_bearing_offset_y = ziptie_thickness+3*mm;
xaxis_carriage_beltpath_offset_y = xaxis_carriage_bearing_offset_y+xaxis_bearing[1]/2;

xaxis_motor = dict_replace(Nema17, NemaFrontAxleLength, 22*mm);
xaxis_motor_thread=ThreadM3;
xaxis_motor_nut=NutHexM3;

yaxis_rod_distance = 170*mm;
yaxis_rod_d = 11.975*mm;
yaxis_rod_l = 500*mm;
/*yaxis_bearing=bearing_igus_rj4jp_01_12;*/
yaxis_bearing=bearing_bronze_12_18_18;
yaxis_bearing_distance_y = 7*cm;

yaxis_motor = dict_replace(Nema17, NemaFrontAxleLength, 22*mm);

yaxis_pulley = pulley_2GT_20T;
yaxis_pulley_inner_d = yaxis_pulley[2];
ymotor_mount_thickness = 5;
ymotor_mount_thickness_h = 5;
yaxis_motor_offset_x = lookup(NemaSideSize,yaxis_motor)/2+ymotor_mount_thickness;
yaxis_motor_offset_z = -5*mm;
yaxis_belt_path_offset_x = -yaxis_pulley_inner_d/2;
yaxis_belt_path_offset_z = yaxis_motor_offset_z + 10*mm;

yaxis_idler_pulley = pulley_2GT_20T_idler;
yaxis_idler_pulley_inner_d = yaxis_idler_pulley[2];
yaxis_idler_pulley_outer_d = yaxis_idler_pulley[3];
yaxis_idler_pulley_h = yaxis_idler_pulley[0];
yaxis_idler_mount_thickness = 5;
yaxis_idler_pulley_tight_len = 20*mm;
yaxis_idler_pulley_offset_y = yaxis_idler_mount_thickness + yaxis_pulley_inner_d/2 + yaxis_idler_pulley_tight_len;
yaxis_idler_offset_x = lookup(NemaSideSize,yaxis_motor)/2+ymotor_mount_thickness;
yaxis_idler_offset_z = 10*mm;

yaxis_carriage_size = [220*mm,220*mm,5*mm];
printbed_size = [213*mm,213*mm,3*mm];

zaxis_rod_d = 11.975*mm;
zaxis_rod_l = 500*mm;
// relative to entire machine
zaxis_rod_offset = [0,-20*mm,0];
zaxis_bearing=bearing_bronze_12_18_18;

// Nema17 motor w/340mm long 8*mm leadscrew
zaxis_motor = dict_replace_multiple(Nema17,
        [
        [NemaAxleDiameter, 8*mm],
        [NemaFrontAxleLength, 340*mm],
        ]);

zmotor_w = lookup(NemaSideSize,zaxis_motor);
zmotor_h = lookup(NemaLengthLong,zaxis_motor);

// inner_d, outer_d, thread, outer_h, full_h, screw_dist, screw_thread
zaxis_nut = [20*mm, 36*mm, 8*mm, 5*mm, 23*mm, 13.5*mm, ThreadM3];

zaxis_motor_offset_z = 10*mm;
zmotor_mount_thickness = 5;
zmotor_mount_thickness_h = 10;
zmotor_mount_motor_offset=5;

zmotor_w = lookup(NemaSideSize,zaxis_motor);
zmotor_h = lookup(NemaLengthLong,zaxis_motor);
zmotor_mount_thread_dia = lookup(ThreadSize, extrusion_thread);
zmotor_mount_width = zmotor_w+zmotor_mount_thickness*2 + zmotor_mount_thread_dia*8;
zmotor_mount_h = main_lower_dist_z+extrusion_size+zaxis_motor_offset_z;

zmotor_mount_clamp_dist = zaxis_rod_d*2.5;
zmotor_mount_clamp_thread = extrusion_mount_thread;
zmotor_mount_clamp_nut = NutHexM4;
zmotor_mount_clamp_thread_dia = lookup(ThreadSize, zmotor_mount_clamp_thread);
zmotor_mount_clamp_nut_dia = lookup(NutWidthMin, zmotor_mount_clamp_nut);
zmotor_mount_clamp_nut_thick = lookup(NutThickness, zmotor_mount_clamp_nut);
zmotor_mount_clamp_width = zmotor_mount_clamp_dist+zmotor_mount_clamp_thread_dia*3;

xaxis_zaxis_distance_y_ = max(xaxis_rod_d/2 + zaxis_bearing[1]/2, zaxis_nut[1]/2 - xaxis_rod_d/2);
xaxis_zaxis_distance_y = xaxis_zaxis_distance_y_ + ziptie_type[0]+.5*mm + 1*mm;

zaxis_nut_mount_outer = zaxis_nut[1]/2 + zaxis_rod_d/2 + 1*mm;

// offset between Z motor screw and z rod
// place z rod as close as possible (depends on z nut and also motor etc)
zaxis_rod_screw_distance_x = max(zaxis_nut_mount_outer, zaxis_rod_d/2 + zmotor_w/2 + 1*mm);

// z rod offset from lower extrusion (outer)
zmotor_mount_rod_offset_x = zmotor_w/2+zaxis_rod_screw_distance_x+zmotor_mount_motor_offset;

// z screw offset from lower extrusion (outer)
zmotor_mount_screw_offset_x = zmotor_mount_rod_offset_x - zaxis_rod_screw_distance_x;

color_extrusion = "DimGray";
color_rods = "CornflowerBlue";
color_part = "DarkRed";
color_gantry_connectors = "OliveDrab";

include <MCAD/stepper.scad>
include <thing_libutils/pulley.scad>
include <thing_libutils/bearing_data.scad>
include <thing_libutils/thread-data.scad>
include <thing_libutils/nut-data.scad>
include <thing_libutils/misc.scad>
include <thing_libutils/timing-belts-data.scad>

e=0.01*mm;

// high quality etc
is_build = false;

// minimum size of a fragment
// resolution of any round object (segment length)
// Because of this variable very small circles have a smaller number of fragments than specified using $fa.
// The default value is 2.
$fs = is_build ? 0.5 : 2;

// minimum angle for a fragment.
// The default value is 12 (i.e. 30 fragments for a full circle)
$fa = is_build ? 4 : 12;

$show_vit = is_build ? false : true;

// enable preview model (faster openscad)
$preview_mode = is_build ? false : true;

extrusion_height            = 0.4*mm;

// width of a single wall, should match your slicer settings
extrusion_width             = 0.4*mm;

// how many lines should a normal wall have (i.e. 0.6(extrusion_width)*6(normal_wall_factor)= 3.6mm wall width)
normal_wall_factor          = 3;

thick_wall_factor           = 4;

// diameter of your filament.
filament_d                  = 1.75*mm;
filament_r                  = filament_d/2;

main_width = 420*mm;
main_depth = 420*mm;
main_height = 400*mm;
main_upper_width = 500*mm;

extrusion_size = 20*mm;
extrusion_thread = ThreadM5;
extrusion_thread_dia = lookup(ThreadSize, extrusion_thread);
extrusion_nut = NutHexM5;
extrusion_nut_dia = lookup(NutWidthMax, extrusion_nut);

extrusion_mount_thread = ThreadM4;

// for tapped ends
extrusion_end_nut = NutHexM6;

main_lower_dist_z = 80*mm;
main_upper_dist_y = 160*mm;

gantry_connector_thickness = 5;

rod_fit_tolerance=1.01;

ziptie_type = [2*mm, 3*mm];
ziptie_thickness = ziptie_type[0];
ziptie_width = ziptie_type[1]+0.6*mm;
ziptie_bearing_distance = 3*mm;

xaxis_rod_distance = 65*mm;
xaxis_rod_d = 9.975*mm;
xaxis_rod_l = 500*mm;
// relative to entire machine
xaxis_rod_offset_x = 0*mm;
xaxis_bearings_top=2;
xaxis_bearings_bottom=1;
xaxis_bearing=bearing_bronze_10_16_12;
xaxis_bearing_bottom=bearing_bronze_10_16_18;
/*xaxis_bearing=bearing_igus_rj4jp_01_10;*/

xaxis_pulley = pulley_2GT_20T;
xaxis_pulley_inner_d = xaxis_pulley[2];
xaxis_pulley_outer_d = xaxis_pulley[3];
xaxis_idler_pulley = pulley_2GT_20T_idler;
xaxis_idler_pulley_inner_d = xaxis_idler_pulley[2];
xaxis_idler_pulley_outer_d = xaxis_idler_pulley[3];

xaxis_belt = TimingBelt_GT2_2;
xaxis_belt_width = 6*mm;
xaxis_beltpath_width = max(xaxis_belt_width+3*mm, xaxis_pulley[0]+2*mm);
xaxis_beltpath_z_offset_pulley = xaxis_pulley_inner_d/2;
/*xaxis_beltpath_z_offsets = [xaxis_beltpath_z_offset_pulley];*/
xaxis_beltpath_z_offsets = [-3*mm-xaxis_beltpath_z_offset_pulley, 3*mm+xaxis_beltpath_z_offset_pulley];
xaxis_beltpath_height_body = xaxis_pulley_outer_d/2+3*mm+v_sum(v_abs(xaxis_beltpath_z_offsets))+5*mm;
xaxis_beltpath_height_holders = max(xaxis_pulley_outer_d+2*mm, xaxis_pulley_inner_d+xaxis_beltpath_z_offsets[0]+3*mm);

xaxis_carriage_bearing_offset_y = ziptie_thickness+3*mm;
xaxis_carriage_beltpath_offset_y = xaxis_carriage_bearing_offset_y+xaxis_bearing[1]/2;

xaxis_motor = dict_replace(Nema17, NemaFrontAxleLength, 22*mm);
xaxis_motor_thread=ThreadM3;
xaxis_motor_nut=NutHexM3;

yaxis_rod_distance = 170*mm;
yaxis_rod_d = 11.975*mm;
yaxis_rod_l = 500*mm;
/*yaxis_bearing=bearing_igus_rj4jp_01_12;*/
yaxis_bearing=bearing_bronze_12_18_18;
yaxis_bearing_distance_y = 7*cm;

yaxis_motor = dict_replace(Nema17, NemaFrontAxleLength, 22*mm);

yaxis_pulley = pulley_2GT_20T;
yaxis_pulley_inner_d = yaxis_pulley[2];
ymotor_mount_thickness = 5;
ymotor_mount_thickness_h = 5;
yaxis_motor_offset_x = lookup(NemaSideSize,yaxis_motor)/2+ymotor_mount_thickness;
yaxis_motor_offset_z = -5*mm;
yaxis_belt_path_offset_x = -yaxis_pulley_inner_d/2;
yaxis_belt_path_offset_z = yaxis_motor_offset_z + 10*mm;

yaxis_idler_pulley = pulley_2GT_20T_idler;
yaxis_idler_pulley_inner_d = yaxis_idler_pulley[2];
yaxis_idler_pulley_outer_d = yaxis_idler_pulley[3];
yaxis_idler_pulley_h = yaxis_idler_pulley[0];
yaxis_idler_mount_thickness = 5;
yaxis_idler_pulley_tight_len = 20*mm;
yaxis_idler_pulley_offset_y = yaxis_idler_mount_thickness + yaxis_pulley_inner_d/2 + yaxis_idler_pulley_tight_len;
yaxis_idler_offset_x = lookup(NemaSideSize,yaxis_motor)/2+ymotor_mount_thickness;
yaxis_idler_offset_z = 10*mm;

yaxis_carriage_size = [220*mm,220*mm,5*mm];
printbed_size = [213*mm,213*mm,3*mm];

zaxis_rod_d = 11.975*mm;
zaxis_rod_l = 500*mm;
// relative to entire machine
zaxis_rod_offset = [0,-20*mm,0];
zaxis_bearing=bearing_bronze_12_18_18;

// Nema17 motor w/340mm long 8*mm leadscrew
zaxis_motor = dict_replace_multiple(Nema17,
        [
        [NemaAxleDiameter, 8*mm],
        [NemaFrontAxleLength, 340*mm],
        ]);

zmotor_w = lookup(NemaSideSize,zaxis_motor);
zmotor_h = lookup(NemaLengthLong,zaxis_motor);

// inner_d, outer_d, thread, outer_h, full_h, screw_dist, screw_thread
zaxis_nut = [20*mm, 36*mm, 8*mm, 5*mm, 23*mm, 13.5*mm, ThreadM3];

zaxis_motor_offset_z = 10*mm;
zmotor_mount_thickness = 5;
zmotor_mount_thickness_h = 10;
zmotor_mount_motor_offset=5;

zmotor_w = lookup(NemaSideSize,zaxis_motor);
zmotor_h = lookup(NemaLengthLong,zaxis_motor);
zmotor_mount_thread_dia = lookup(ThreadSize, extrusion_thread);
zmotor_mount_width = zmotor_w+zmotor_mount_thickness*2 + zmotor_mount_thread_dia*8;
zmotor_mount_h = main_lower_dist_z+extrusion_size+zaxis_motor_offset_z;

zmotor_mount_clamp_dist = zaxis_rod_d*2.5;
zmotor_mount_clamp_thread = extrusion_mount_thread;
zmotor_mount_clamp_nut = NutHexM4;
zmotor_mount_clamp_thread_dia = lookup(ThreadSize, zmotor_mount_clamp_thread);
zmotor_mount_clamp_nut_dia = lookup(NutWidthMin, zmotor_mount_clamp_nut);
zmotor_mount_clamp_nut_thick = lookup(NutThickness, zmotor_mount_clamp_nut);
zmotor_mount_clamp_width = zmotor_mount_clamp_dist+zmotor_mount_clamp_thread_dia*3;

xaxis_zaxis_distance_y_ = max(xaxis_rod_d/2 + zaxis_bearing[1]/2, zaxis_nut[1]/2 - xaxis_rod_d/2);
xaxis_zaxis_distance_y = xaxis_zaxis_distance_y_ + ziptie_type[0]+.5*mm + 1*mm;

zaxis_nut_mount_outer = zaxis_nut[1]/2 + zaxis_rod_d/2 + 1*mm;

// offset between Z motor screw and z rod
// place z rod as close as possible (depends on z nut and also motor etc)
zaxis_rod_screw_distance_x = max(zaxis_nut_mount_outer, zaxis_rod_d/2 + zmotor_w/2 + 1*mm);

// z rod offset from lower extrusion (outer)
zmotor_mount_rod_offset_x = zmotor_w/2+zaxis_rod_screw_distance_x+zmotor_mount_motor_offset;

// z screw offset from lower extrusion (outer)
zmotor_mount_screw_offset_x = zmotor_mount_rod_offset_x - zaxis_rod_screw_distance_x;

color_extrusion = "DimGray";
color_rods = "CornflowerBlue";
color_part = "DarkRed";
color_gantry_connectors = "OliveDrab";


bearing: increase rod cutout

bearing: increase rod cutout

use <transforms.scad>;
use <shapes.scad>
include <bearing_data.scad>
include <units.scad>
include <misc.scad>

module bearing(bearing_type, extra_h=0, override_h=undef, orient=[0,0,1], align=[0,0,0])
{
    h = fallback(override_h, bearing_type[2]) + extra_h;
    size_align(size=[bearing_type[1],bearing_type[1],h], align=align ,orient=orient)
    difference()
    {
        // outer
        cylindera(h=h, d=bearing_type[1], align=[0,0,0]);
        // inner
        cylindera(h=h+.1, d=bearing_type[0], align=[0,0,0]);
        // clips
        if(len(bearing_type) > 3)
        {
            clip_depth=.5;
            for(z=[-1,1])
            translate([0,0,z*bearing_type[3]/2])
            difference()
            {
                cylindera(h=1*mm, d=bearing_type[2]+1, align=[0,0,-z]);
                cylindera(h=1*mm+.1, d=bearing_type[4]-clip_depth, align=[0,0,-z]);
            }

        }
    }
}

module bearing_mount_holes(bearing_type, ziptie_type=[2*mm, 3*mm], ziptie_bearing_distance=3*mm, tolerance=1.01, orient=[1,0,0], ziptie_dist=undef, with_zips=true)
{
    ziptie_thickness = ziptie_type[0];
    ziptie_width = ziptie_type[1]+0.6*mm;

    ziptie_dist_ = fallback(ziptie_dist, bearing_type[3]/2);

    orient(orient)
    {
        // Main bearing cut
        cylindera(h=bearing_type[2]*tolerance, d=bearing_type[1]*tolerance, orient=[0,0,1]);

        if(with_zips)
        {
            for(z=[-1,1])
                translate([0,0,z*ziptie_dist_ - z*1/2])
                    hollow_cylinder(
                            d=bearing_type[1]+ziptie_bearing_distance+ziptie_thickness,
                            thickness = ziptie_thickness*2,
                            h = ziptie_width,
                            taper=false,
                            orient=[0,0,1],
                            align=[0,0,0]
                            );
        }

        // for linear rod
        cylindera(d=bearing_type[0]+2*mm, h=100, orient=[0,0,1]);

        if($show_vit)
        {
            %bearing(bearing_type=bearing_type);

            for(z=[-1,1])
            translate([0,0,z*ziptie_dist_])
            {
                %hollow_cylinder(
                        d=bearing_type[1]+ziptie_bearing_distance+ziptie_thickness,
                        thickness = ziptie_thickness,
                        h = ziptie_width,
                        taper=false,
                        orient=[0,0,1],
                        align=[0,0,-z]
                        );
            }
        }
    }
}

if(false)
{
    b=bearing_igus_rj4jp_01_12;
    bearing_mount_holes(b, orient=[0,0,1]);
    translate([30,0,0])
    bearing(b, orient=[0,0,1]);
}

use <transforms.scad>;
use <shapes.scad>
include <bearing_data.scad>
include <units.scad>
include <misc.scad>

module bearing(bearing_type, extra_h=0, override_h=undef, orient=[0,0,1], align=[0,0,0])
{
    h = fallback(override_h, bearing_type[2]) + extra_h;
    size_align(size=[bearing_type[1],bearing_type[1],h], align=align ,orient=orient)
    difference()
    {
        // outer
        cylindera(h=h, d=bearing_type[1], align=[0,0,0]);
        // inner
        cylindera(h=h+.1, d=bearing_type[0], align=[0,0,0]);
        // clips
        if(len(bearing_type) > 3)
        {
            clip_depth=.5;
            for(z=[-1,1])
            translate([0,0,z*bearing_type[3]/2])
            difference()
            {
                cylindera(h=1*mm, d=bearing_type[2]+1, align=[0,0,-z]);
                cylindera(h=1*mm+.1, d=bearing_type[4]-clip_depth, align=[0,0,-z]);
            }

        }
    }
}

module bearing_mount_holes(bearing_type, ziptie_type=[2*mm, 3*mm], ziptie_bearing_distance=3*mm, tolerance=1.01, orient=[1,0,0], ziptie_dist=undef, with_zips=true)
{
    ziptie_thickness = ziptie_type[0];
    ziptie_width = ziptie_type[1]+0.6*mm;

    ziptie_dist_ = fallback(ziptie_dist, bearing_type[3]/2);

    orient(orient)
    {
        // Main bearing cut
        cylindera(h=bearing_type[2]*tolerance, d=bearing_type[1]*tolerance, orient=[0,0,1]);

        if(with_zips)
        {
            for(z=[-1,1])
                translate([0,0,z*ziptie_dist_ - z*1/2])
                    hollow_cylinder(
                            d=bearing_type[1]+ziptie_bearing_distance+ziptie_thickness,
                            thickness = ziptie_thickness*2,
                            h = ziptie_width,
                            taper=false,
                            orient=[0,0,1],
                            align=[0,0,0]
                            );
        }

        // for linear rod
        cylindera(d=bearing_type[0]+1*mm, h=100, orient=[0,0,1]);

        if($show_vit)
        {
            %bearing(bearing_type=bearing_type);

            for(z=[-1,1])
            translate([0,0,z*ziptie_dist_])
            {
                %hollow_cylinder(
                        d=bearing_type[1]+ziptie_bearing_distance+ziptie_thickness,
                        thickness = ziptie_thickness,
                        h = ziptie_width,
                        taper=false,
                        orient=[0,0,1],
                        align=[0,0,-z]
                        );
            }
        }
    }
}

if(false)
{
    b=bearing_igus_rj4jp_01_12;
    bearing_mount_holes(b, orient=[0,0,1]);
    translate([30,0,0])
    bearing(b, orient=[0,0,1]);
}