extruder wip

extruder wip

use <thing_libutils/shapes.scad>;
use <thing_libutils/misc.scad>;
use <thing_libutils/transforms.scad>;
use <thing_libutils/attach.scad>;
use <thing_libutils/triangles.scad>
use <thing_libutils/linear-extrusion.scad>;
use <thing_libutils/bearing.scad>
use <thing_libutils/metric-screw.scad>

include <config.scad>

xaxis_carriage_bearing_distance = 8;
xaxis_carriage_padding = 2;
xaxis_carriage_mount_distance = 23;
xaxis_carriage_mount_offset_z = 0;
xaxis_carriage_teeth_height=xaxis_belt_width*1.5;
xaxis_carriage_mount_screws = ThreadM4;

xaxis_carriage_conn = [[0, -xaxis_bearing[1]/2 - xaxis_carriage_bearing_offset_y,0], [0,0,0]];

xaxis_carriage_beltfasten_w = 20;

hobbed_gear_d_outer = 12.65;
hobbed_gear_d_inner = 11.5;
hobbed_gear_h = 11;

extruder_gear_small_d_inner = 5.75*mm;
extruder_gear_big_d_inner = 29.35*mm;
extruder_gear_big_d_outer = 30.85*mm;
extruder_gear_big_h = [3.85*mm, 5*mm];

// 13t metal gear and 60t metal gear
extruder_gears_distance=extruder_gear_big_d_inner/2+extruder_gear_small_d_inner/2;

extruder_motor = dict_replace_multiple(Nema17,
        [
        [NemaLengthMedium, 11.75*mm],
        [NemaFrontAxleLength, 5*mm],
        ]);

// shaft from big gear to hobbed gear
extruder_shaft_d = 5*mm;

// dist between gear and motor
extruder_gear_motor_dist = .5*mm;
extruder_motor_angle = -80;
extruder_motor_offset_x = cos(extruder_motor_angle) * extruder_gears_distance;
extruder_motor_offset_z = sin(extruder_motor_angle) * extruder_gears_distance;
extruder_motor_holedist = lookup(NemaDistanceBetweenMountingHoles, extruder_motor);

extruder_gear_big_offset=[-extruder_motor_offset_x,0,extruder_motor_offset_z];

extruder_offset = [0,0,10*mm];
extruder_offset_a = -extruder_gear_big_offset+[
    0,
    xaxis_bearing[1] + xaxis_carriage_bearing_offset_y + 1*mm,
    0];
extruder_filapath_offset = [hobbed_gear_d_inner/2, -15*mm, 0];

extruder_guilder_bearing = bearing_625;
extruder_hotmount_clamp_thread = ThreadM3;

module x_carriage_base(show_bearings=false)
{
    bottom_width = xaxis_bearing[2] + 2*xaxis_carriage_padding;
    top_width = xaxis_bearing[2]*2 + xaxis_carriage_bearing_distance + 2*xaxis_carriage_padding;
    thickness = xaxis_bearing[1]/2 + xaxis_carriage_bearing_offset_y;

    hull()
    {
        // top bearings
        translate([0,0,xaxis_rod_distance/2])
            rcubea([top_width, thickness, xaxis_bearing[1]+xaxis_carriage_padding+ziptie_bearing_distance*2], align=[0,1,0]);

        /*rcubea([top_width,thickness,xaxis_rod_distance/2], align=[0,1,0]);*/

        // bottom bearing
        translate([0,0,-xaxis_rod_distance/2])
            rcubea([bottom_width, thickness, xaxis_bearing[1]+xaxis_carriage_padding+ziptie_bearing_distance*2], align=[0,1,0]);

    }
    translate([0,xaxis_bearing[1]/2+xaxis_carriage_bearing_offset_y+xaxis_carriage_beltpath_offset+.1,0])
    {
        translate([0,-xaxis_beltpath_width/2,0])
        for(x=[-1,1])
        translate([x*(xaxis_carriage_beltfasten_w/2+5),-xaxis_beltpath_width/2,xaxis_pulley_inner_d/2])
        rcubea([xaxis_carriage_beltfasten_w,xaxis_beltpath_width,xaxis_beltpath_height/3], align=[0,0,-1]);
    }

    if(show_bearings)
    {
        for(x=[-1,1])
        translate([
                x*(xaxis_carriage_bearing_distance+xaxis_bearing[2])/2,
                xaxis_bearing[1]/2 + xaxis_carriage_bearing_offset_y,
                xaxis_rod_distance/2
        ])
        bearing(xaxis_bearing, orient=[1,0,0]);

        translate([
                0,
                xaxis_bearing[1]/2 + xaxis_carriage_bearing_offset_y,
                -xaxis_rod_distance/2
        ])
        bearing(xaxis_bearing, orient=[1,0,0]);

        /*translate([0,xaxis_carriage_beltpath_offset,0])*/
        /*for(i=[-1,1])*/
        /*translate([i*100,0,0])*/
        /*pulley(xaxis_idler_pulley, orient=[0,1,0]);*/
    }

}

module x_carriage_holes()
{
    for(i=[-1,1])
    translate([
            i*(xaxis_bearing[2]/2+xaxis_carriage_bearing_distance/2),
            xaxis_bearing[1]/2+xaxis_carriage_bearing_offset_y,
            xaxis_rod_distance/2
    ])
    {
        bearing_mount_holes(xaxis_bearing, orient=[1,0,0]);
        cubea([xaxis_bearing[2]*2,xaxis_bearing[1]/2+10,xaxis_bearing[1]+1*mm], align=[0,1,0]);
    }

    translate([
            0,
            xaxis_bearing[1]/2+xaxis_carriage_bearing_offset_y,
            -xaxis_rod_distance/2])
    {
        bearing_mount_holes(xaxis_bearing, orient=[1,0,0]);
        cubea([xaxis_bearing[2]*2,xaxis_bearing[1]/2+10,xaxis_bearing[1]+1*mm], align=[0,1,0]);
    }

    // Extruder mounting holes
    /*translate([0,0,xaxis_carriage_mount_offset_z])*/
    /*for(j=[-1,1])*/
    /*for(i=[-1,1])*/
    /*{*/
        /*translate([i*xaxis_carriage_mount_distance/2,0,j*xaxis_carriage_mount_distance/2])*/
        /*{*/
            /*screw_dia = lookup(ThreadSize, xaxis_carriage_mount_screws);*/
            /*cylindera(d=screw_dia, h=100, orient=[0,1,0]);*/
        /*}*/
    /*}*/

    translate([0,xaxis_carriage_beltpath_offset+.1,0])
    {
        // Cut clearing space for the belt
        /*translate([0,-xaxis_beltpath_width/2,-xaxis_beltpath_height/2])*/
            /*#rcubea([500,xaxis_beltpath_width+1,5], align=[0,1,0], extrasize=[0,0,4], extrasize_align=[0,0,1]);*/

        translate([0,-xaxis_beltpath_width/2,0])
        {
            difference()
            {
                rcubea([500,xaxis_beltpath_width*2,xaxis_beltpath_height], align=[0,1,0]);
                for(x=[-1,1])
                translate([x*(xaxis_carriage_beltfasten_w/2+5),-xaxis_beltpath_width/2,xaxis_pulley_inner_d/2])
                    rcubea([xaxis_carriage_beltfasten_w,xaxis_beltpath_width*2,xaxis_beltpath_height/3], align=[0,1,-1]);
            }
        }

        /*belt_thickness=1.5;*/
        /*for(i=[-1,1])*/
            /*translate([i*30,0,0])*/
                /*rcubea([15,xaxis_beltpath_width,15-belt_thickness], align=[0,0,0]);*/

        // Cut in the middle for belt
        /*rcubea([7,xaxis_beltpath_width,xaxis_beltpath_height], align=[0,0,0]);*/

        /*translate([0,-xaxis_beltpath_width/2,xaxis_pulley_inner_d/2])*/
        /*{*/
            /*// Belt slit*/
            /*rcubea([500,xaxis_beltpath_width,belt_thickness], align=[0,1,0]);*/

            /*[>// Teeth cuts<]*/
            /*[>teeth = 50;<]*/
            /*[>teeth_height = 2;<]*/
            /*[>translate([-belt_tooth_distance/2*teeth-.5,0,0])<]*/
            /*[>for(i=[0:teeth])<]*/
            /*[>{<]*/
                /*[>translate([i*belt_tooth_distance,0,0])<]*/
                    /*[>cubea([belt_tooth_distance*belt_tooth_ratio,xaxis_carriage_teeth_height,teeth_height], align=[0,0,-1]);<]*/
            /*[>}<]*/
        /*}*/
    }
}

module extruder_gear_small()
{
    difference()
    {
        union()
        {
            hull()
            {
                cylindera(d=extruder_gear_small_d_inner, h=7*mm, orient=[0,1,0], align=[0,1,0]);
                cylindera(d=10*mm, h= 3*mm, orient=[0,1,0], align=[0,1,0]);
            }
            cylindera(d=extruder_gear_small_d_inner, h=13*mm, orient=[0,1,0], align=[0,1,0]);
        }
        cylindera(d=5*mm, h=13*mm+.1, orient=[0,1,0], align=[0,1,0]);
    }
}

module extruder_gear_big(align=[0,0,0], orient=[0,0,1])
{
    total_h = extruder_gear_big_h[0]+extruder_gear_big_h[1];
    size_align([extruder_gear_big_d_inner, extruder_gear_big_d_inner, total_h], align=align, orient=orient)
    translate([0,0,-extruder_gear_big_h[0] + total_h/2])
    difference()
    {
        union()
        {
            cylindera(d=extruder_gear_big_d_inner, h=extruder_gear_big_h[0], orient=[0,0,1], align=[0,0,1]);
            cylindera(d=12*mm, h=extruder_gear_big_h[1], orient=[0,0,1], align=[0,0,-1]);
        }
        translate([0,0,-.5])
        cylindera(d=5*mm, h=total_h+.2, orient=[0,0,1], align=[0,0,0]);
    }
}

module motor_mount_cut(motor=Nema17, h=10*mm)
{
    screw_dist = lookup(NemaDistanceBetweenMountingHoles, motor);

    // round dia
    translate([0, .1, 0])
    cylindera(d=1.1*lookup(NemaRoundExtrusionDiameter, motor), h=h, orient=[0,1,0], align=[0,1,0]);

    // motor axle
    translate([0, .1, 0])
    cylindera(d=1.2*lookup(NemaAxleDiameter, motor), h=lookup(NemaFrontAxleLength, motor)+2*mm, orient=[0,1,0], align=[0,1,0]);

    // bearing for offloading force on motor shaft
    /*translate([0, -1*mm-xaxis_pulley[1]-.1, 0])*/
    scale(1.03)
    bearing(bearing_MR105, override_h=h, orient=[0,1,0], align=[0,-1,0]);

    motor_thread=ThreadM3;
    motor_nut=MHexNutM3;
    for(x=[-1,1])
    for(z=[-1,1])
    translate([x*screw_dist/2, -h, z*screw_dist/2])
    {
        if(x!=-1 || z!=-1)
        screw_cut(motor_nut, h=h, with_nut=false, orient=[0,1,0], align=[0,1,0]);
    }
}
extruder_a_h = 14*mm;

module extruder_a(show_vitamins=false)
{
    difference()
    {
        hull()
        /*union()*/
        {
            side = 15*mm;
            rcubea([extruder_motor_holedist+side/2,extruder_a_h,extruder_motor_holedist+side/2], align=[0,1,0]);
            /*hull()*/
            /*{*/
                /*for(x=[-1,1])*/
                /*for(z=[-1,1])*/
                /*translate([(extruder_motor_holedist/2)*x,0,(extruder_motor_holedist/2)*z])*/
                /*rotate([0,x*45,0])*/
                /*rcubea([side/2,extruder_a_h,side/2], align=[0,1,0]);*/
            /*}*/
            translate(extruder_gear_big_offset)
            cylindera(d=extruder_gear_big_d_outer+3*mm, h=extruder_a_h, orient=[0,1,0], align=[0,-1,0], round_radius=2);
        }

        translate([0,extruder_a_h,0])
        {
            translate(extruder_gear_big_offset)
            {
                /*scale([1.3,2.0,1.3])*/
                /*#extruder_gear_big(orient=[0,-1,0], align=[0,-1,0]);*/

                // big gear cutout
                translate([0,-bearing_MR105[2]+.1,0])
                cylindera(d=extruder_gear_big_d_outer+1*mm, h=extruder_a_h+.2, orient=[0,1,0], align=[0,1,0]);

                translate([0,.1,0])
                cylindera(d=extruder_shaft_d+.5*mm, h=extruder_a_h+.2, orient=[0,1,0], align=[0,1,0]);

                translate([0,.1,0])
                scale(1.03)
                bearing(bearing_MR105, override_h=6*mm, orient=[0,1,0], align=[0,-1,0]);
            }

            motor_mount_cut(extruder_motor, h=extruder_a_h+1);
        }

    }

    if(show_vitamins)
    translate([0,extruder_a_h,0])
    {
        translate([0,-extruder_gear_motor_dist,0])
        {
            extruder_gear_small();

            // big gear
            translate(extruder_gear_big_offset)
            {
                translate([0,1,0])
                translate([0,-bearing_MR105[2]+.1,0])
                extruder_gear_big(orient=[0,-1,0], align=[0,-1,0]);

                translate([0,1,0])
                bearing(bearing_MR105, orient=[0,1,0], align=[0,-1,0]);

                translate([0,bearing_MR105[2],0])
                {
                    cylindera(h=60*mm, d=extruder_shaft_d, orient=[0,1,0], align=[0,1,0]);
                }
            }
        }
        motor(extruder_motor, NemaMedium, dualAxis=false, orientation=[-90,0,0]);
    }
}

// from E3D V6 heatsink drawing
// http://wiki.e3d-online.com/wiki/File:DRAWING-V6-175-SINK.png
// each entry == dia + h
hotmount_d_h=[[16*mm,3.7*mm],[12*mm,6*mm],[16*mm,3*mm]];
hotmount_outer_size_xy=max(vec_i(hotmount_d_h,0))+5*mm;
hotmount_outer_size_h=max(vec_i(hotmount_d_h,1))+5*mm;
hotmount_offset_h=-4*mm;
// which side does hotend slide in (x-axis, i.e. -1 is left, 1 is right)
hotmount_clamp_side=1;
hotmount_tolerance=1.05*mm;

// hotmount clamp screws distance from center
hotmount_clamp_thread = ThreadM3;
hotmount_clamp_nut = MHexNutM3;

hotmount_clamp_screw_dia = lookup(ThreadSize, hotmount_clamp_thread);
hotmount_clamp_screws_dist = hotmount_d_h[1][1] + 1.5*hotmount_clamp_screw_dia;
hotmount_clamp_pad = 0;
hotmount_clamp_thickness = 5*mm;
hotmount_clamp_y = 2*(hotmount_clamp_screws_dist + hotmount_clamp_screw_dia + hotmount_clamp_pad);
hotmount_clamp_height = hotmount_d_h[1][1];

module hotmount_cutout(extend_cut=false)
{
    // cutout of j-head/e3d heatsink mount
    heights=vec_i(hotmount_d_h,1);
    for(e=v_itrlen(hotmount_d_h))
    {
        hs=v_sum(heights,e-1);
        translate([0,0,-hs])
        {
            d=hotmount_d_h[e][0]*hotmount_tolerance;
            h=hotmount_d_h[e][1]*hotmount_tolerance;
            cylindera(d=d,h=h,align=[0,0,-1]);
            if(extend_cut)
            {
                cubea([extruder_b_w/2+1,d,h],align=[hotmount_clamp_side,0,-1]);
            }
        }
    }
}

module hotmount_clamp()
{
    difference()
    {
        union()
        {
            translate([extruder_b_w/2 * hotmount_clamp_side, 0, 0]);
            {
                cubea([hotmount_clamp_thickness, hotmount_clamp_y, hotmount_clamp_height], align=[-hotmount_clamp_side,0,0]);
            }

            difference()
            {
                translate([extruder_b_w/2 * hotmount_clamp_side, 0, 0]);
                {
                    cubea([extruder_b_w/2, hotmount_d_h[1][0], hotmount_clamp_height], align=[-hotmount_clamp_side,0,0]);
                }

                translate([(-extruder_b_w/2 * hotmount_clamp_side) + (-0.5*hotmount_clamp_side), 0, hotmount_d_h[0][1]+hotmount_d_h[1][1]/2])
                {
                    hotmount_cutout(extend_cut = false);
                }
            }

        }

        // clamp mount screw holes
        for(i=[-1,1])
        {
            translate([.1, i*hotmount_clamp_screws_dist, 0])
                rotate([0,90,0])
                cylindera(r=screw_m3[0], h=hotmount_clamp_thickness+.2, align=[0,0,-hotmount_clamp_side], extra_h=2);
        }
    }
}

extruder_b_bearing = bearing_MR105;
extruder_b_w = hobbed_gear_d_outer+10*mm;

module extruder_b(show_vitamins=false)
{
    translate(extruder_filapath_offset-[hobbed_gear_d_inner/2,0,0])
    {
        // guidler mount
        guidler_arm_len = 15*mm;
        translate([hobbed_gear_d_inner/2,0,guidler_arm_len])
        {
            difference()
            {
                cylindera(d=2*lookup(ThreadSize, ThreadM3), h=10*mm, orient=[0,1,0]);
                cylindera(d=2*lookup(ThreadSize, ThreadM3), h=10*mm, orient=[0,1,0]);
            }
        }

        difference()
        {
            /*hull()*/
            union()
            {
                // main house
                extruder_b_size=[10,extruder_filapath_offset,10];
                #rcubea(extruder_b_size);

                // gear support
                translate([0,-hobbed_gear_h/2,0])
                {
                    // hobbed gear support
                    cylindera(d=hobbed_gear_d_outer+5*mm, h=abs(extruder_filapath_offset[1])+hobbed_gear_h/2, align=[0,-1,0], orient=[0,1,0]);

                    // bearing support
                    cylindera(d=extruder_b_bearing[1]+5*mm, h=extruder_b_bearing[2]+4*mm, align=[0,1,0], orient=[0,1,0]);

                }
                // hotmount support
                translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h])
                cubea([extruder_b_w, hotmount_outer_size_xy, hotmount_outer_size_h], align=[0,0,-1]);

                // clamp mount screw holes
                translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h])
                for(i=[-1,1])
                {
                    translate([0, i*hotmount_clamp_screws_dist, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                        rotate([0,90,0])
                        cylindera(r=lookup(ThreadSize, extruder_hotmount_clamp_thread)+3*mm, h=extruder_b_w);
                }
            }

            // hobbed gear
            cylindera(h=hobbed_gear_h, d=hobbed_gear_d_outer+2*mm, orient=[0,1,0], align=[0,0,0]);

            translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h])
            for(i=[-1,1])
            {
                translate([0, i*hotmount_clamp_screws_dist, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                    rotate([0,90,0])
                    cylindera(d=lookup(ThreadSize, extruder_hotmount_clamp_thread), h=extruder_b_w+10);
            }

            // filament path
            translate([hobbed_gear_d_outer/2,0,0])
            cylindera(h=1000, d=4*mm, orient=[0,0,1], align=[0,0,0]);

            // gear cutout
            translate([0,-hobbed_gear_h/2-.5*mm,0])
                cylindera(d=extruder_b_bearing[1]+.3*mm, h=extruder_b_bearing[2]+.5*mm, align=[0,1,0], orient=[0,1,0]);

            for(x=[-1,1])
            translate([x*hobbed_gear_d_inner/2,0,0])
            scale([1.03,1,1.03])
            {
                cubea([extruder_guilder_bearing[1]+1*mm,extruder_guilder_bearing[2]+1*mm,extruder_guilder_bearing[1]*2], align=[x,0,1]);
                cylindera(d=extruder_guilder_bearing[1]+1*mm, h=extruder_guilder_bearing[2]+1*mm, orient=[0,1,0], align=[x,0,0]);
            }

            translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h+.01])
            {
                hotmount_cutout(extend_cut=true);

                // clamp mount screw holes
                for(i=[-1,1])
                {
                    translate([0, i*hotmount_clamp_screws_dist, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                        rotate([0,90,0])
                        cylindera(d=lookup(ThreadSize, extruder_hotmount_clamp_thread), h=extruder_b_w+1);
                }

                translate([extruder_b_w/2 * (hotmount_clamp_side), 0, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                {
                    cubea([hotmount_clamp_thickness+0.2, hotmount_clamp_y+0.2, hotmount_clamp_height+0.2], align=[-hotmount_clamp_side,0,0], extrasize=[1,0,0], extrasize_align=[hotmount_clamp_side,0,0]);
                }
            }
        }

        if(show_vitamins)
        {
            translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h+.01])
            translate([extruder_b_w/2 * (hotmount_clamp_side), 0, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
            hotmount_clamp();

            translate([0,-hobbed_gear_h/2-extruder_b_bearing[2]-.5*mm,0])
            {
                cylindera(h=extruder_a_h+extruder_offset_a[1]-extruder_filapath_offset[1], d=extruder_shaft_d, orient=[0,1,0], align=[0,-1,0]);

                bearing(extruder_b_bearing, orient=[0,1,0], align=[0,1,0]);
            }

            // hobbed gear
            cylindera(h=hobbed_gear_h, d=hobbed_gear_d_inner, orient=[0,1,0], align=[0,0,0]);
            for(y=[-1,1])
            translate([0,y*hobbed_gear_h/2,0])
            {
                cylindera(h=hobbed_gear_h/3, d=hobbed_gear_d_outer, orient=[0,1,0], align=[0,y,0]);
            }
        }
    }
}

// Final part
module x_carriage(show_bearings=true)
{
    difference()
    {
        /*hull()*/
        union()
        {
            x_carriage_base(show_bearings=show_bearings);
            translate(extruder_offset)
            translate(extruder_offset_a)
            {
                for(x=[-1,1])
                for(z=[-1,1])
                translate([x*extruder_motor_holedist/2,0,z*extruder_motor_holedist/2])
                cylindera(d=10*mm, h=extruder_offset_a[1], orient=[0,1,0], align=[0,1,0], round_radius=2);
            }
        }
        translate(extruder_offset)
        translate(extruder_offset_a)
        {
            for(x=[-1,1])
            for(z=[-1,1])
            translate([x*extruder_motor_holedist/2,0,z*extruder_motor_holedist/2])
            translate([0,.1,0])
            cylindera(d=3*mm, h=extruder_offset_a[1]+.2, orient=[0,1,0], align=[0,1,0]);
        }
        x_carriage_holes();
    }
}

module x_extruder_a()
{
    translate(extruder_offset)
    translate(extruder_offset_a)
    extruder_a(show_vitamins=true);
}

module x_extruder_b()
{
    translate(extruder_offset)
    {
        extruder_b(show_vitamins=true);
    }
}

/*translate([0,-42,38])*/
/*rotate([0,0,90])*/
/*translate([0,-1,-42])*/
/*translate([-83,25,-42])*/
/*rotate([90,0,0])*/
/*import("stl/i3R_Compact_E3Dv6_Extruder_1.75_01.STL");*/

module x_extruder_hotend()
{
    hotend_conn =[[0,0,27.8-hotmount_offset_h],[0,0,1]];
    translate(extruder_offset)
    translate(extruder_filapath_offset)
    attach(extruder_conn_hotend, hotend_conn)
        rotate([90,0,270])
        %import("stl/E3D_V6_1.75mm_Universal_HotEnd_Mockup.stl");

}

/*if(false)*/
{
    /*extruder_a(show_vitamins=true);*/
    %x_carriage(show_bearings=false);

    /*if(false)*/
    %x_extruder_a();

    /*if(false)*/
    x_extruder_b();

    //filament path
    %translate(extruder_filapath_offset)
        cylindera(h=1000, d=1.75*mm, orient=[0,0,1], align=[0,0,0]);
}

use <thing_libutils/shapes.scad>;
use <thing_libutils/misc.scad>;
use <thing_libutils/transforms.scad>;
use <thing_libutils/attach.scad>;
use <thing_libutils/triangles.scad>
use <thing_libutils/linear-extrusion.scad>;
use <thing_libutils/bearing.scad>
use <thing_libutils/metric-screw.scad>

include <config.scad>

xaxis_carriage_bearing_distance = 8;
xaxis_carriage_padding = 2;
xaxis_carriage_mount_distance = 23;
xaxis_carriage_mount_offset_z = 0;
xaxis_carriage_teeth_height=xaxis_belt_width*1.5;
xaxis_carriage_mount_screws = ThreadM4;

xaxis_carriage_conn = [[0, -xaxis_bearing[1]/2 - xaxis_carriage_bearing_offset_y,0], [0,0,0]];

xaxis_carriage_beltfasten_w = 20;
module x_carriage_base()
{
    bottom_width = xaxis_bearing[2] + 2*xaxis_carriage_padding;
    top_width = xaxis_bearing[2]*2 + xaxis_carriage_bearing_distance + 2*xaxis_carriage_padding;
    thickness = xaxis_bearing[1]/2 + xaxis_carriage_bearing_offset_y;

    hull()
    {
        // top bearings
        translate([0,0,xaxis_rod_distance/2])
            rcubea([top_width, thickness, xaxis_bearing[1]+xaxis_carriage_padding+ziptie_bearing_distance*2], align=[0,1,0]);

        /*rcubea([top_width,thickness,xaxis_rod_distance/2], align=[0,1,0]);*/

        // bottom bearing
        translate([0,0,-xaxis_rod_distance/2])
            rcubea([bottom_width, thickness, xaxis_bearing[1]+xaxis_carriage_padding+ziptie_bearing_distance*2], align=[0,1,0]);

    }
    translate([0,xaxis_bearing[1]/2+xaxis_carriage_bearing_offset_y+xaxis_carriage_beltpath_offset+.1,0])
    {
        translate([0,-xaxis_beltpath_width/2,0])
        for(x=[-1,1])
        translate([x*(xaxis_carriage_beltfasten_w/2+5),-xaxis_beltpath_width/2,xaxis_pulley_inner_d/2])
        rcubea([xaxis_carriage_beltfasten_w,xaxis_beltpath_width,xaxis_beltpath_height/3], align=[0,0,-1]);
    }
}

module x_carriage_holes()
{
    for(i=[-1,1])
    translate([
            i*(xaxis_bearing[2]/2+xaxis_carriage_bearing_distance/2),
            xaxis_bearing[1]/2+xaxis_carriage_bearing_offset_y,
            xaxis_rod_distance/2
    ])
    {
        bearing_mount_holes(xaxis_bearing, orient=[1,0,0]);
        cubea([xaxis_bearing[2]*2,xaxis_bearing[1]/2+10,xaxis_bearing[1]+1*mm], align=[0,1,0]);
    }

    translate([
            0,
            xaxis_bearing[1]/2+xaxis_carriage_bearing_offset_y,
            -xaxis_rod_distance/2])
    {
        bearing_mount_holes(xaxis_bearing, orient=[1,0,0]);
        cubea([xaxis_bearing[2]*2,xaxis_bearing[1]/2+10,xaxis_bearing[1]+1*mm], align=[0,1,0]);
    }

    // Extruder mounting holes
    /*translate([0,0,xaxis_carriage_mount_offset_z])*/
    /*for(j=[-1,1])*/
    /*for(i=[-1,1])*/
    /*{*/
        /*translate([i*xaxis_carriage_mount_distance/2,0,j*xaxis_carriage_mount_distance/2])*/
        /*{*/
            /*screw_dia = lookup(ThreadSize, xaxis_carriage_mount_screws);*/
            /*cylindera(d=screw_dia, h=100, orient=[0,1,0]);*/
        /*}*/
    /*}*/

    translate([0,xaxis_carriage_beltpath_offset+.1,0])
    {
        // Cut clearing space for the belt
        /*translate([0,-xaxis_beltpath_width/2,-xaxis_beltpath_height/2])*/
            /*#rcubea([500,xaxis_beltpath_width+1,5], align=[0,1,0], extrasize=[0,0,4], extrasize_align=[0,0,1]);*/

        translate([0,-xaxis_beltpath_width/2,0])
        {
            difference()
            {
                rcubea([500,xaxis_beltpath_width*2,xaxis_beltpath_height], align=[0,1,0]);
                for(x=[-1,1])
                translate([x*(xaxis_carriage_beltfasten_w/2+5),-xaxis_beltpath_width/2,xaxis_pulley_inner_d/2])
                    rcubea([xaxis_carriage_beltfasten_w,xaxis_beltpath_width*2,xaxis_beltpath_height/3], align=[0,1,-1]);
            }
        }

        /*belt_thickness=1.5;*/
        /*for(i=[-1,1])*/
            /*translate([i*30,0,0])*/
                /*rcubea([15,xaxis_beltpath_width,15-belt_thickness], align=[0,0,0]);*/

        // Cut in the middle for belt
        /*rcubea([7,xaxis_beltpath_width,xaxis_beltpath_height], align=[0,0,0]);*/

        /*translate([0,-xaxis_beltpath_width/2,xaxis_pulley_inner_d/2])*/
        /*{*/
            /*// Belt slit*/
            /*rcubea([500,xaxis_beltpath_width,belt_thickness], align=[0,1,0]);*/

            /*[>// Teeth cuts<]*/
            /*[>teeth = 50;<]*/
            /*[>teeth_height = 2;<]*/
            /*[>translate([-belt_tooth_distance/2*teeth-.5,0,0])<]*/
            /*[>for(i=[0:teeth])<]*/
            /*[>{<]*/
                /*[>translate([i*belt_tooth_distance,0,0])<]*/
                    /*[>cubea([belt_tooth_distance*belt_tooth_ratio,xaxis_carriage_teeth_height,teeth_height], align=[0,0,-1]);<]*/
            /*[>}<]*/
        /*}*/
    }
}

extruder_gear_small_d_inner = 5.75*mm;
extruder_gear_big_d_inner = 29.35*mm;
extruder_gear_big_d_outer = 30.85*mm;
extruder_gear_big_h = [3.85*mm, 5*mm];

module extruder_gear_small()
{
    difference()
    {
        union()
        {
            hull()
            {
                cylindera(d=extruder_gear_small_d_inner, h=7*mm, orient=[0,1,0], align=[0,1,0]);
                cylindera(d=10*mm, h= 3*mm, orient=[0,1,0], align=[0,1,0]);
            }
            cylindera(d=extruder_gear_small_d_inner, h=13*mm, orient=[0,1,0], align=[0,1,0]);
        }
        cylindera(d=5*mm, h=13*mm+.1, orient=[0,1,0], align=[0,1,0]);
    }
}

module extruder_gear_big(align=[0,0,0], orient=[0,0,1])
{
    total_h = extruder_gear_big_h[0]+extruder_gear_big_h[1];
    size_align([extruder_gear_big_d_inner, extruder_gear_big_d_inner, total_h], align=align, orient=orient)
    translate([0,0,-extruder_gear_big_h[0] + total_h/2])
    difference()
    {
        union()
        {
            cylindera(d=extruder_gear_big_d_inner, h=extruder_gear_big_h[0], orient=[0,0,1], align=[0,0,1]);
            cylindera(d=12*mm, h=extruder_gear_big_h[1], orient=[0,0,1], align=[0,0,-1]);
        }
        translate([0,0,-.5])
        cylindera(d=5*mm, h=total_h+.2, orient=[0,0,1], align=[0,0,0]);
    }
}

extruder_motor = dict_replace_multiple(Nema17,
        [
        [NemaLengthMedium, 11.75*mm],
        [NemaFrontAxleLength, 5*mm],
        ]);

extruder_shaft_d = 5*mm;
// dist between gear and motor
extruder_gear_motor_dist = .5*mm;

module motor_mount_cut(motor=Nema17, h=10*mm)
{
    screw_dist = lookup(NemaDistanceBetweenMountingHoles, motor);

    // round dia
    translate([0, .1, 0])
    cylindera(d=1.1*lookup(NemaRoundExtrusionDiameter, motor), h=h, orient=[0,1,0], align=[0,1,0]);

    // motor axle
    translate([0, .1, 0])
    cylindera(d=1.2*lookup(NemaAxleDiameter, motor), h=lookup(NemaFrontAxleLength, motor)+2*mm, orient=[0,1,0], align=[0,1,0]);

    // bearing for offloading force on motor shaft
    /*translate([0, -1*mm-xaxis_pulley[1]-.1, 0])*/
    scale(1.03)
    bearing(bearing_MR105, override_h=h, orient=[0,1,0], align=[0,-1,0]);

    motor_thread=ThreadM3;
    motor_nut=MHexNutM3;
    for(x=[-1,1])
    for(z=[-1,1])
    translate([x*screw_dist/2, -h, z*screw_dist/2])
    {
        if(x!=-1 || z!=-1)
        screw_cut(motor_nut, h=h, with_nut=false, orient=[0,1,0], align=[0,1,0]);
    }
}

function sinh(x) = (1 - pow(e, -2 * x)) / (2 * pow(e, -x));
function cosh(x) = (1 + pow(e, -2 * x)) / (2 * pow(e, -x));
function tanh(x) = sinh(x) / cosh(x);
function cot(x) = 1 / tan(x);

// 13t metal gear and 60t metal gear
extruder_gears_distance=extruder_gear_big_d_inner/2+extruder_gear_small_d_inner/2;

extruder_motor_angle = -80;
extruder_motor_offset_x = cos(extruder_motor_angle) * extruder_gears_distance;
extruder_motor_offset_z = sin(extruder_motor_angle) * extruder_gears_distance;
extruder_motor_holedist = lookup(NemaDistanceBetweenMountingHoles, extruder_motor);

extruder_gear_big_offset=[-extruder_motor_offset_x,0,extruder_motor_offset_z];

extruder_a_h = 14*mm;

module extruder_a(show_vitamins=false)
{
    difference()
    {
        hull()
        /*union()*/
        {
            side = 15*mm;
            rcubea([extruder_motor_holedist+side/2,extruder_a_h,extruder_motor_holedist+side/2], align=[0,1,0]);
            /*hull()*/
            /*{*/
                /*for(x=[-1,1])*/
                /*for(z=[-1,1])*/
                /*translate([(extruder_motor_holedist/2)*x,0,(extruder_motor_holedist/2)*z])*/
                /*rotate([0,x*45,0])*/
                /*rcubea([side/2,extruder_a_h,side/2], align=[0,1,0]);*/
            /*}*/
            translate(extruder_gear_big_offset)
            cylindera(d=extruder_gear_big_d_outer+3*mm, h=extruder_a_h, orient=[0,1,0], align=[0,-1,0]);
        }

        translate([0,extruder_a_h,0])
        {
            translate(extruder_gear_big_offset)
            {
                /*scale([1.3,2.0,1.3])*/
                /*#extruder_gear_big(orient=[0,-1,0], align=[0,-1,0]);*/

                // big gear cutout
                translate([0,-bearing_MR105[2]+.1,0])
                cylindera(d=extruder_gear_big_d_outer+1*mm, h=extruder_a_h+.2, orient=[0,1,0], align=[0,1,0]);

                translate([0,.1,0])
                cylindera(d=extruder_shaft_d+.5*mm, h=extruder_a_h+.2, orient=[0,1,0], align=[0,1,0]);

                translate([0,.1,0])
                scale(1.03)
                bearing(bearing_MR105, override_h=6*mm, orient=[0,1,0], align=[0,-1,0]);
            }

            motor_mount_cut(extruder_motor, h=extruder_a_h+1);
        }

    }

    if(show_vitamins)
    translate([0,extruder_a_h,0])
    {
        translate([0,-extruder_gear_motor_dist,0])
        {
            extruder_gear_small();

            // big gear
            translate(extruder_gear_big_offset)
            {
                translate([0,1,0])
                translate([0,-bearing_MR105[2]+.1,0])
                extruder_gear_big(orient=[0,-1,0], align=[0,-1,0]);

                translate([0,1,0])
                bearing(bearing_MR105, orient=[0,1,0], align=[0,-1,0]);

                translate([0,bearing_MR105[2],0])
                {
                    cylindera(h=60*mm, d=extruder_shaft_d, orient=[0,1,0], align=[0,1,0]);
                }
            }
        }
        motor(extruder_motor, NemaMedium, dualAxis=false, orientation=[-90,0,0]);
    }
}

// from E3D V6 heatsink drawing
// http://wiki.e3d-online.com/wiki/File:DRAWING-V6-175-SINK.png
// each entry == dia + h
hotmount_d_h=[[16*mm,3.7*mm],[12*mm,6*mm],[16*mm,3*mm]];
hotmount_outer_size_xy=max(vec_i(hotmount_d_h,0))+5*mm;
hotmount_outer_size_h=max(vec_i(hotmount_d_h,1))+5*mm;
hotmount_offset_h=-4*mm;
// which side does hotend slide in (x-axis, i.e. -1 is left, 1 is right)
hotmount_clamp_side=1;
hotmount_tolerance=1.05*mm;

// hotmount clamp screws distance from center
hotmount_clamp_thread = ThreadM3;
hotmount_clamp_nut = MHexNutM3;

hotmount_clamp_screw_dia = lookup(ThreadSize, hotmount_clamp_thread);
hotmount_clamp_screws_dist = hotmount_d_h[1][1] + 1.5*hotmount_clamp_screw_dia;
hotmount_clamp_pad = 0;
hotmount_clamp_thickness = 5*mm;
hotmount_clamp_y = 2*(hotmount_clamp_screws_dist + hotmount_clamp_screw_dia + hotmount_clamp_pad);
hotmount_clamp_height = hotmount_d_h[1][1];

module hotmount_cutout(extend_cut=false)
{
    // cutout of j-head/e3d heatsink mount
    heights=vec_i(hotmount_d_h,1);
    for(e=v_itrlen(hotmount_d_h))
    {
        hs=v_sum(heights,e-1);
        translate([0,0,-hs])
        {
            d=hotmount_d_h[e][0]*hotmount_tolerance;
            h=hotmount_d_h[e][1]*hotmount_tolerance;
            cylindera(d=d,h=h,align=[0,0,-1]);
            if(extend_cut)
            {
                cubea([extruder_b_w/2+1,d,h],align=[hotmount_clamp_side,0,-1]);
            }
        }
    }
}

module hotmount_clamp()
{
    difference()
    {
        union()
        {
            translate([extruder_b_w/2 * hotmount_clamp_side, 0, 0]);
            {
                cubea([hotmount_clamp_thickness, hotmount_clamp_y, hotmount_clamp_height], align=[-hotmount_clamp_side,0,0]);
            }

            difference()
            {
                translate([extruder_b_w/2 * hotmount_clamp_side, 0, 0]);
                {
                    cubea([extruder_b_w/2, hotmount_d_h[1][0], hotmount_clamp_height], align=[-hotmount_clamp_side,0,0]);
                }

                translate([(-extruder_b_w/2 * hotmount_clamp_side) + (-0.5*hotmount_clamp_side), 0, hotmount_d_h[0][1]+hotmount_d_h[1][1]/2])
                {
                    hotmount_cutout(extend_cut = false);
                }
            }

        }

        // clamp mount screw holes
        for(i=[-1,1])
        {
            translate([.1, i*hotmount_clamp_screws_dist, 0])
                rotate([0,90,0])
                cylindera(r=screw_m3[0], h=hotmount_clamp_thickness+.2, align=[0,0,-hotmount_clamp_side], extra_h=2);
        }
    }
}

extruder_guilder_bearing = bearing_625;
extruder_b_bearing = bearing_MR105;
extruder_hotmount_clamp_thread = ThreadM3;
module extruder_b(show_vitamins=false)
{
    translate(extruder_filapath_offset-[hobbed_gear_d_inner/2,0,0])
    {
        // guidler mount
        guidler_arm_len = 15*mm;
        translate([hobbed_gear_d_inner/2,0,guidler_arm_len])
        {
            difference()
            {
                cylindera(d=2*lookup(ThreadSize, ThreadM3), h=10*mm, orient=[0,1,0]);
                cylindera(d=2*lookup(ThreadSize, ThreadM3), h=10*mm, orient=[0,1,0]);
            }
        }

        difference()
        {
            hull()
            /*union()*/
            {
                // gear support
                translate([0,-hobbed_gear_h/2,0])
                {
                    // hobbed gear support
                    cylindera(d=hobbed_gear_d_outer+5*mm, h=abs(extruder_filapath_offset[1])+hobbed_gear_h/2, align=[0,-1,0], orient=[0,1,0]);

                    // bearing support
                    cylindera(d=extruder_b_bearing[1]+5*mm, h=extruder_b_bearing[2]+4*mm, align=[0,1,0], orient=[0,1,0]);

                }
                // hotmount support
                translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h])
                cubea([extruder_b_w, hotmount_outer_size_xy, hotmount_outer_size_h], align=[0,0,-1]);

                // clamp mount screw holes
                translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h])
                for(i=[-1,1])
                {
                    translate([0, i*hotmount_clamp_screws_dist, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                        rotate([0,90,0])
                        cylindera(r=lookup(ThreadSize, extruder_hotmount_clamp_thread)+3*mm, h=extruder_b_w);
                }
            }

            // hobbed gear
            cylindera(h=hobbed_gear_h, d=hobbed_gear_d_outer+2*mm, orient=[0,1,0], align=[0,0,0]);

            translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h])
            for(i=[-1,1])
            {
                translate([0, i*hotmount_clamp_screws_dist, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                    rotate([0,90,0])
                    cylindera(d=lookup(ThreadSize, extruder_hotmount_clamp_thread), h=extruder_b_w+10);
            }

            // filament path
            translate([hobbed_gear_d_outer/2,0,0])
            cylindera(h=1000, d=4*mm, orient=[0,0,1], align=[0,0,0]);

            // gear cutout
            translate([0,-hobbed_gear_h/2-.5*mm,0])
                cylindera(d=extruder_b_bearing[1]+.3*mm, h=extruder_b_bearing[2]+.5*mm, align=[0,1,0], orient=[0,1,0]);

            for(x=[-1,1])
            translate([x*hobbed_gear_d_inner/2,0,0])
            scale([1.03,1,1.03])
            {
                cubea([extruder_guilder_bearing[1]+1*mm,extruder_guilder_bearing[2]+1*mm,extruder_guilder_bearing[1]*2], align=[x,0,1]);
                cylindera(d=extruder_guilder_bearing[1]+1*mm, h=extruder_guilder_bearing[2]+1*mm, orient=[0,1,0], align=[x,0,0]);
            }

            translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h+.01])
            {
                hotmount_cutout(extend_cut=true);

                // clamp mount screw holes
                for(i=[-1,1])
                {
                    translate([0, i*hotmount_clamp_screws_dist, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                        rotate([0,90,0])
                        cylindera(d=lookup(ThreadSize, extruder_hotmount_clamp_thread), h=extruder_b_w+1);
                }

                translate([extruder_b_w/2 * (hotmount_clamp_side), 0, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
                {
                    cubea([hotmount_clamp_thickness+0.2, hotmount_clamp_y+0.2, hotmount_clamp_height+0.2], align=[-hotmount_clamp_side,0,0], extrasize=[1,0,0], extrasize_align=[hotmount_clamp_side,0,0]);
                }
            }
        }

        if(show_vitamins)
        {
            translate([hobbed_gear_d_inner/2,0,-hobbed_gear_d_outer/2 + hotmount_offset_h+.01])
            translate([extruder_b_w/2 * (hotmount_clamp_side), 0, -hotmount_d_h[0][1]-hotmount_d_h[1][1]/2])
            hotmount_clamp();

            translate([0,-hobbed_gear_h/2-extruder_b_bearing[2]-.5*mm,0])
            {
                cylindera(h=extruder_a_h+extruder_offset_a[1]-extruder_filapath_offset[1], d=extruder_shaft_d, orient=[0,1,0], align=[0,-1,0]);

                bearing(extruder_b_bearing, orient=[0,1,0], align=[0,1,0]);
            }

            // hobbed gear
            cylindera(h=hobbed_gear_h, d=hobbed_gear_d_inner, orient=[0,1,0], align=[0,0,0]);
            for(y=[-1,1])
            translate([0,y*hobbed_gear_h/2,0])
            {
                cylindera(h=hobbed_gear_h/3, d=hobbed_gear_d_outer, orient=[0,1,0], align=[0,y,0]);
            }
        }
    }
}

hobbed_gear_d_outer = 12.65;
hobbed_gear_d_inner = 11.5;
hobbed_gear_h = 11;
extruder_offset = [0,0,10*mm];
extruder_offset_a = -extruder_gear_big_offset+[
    0,
    xaxis_bearing[1] + xaxis_carriage_bearing_offset_y + 1*mm,
    0];
extruder_filapath_offset = [hobbed_gear_d_inner/2, -15*mm, 0];

extruder_b_w = hobbed_gear_d_outer+10*mm;

// Final part
module x_carriage(show_bearings=true)
{
    difference()
    {
        /*hull()*/
        union()
        {
            x_carriage_base();
            translate(extruder_offset)
            translate(extruder_offset_a)
            {
                for(x=[-1,1])
                for(z=[-1,1])
                translate([x*extruder_motor_holedist/2,0,z*extruder_motor_holedist/2])
                cylindera(d=10*mm, h=extruder_offset_a[1], orient=[0,1,0], align=[0,1,0], round_radius=2);
            }
        }
        translate(extruder_offset)
        translate(extruder_offset_a)
        {
            for(x=[-1,1])
            for(z=[-1,1])
            translate([x*extruder_motor_holedist/2,0,z*extruder_motor_holedist/2])
            translate([0,.1,0])
            cylindera(d=3*mm, h=extruder_offset_a[1]+.2, orient=[0,1,0], align=[0,1,0]);
        }
        x_carriage_holes();
    }

    /*if(false)*/
    translate(extruder_offset)
    {
        extruder_b(show_vitamins=true);

        translate(extruder_offset_a)
        {
            %extruder_a(show_vitamins=true);
        }
    }

    /*translate([0,-42,38])*/
    /*rotate([0,0,90])*/
    /*translate([0,-1,-42])*/
    /*translate([-83,25,-42])*/
    /*rotate([90,0,0])*/
    /*import("stl/i3R_Compact_E3Dv6_Extruder_1.75_01.STL");*/

    //filament path
    %translate(extruder_filapath_offset)
        cylindera(h=1000, d=1.75*mm, orient=[0,0,1], align=[0,0,0]);

    hotend_conn =[[0,0,27.8-hotmount_offset_h],[0,0,1]];
    translate(extruder_offset)
    translate(extruder_filapath_offset)
    attach(extruder_conn_hotend, hotend_conn)
        rotate([90,0,270])
        %import("stl/E3D_V6_1.75mm_Universal_HotEnd_Mockup.stl");

    if(show_bearings)
    {
        for(x=[-1,1])
        translate([
                x*(xaxis_carriage_bearing_distance+xaxis_bearing[2])/2,
                xaxis_bearing[1]/2 + xaxis_carriage_bearing_offset_y,
                xaxis_rod_distance/2
        ])
        bearing(xaxis_bearing, orient=[1,0,0]);

        translate([
                0,
                xaxis_bearing[1]/2 + xaxis_carriage_bearing_offset_y,
                -xaxis_rod_distance/2
        ])
        bearing(xaxis_bearing, orient=[1,0,0]);

        /*translate([0,xaxis_carriage_beltpath_offset,0])*/
        /*for(i=[-1,1])*/
        /*translate([i*100,0,0])*/
        /*pulley(xaxis_idler_pulley, orient=[0,1,0]);*/
    }
}

/*if(false)*/
{
/*extruder_a(show_vitamins=true);*/
    x_carriage();
}


polygon wave ant3

polygon wave ant3

error: pathspec 'ant3/polygonWave.scad' did not match any file(s) known to git


Adapt boardholder to box.

Adapt boardholder to box.

$fs=0.2;

plate_width = 110.0;
plate_depth = 120.0;
plate_thickness = 3;

main_standoff_mounting_holes = [
  [-45,  50], [ 45,  50],
  [-45, -44], [ 45, -44],
];

module esc_cutout() {
    translate([0.0, plate_depth / 2.0, 0.0]) {
        cube([62.0, 38.0 * 2.0, plate_thickness * 4.0],
            center=true);
    }
    translate([0.0, 23.0, 0.0]) {
        cylinder(h=10.0,r=5, center=true);
    }
}

module corner_cutouts() {
    union() {
        translate([plate_width / 2, plate_depth / 2, 0.0]) {
            rotate(60.0) {
                cube([20.0, 40.0, 8.0], center=true);
            }
        }
        translate([-plate_width / 2, plate_depth / 2, 0.0]) {
            rotate(-600.0) {
                cube([20.0, 40.0, 8.0], center=true);
            }
        }
    }
}

module power_switch_cutout() {
    translate([-45.0, 35.0, 0.0]) {
        cylinder(h=10.0,r=3.175, center=true);
    }
}

module main_plate_base() {
    translate([0.0, 0.0, plate_thickness / 2.0]) {
        cube([plate_width, plate_depth, plate_thickness],
            center=true);
    }

}

module main_plate() {
    difference() {
        union() {
            main_plate_base();
        }
        union() {
            esc_cutout();
            //corner_cutouts();
            //power_switch_cutout();
            for (hole = main_standoff_mounting_holes) {
                translate([hole[0], hole[1], 0.0]) {
                    cylinder(h=10.0,r=1.5, center=true);
                }
            }
            for (x = [-1, 1], y=[-1, 1]) {
                translate([x * 25, y * 25-25, 0.0]) {
                    cylinder(h=10.0,r=1.5, center=true);
                }
            }
        }
    }
}

main_plate();

$fs=0.2;

plate_width = 130.0;
plate_depth = 120.0;
plate_thickness = 2.5;

main_standoff_mounting_holes = [
  [-45,  50], [ 45,  50],
  [-45, -44], [ 45, -44],
];

pi_holes = [
  [0, 0], [49, 0],
  [0, 58], [49, 58],
];

module esc_cutout() {
    translate([0.0, plate_depth / 2.0, 0.0]) {
        cube([62.0, 38.0 * 2.0, plate_thickness * 4.0],
            center=true);
    }
    translate([0.0, 23.0, 0.0]) {
        cylinder(h=10.0,r=5, center=true);
    }
}

module corner_cutouts() {
    union() {
        translate([plate_width / 2, plate_depth / 2, 0.0]) {
            rotate(60.0) {
                cube([20.0, 40.0, 8.0], center=true);
            }
        }
        translate([-plate_width / 2, plate_depth / 2, 0.0]) {
            rotate(-600.0) {
                cube([20.0, 40.0, 8.0], center=true);
            }
        }
    }
}

module power_switch_cutout() {
    translate([-45.0, 35.0, 0.0]) {
        cylinder(h=10.0,r=3.175, center=true);
    }
}

module main_plate_base() {
    translate([0.0, 0.0, plate_thickness / 2.0]) {
        cube([plate_width, plate_depth, plate_thickness],
            center=true);
    }
    for (hole = pi_holes) {
        translate([hole[0] + 10, hole[1] - 55, 8]) {
            cylinder(h=16,r=2.5, center=true);
        }
        translate([hole[0] + 10, hole[1] - 55, 5]) {
            cylinder(h=10,r=4, center=true);
        }
    }
    translate([0,-plate_depth/2-2,3.25]) {
        difference() {
            cube([20,10,6.5], center=true);
            translate([0,0,2.5])
                cube([16,4,10], center=true);
        }
    }
}

module breadboard() {
    cube([54.45, 82.56, 9.5]);
}

module breadboard_support() {
    cube([54.45, 10, 4.0]);
}

module breadboard_clip() {
    h = 20;
    rotate([90,0,0]) linear_extrude(height=5)
        polygon(points=[[0,0],[3,0],[3,h],[2,h],[0,h-3],[0,h-4],[1.5,h-4],[1.5,0]]);
}

module breadboard_clips() {
    translate([-8,0,0])
        breadboard_clip();
    translate([-8,-32,0])
        breadboard_clip();
    translate([-59.45,-5,0]) rotate([0,0,180])
        breadboard_clip();
    translate([-59.45,-37,0]) rotate([0,0,180])
        breadboard_clip();
    translate([-25,20,0]) rotate([0,0,90])
        breadboard_clip();
    translate([-50,20,0]) rotate([0,0,90])
        breadboard_clip();
    translate([-20,-82.56+20+3,0]) rotate([0,0,-90])
        breadboard_clip();
    translate([-45,-82.56+20+3,0]) rotate([0,0,-90])
        breadboard_clip();
}

module breadboard_mount() {
    union() {
        translate([(-plate_width/2)+4,(-plate_depth/2),2.5]) {
            breadboard_support();
        }
        translate([(-plate_width/2)+4,(-plate_depth/2)-2+82.56/2-5,2.5]) {
            breadboard_support();
        }
        translate([(-plate_width/2)+4,(-plate_depth/2)-3+82.56-8,2.5]) {
            breadboard_support();
        }
    }
}

module main_plate() {
    difference() {
        union() {
            main_plate_base();
            breadboard_mount();
        }
        union() {
            esc_cutout();
            corner_cutouts();
            power_switch_cutout();
            for (hole = main_standoff_mounting_holes) {
                translate([hole[0], hole[1], 0.0]) {
                    cylinder(h=10.0,r=1.5, center=true);
                }
            }
            for (hole = pi_holes) {
                translate([hole[0] + 10, hole[1] - 55, 0.0]) {
                    cylinder(h=40.0,r=1.135, center=true);
                }
            }
            translate([-plate_width/2+4, 6, 0.0]) {
                cylinder(h=20.0,r=1.135, center=true);
            }
            translate([-plate_width/2+4, -11, 0.0]) {
                cylinder(h=20.0,r=1.135, center=true);
            }
        }
    }
}

main_plate();
translate([(-plate_width/2)+4,(-plate_depth/2)-1,6.5]) {
    %breadboard();
}


checking in before changing to have braces under main bar

// config e
Ay=3.318;
AC=17.5;
Bx=53.83;

loY=-60;  // location of lower brace beams
loX= 10;

zBar=90;

$fn=8;

for (a=[-1,1]) {
  %translate([0,0,(zBar-10)*a]) legProxy();
  %translate([0,0,(zBar+10)*a]) legProxy();
  translate( [0,0, zBar    *a]) mainBar();

  %translate([Bx*a,0,0]) cylinder(r=1,h=120,$fn=16,center=true); // main axle
  for (b=[-1,1]) translate([Bx*b,0,zBar*a]) {
     color([0,0,1,1]) translate([0,0,-6*a])
     cylinder(r=1.9,h=60,$fn=16,center=true); // axle

     // axle brace sleves... shorter on outside
     translate([0,0, 20*a]) cylinder(r=2.5,h=6 ,$fn=16,center=true);
     translate([0,0,-26*a]) cylinder(r=2.5,h=18,$fn=16,center=true);
  }

  translate([loX*a,loY,0]) {
     cube([3.8,3.8,217],center=true); // lower rails
     for(z=[-1,1]) translate([0,0,z*108])
       color([0,0,1,1]) cube([2.5,2.5,6],center=true); // lower rail pegs
  }
  translate([0,loY+3.8,a*103]) cube([2*loX+4,3.8,3.8],center=true);

  hull() for (b=[-1,1]) translate([ Bx*b, 0 ,71*a]) sphere(1); // arm guard bar
  //hull() for (b=[-1,1]) translate([loX*b,loY,71*a]) sphere(1); // outer foot bar
  for (b=[-1,1]) {
    hull() { // outer diagonal
      translate([ Bx*b, 0 ,70*a]) sphere(1);
      translate([loX*b,loY,70*a]) sphere(1);
    }
  }

  *hull() { // outer front diag
    translate([loX,loY,68*a]) sphere(1);
    translate([ Bx, 0 ,40*a]) sphere(1);
  }
  for(x=[-1,1]) {
     #hull() { // inner back trap
       translate([x*loX,loY,25*a]) sphere(1);
       translate([x*Bx, 0 , 5*a]) sphere(1);
     }
     hull() { // outer back
       translate([x*loX,loY,35*a]) sphere(1);
       translate([x*Bx , 0 ,60*a]) sphere(1);
     }
  }

  for (b=[-1,1]) { // outside diagonal brace
    hull() {
      translate([loX*b,loY,110*a]) sphere(1);
      translate([ Bx*b, 0 ,110*a]) sphere(1);
    }
  }
  hull() for(b=[-1,1]) translate([ Bx*b, 0 ,110*a]) sphere(1);

  *hull() { // center foot low diag
    translate([ loX,loY, 5*a]) sphere(1);
    translate([-loX,loY,30*a]) sphere(1);
  }
  *hull() {
    translate([-loX,loY,40*a]) sphere(1);
    translate([ loX,loY,70*a]) sphere(1);
  }
  *for (b=[-1,1]) hull() {  // outer low X
    translate([-loX*b,loY,130*a]) sphere(1);
    translate([ loX*b,loY, 70*a]) sphere(1);
  }

  // expanded mesh floor
  color([0,.2,.8,.2]) translate([0,loY+2,0]) cube([2*loX,1,130],center=true);

}

module mainBar() {
  cube([110,5,5],center=true);
  translate([0,Ay,0]) {
    cylinder(r=1.5,h=4,$fn=16,center=true);
    #cylinder(r=AC,h=2,$fn=36,center=true);
    //cylinder(r=AC+2,h=.4,$fn=36,center=true);
  }

}
module legProxy() scale([1,1,12]) {
  legProxy1();
  mirror([1,0,0]) legProxy1();
}

// measurements from drawing, center pixel 600,300, 4 pixels/cm
module legProxy1() {

  hull() {
    translate([0,3.32,0]) cylinder(r=17.5+2,h=1,$fn=36,center=true);
    translate([-250/4, 290/4,0]) node();
    translate([-200/4, 290/4,0]) node();
    translate([-360/4, 120/4,0]) node();
    translate([-500/4,-110/4,0]) node();
    translate([-430/4,-230/4,0]) node();
  }
  hull() {
    translate([-400/4,-220/4  ,0]) node();
    translate([-340/4,-370/4+2,0]) node();
    translate([ -90/4,-370/4+2,0]) node();
    translate([-140/4,-120/4  ,0]) node();
  }
}

module node() cylinder(r=2,h=1,$fn=9,center=true);

// config e
Ay=3.318;
AC=17.5;
Bx=53.83;

loY=-40;  // location of lower brace beams
loX= 20;

$fn=8;

for (a=[-1,1]) {
  %translate([0,0, 80*a]) legProxy();
  %translate([0,0,100*a]) legProxy();
  translate([0,0,90*a]) mainBar();
  translate([Bx*a,0,0]) cylinder(r=2.5,h=300,$fn=16,center=true); // main axle
  translate([-20*a,-40,0]) cube([2.5,2.5,300],center=true); // lower rails

  hull() for (b=[-1,1]) translate([ Bx*b, 0 ,70*a]) sphere(1); // arm guard bar
  hull() for (b=[-1,1]) translate([loX*b,loY,70*a]) sphere(1); // outer foot bar
  for (b=[-1,1]) {
    hull() { // outer diagonal
      translate([ Bx*b, 0 ,70*a]) sphere(1);
      translate([loX*b,loY,70*a]) sphere(1);
    }
    hull() { // inner support on outside trapaoid
      translate([  5*b, 0 ,70*a]) sphere(1);
      translate([loX*b,loY,70*a]) sphere(1);
    }
  }

  hull() { // center front trap
    translate([loX,loY, 2*a]) sphere(1);
    translate([ Bx, 0 ,25*a]) sphere(1);
  }
  hull() { // outer front diag
    translate([loX,loY,68*a]) sphere(1);
    translate([ Bx, 0 ,40*a]) sphere(1);
  }
  hull() { // inner back trap
    translate([-loX,loY,25*a]) sphere(1);
    translate([ -Bx, 0 , 5*a]) sphere(1);
  }
  hull() { // outer back
    translate([-loX,loY,35*a]) sphere(1);
    translate([ -Bx, 0 ,65*a]) sphere(1);
  }

  for (b=[-1,1]) { // outside diagonal brace
    hull() {
      translate([loX*b,loY,140*a]) sphere(1);
      translate([ Bx*b, 0 ,110*a]) sphere(1);
    }
    hull() {
      translate([ Bx*b, 0 ,140*a]) sphere(1);
      translate([loX*b,loY,110*a]) sphere(1);
    }
    hull() {
      translate([loX*b,loY,110*a]) sphere(1);
      translate([ Bx*b, 0 ,110*a]) sphere(1);
    }
  }
  hull() for(b=[-1,1]) translate([loX*b,loY,140*a]) sphere(1);
  hull() for(b=[-1,1]) translate([ Bx*b, 0 ,110*a]) sphere(1);

  hull() { // center foot low diag
    translate([ loX,loY, 5*a]) sphere(1);
    translate([-loX,loY,30*a]) sphere(1);
  }
  hull() {
    translate([-loX,loY,40*a]) sphere(1);
    translate([ loX,loY,70*a]) sphere(1);
  }
  for (b=[-1,1]) hull() {  // outer low X
    translate([-loX*b,loY,130*a]) sphere(1);
    translate([ loX*b,loY, 70*a]) sphere(1);
  }

}

module mainBar() {
  cube([110,5,5],center=true);
  translate([0,Ay,0]) {
    cylinder(r=1.5,h=4,$fn=16,center=true);
    #cylinder(r=AC,h=2,$fn=36,center=true);
    //cylinder(r=AC+2,h=.4,$fn=36,center=true);
  }

}
module legProxy() {

  legProxy1();
  mirror([1,0,0]) legProxy1();

}

// measurements from drawing, center pixel 600,300, 4 pixels/cm
module legProxy1() {

  hull() {
    translate([0,3.32,0]) cylinder(r=17.5+2,h=1,$fn=36,center=true);
    translate([-250/4, 290/4,0]) node();
    translate([-200/4, 290/4,0]) node();
    translate([-360/4, 120/4,0]) node();
    translate([-500/4,-110/4,0]) node();
    translate([-430/4,-230/4,0]) node();
  }
  hull() {
    translate([-400/4,-220/4  ,0]) node();
    translate([-340/4,-370/4+2,0]) node();
    translate([ -90/4,-370/4+2,0]) node();
    translate([-140/4,-120/4  ,0]) node();
  }
}

module node() cylinder(r=2,h=1,$fn=9,center=true);


completed first version of 5 part assembly

// config e
Ay=3.318;
AC=17.5;
Bx=53.83;

loY=-60;  // location of lower brace beams
loX= 10;

zBar=90;

$fn=8;

for (a=[-1,1]) {
  %translate([0,0,(zBar-10)*a]) legProxy();
  %translate([0,0,(zBar+10)*a]) legProxy();
  translate( [0,0, zBar    *a]) mainBar();
  translate([0,0,a*(zBar+20)]) rotate([0,90*(a+1),0]) outerCap();
}
basket();

module basket() {
  for(a=[-1,1]) {
    %translate([Bx*a,0,0]) cylinder(r=1,h=120,$fn=16,center=true); // main axle
    for (b=[-1,1]) translate([Bx*b,0,zBar*a]) {
       color([0,0,1,1]) translate([0,0,-6*a])
       cylinder(r=1.9,h=60,$fn=16,center=true); // axle

       // axle brace sleves
       translate([0,0,-26*a]) cylinder(r=2.5,h=18,$fn=16,center=true);
    }

    translate([loX*a,loY,0]) {
       color([0,0,1,1]) cube([2.5,2.5,230],center=true); // lower rails
    }

    hull() for (b=[-1,1]) translate([ Bx*b, 0 ,71*a]) sphere(1); // arm guard bar
    //hull() for (b=[-1,1]) translate([loX*b,loY,71*a]) sphere(1); // outer foot bar
    for (b=[-1,1]) {
      hull() { // outer diagonal
        translate([ Bx*b, 0 ,70*a]) sphere(1);
        translate([loX*b,loY,70*a]) sphere(1);
      }
    }

    *hull() { // outer front diag
      translate([loX,loY,68*a]) sphere(1);
      translate([ Bx, 0 ,40*a]) sphere(1);
    }
    for(x=[-1,1]) {
       #hull() { // inner back trap
         translate([x*loX,loY,25*a]) sphere(1);
         translate([x*Bx, 0 , 5*a]) sphere(1);
       }
       hull() { // outer back
         translate([x*loX,loY,35*a]) sphere(1);
         translate([x*Bx , 0 ,60*a]) sphere(1);
       }
    }

    *hull() { // center foot low diag
      translate([ loX,loY, 5*a]) sphere(1);
      translate([-loX,loY,30*a]) sphere(1);
    }
    *hull() {
      translate([-loX,loY,40*a]) sphere(1);
      translate([ loX,loY,70*a]) sphere(1);
    }
    *for (b=[-1,1]) hull() {  // outer low X
      translate([-loX*b,loY,130*a]) sphere(1);
      translate([ loX*b,loY, 70*a]) sphere(1);
    }

    // may do something more complicated for payload bay,
    // but for now, just stich sides together
    translate([a*(Bx+2),2,0]) cube([3.8,3.8,140],center=true);
  }

  // expanded mesh floor
  color([0,.2,.8,.2]) translate([0,loY+2,0]) cube([2*loX,1,130],center=true);
}

module mainBar() {
  cube([110,5,5],center=true);
  translate([0,Ay,0]) {
    cylinder(r=1.5,h=4,$fn=16,center=true);
    #cylinder(r=AC,h=2,$fn=36,center=true);
    //cylinder(r=AC+2,h=.4,$fn=36,center=true);
  }

  // lower support
  for(x=[-1,1]) {
     // lower rail tubes
     translate([x*loX,loY,0]) cube([3.8,3.8,10],center=true);

     hull() {     // diagonals
       translate([x*(loX+2),loY,0]) sphere(1);
       translate([x*(Bx-8),0,0]) sphere(1);
     }
  }
  translate([0,loY,0]) cube([2*loX,3.8,3.8],center=true);
}

module outerCap() {
  for (b=[-1,1]) translate([Bx*b,0,-1]) {
     // axle brace sleves... shorter on outside
     cylinder(r=2.5,h=6 ,$fn=16,center=true);
  }
  translate([0,loY,0]) cube([2*loX,3.8,3.8],center=true);
  for(x=[-1,1]) translate([x*loX,loY,1])
         cube([3.8,3.8,8],center=true); // lower rail sleves

  for (b=[-1,1]) hull() { // outside diagonal brace
    translate([loX*b,loY,0]) sphere(1);
    translate([ Bx*b, 0 ,0]) sphere(1);
  }
  hull() for(b=[-1,1]) translate([Bx*b,0,0]) sphere(1);
}

module legProxy() scale([1,1,12]) {
  legProxy1();
  mirror([1,0,0]) legProxy1();
}

// measurements from drawing, center pixel 600,300, 4 pixels/cm
module legProxy1() {

  hull() {
    translate([0,3.32,0]) cylinder(r=17.5+2,h=1,$fn=36,center=true);
    translate([-250/4, 290/4,0]) node();
    translate([-200/4, 290/4,0]) node();
    translate([-360/4, 120/4,0]) node();
    translate([-500/4,-110/4,0]) node();
    translate([-430/4,-230/4,0]) node();
  }
  hull() {
    translate([-400/4,-220/4  ,0]) node();
    translate([-340/4,-370/4+2,0]) node();
    translate([ -90/4,-370/4+2,0]) node();
    translate([-140/4,-120/4  ,0]) node();
  }
}

module node() cylinder(r=2,h=1,$fn=9,center=true);

// config e
Ay=3.318;
AC=17.5;
Bx=53.83;

loY=-60;  // location of lower brace beams
loX= 10;

zBar=90;

$fn=8;

for (a=[-1,1]) {
  %translate([0,0,(zBar-10)*a]) legProxy();
  %translate([0,0,(zBar+10)*a]) legProxy();
  translate( [0,0, zBar    *a]) mainBar();

  %translate([Bx*a,0,0]) cylinder(r=1,h=120,$fn=16,center=true); // main axle
  for (b=[-1,1]) translate([Bx*b,0,zBar*a]) {
     color([0,0,1,1]) translate([0,0,-6*a])
     cylinder(r=1.9,h=60,$fn=16,center=true); // axle

     // axle brace sleves... shorter on outside
     translate([0,0, 20*a]) cylinder(r=2.5,h=6 ,$fn=16,center=true);
     translate([0,0,-26*a]) cylinder(r=2.5,h=18,$fn=16,center=true);
  }

  translate([loX*a,loY,0]) {
     cube([3.8,3.8,217],center=true); // lower rails
     for(z=[-1,1]) translate([0,0,z*108])
       color([0,0,1,1]) cube([2.5,2.5,6],center=true); // lower rail pegs
  }
  translate([0,loY+3.8,a*103]) cube([2*loX+4,3.8,3.8],center=true);

  hull() for (b=[-1,1]) translate([ Bx*b, 0 ,71*a]) sphere(1); // arm guard bar
  //hull() for (b=[-1,1]) translate([loX*b,loY,71*a]) sphere(1); // outer foot bar
  for (b=[-1,1]) {
    hull() { // outer diagonal
      translate([ Bx*b, 0 ,70*a]) sphere(1);
      translate([loX*b,loY,70*a]) sphere(1);
    }
  }

  *hull() { // outer front diag
    translate([loX,loY,68*a]) sphere(1);
    translate([ Bx, 0 ,40*a]) sphere(1);
  }
  for(x=[-1,1]) {
     #hull() { // inner back trap
       translate([x*loX,loY,25*a]) sphere(1);
       translate([x*Bx, 0 , 5*a]) sphere(1);
     }
     hull() { // outer back
       translate([x*loX,loY,35*a]) sphere(1);
       translate([x*Bx , 0 ,60*a]) sphere(1);
     }
  }

  for (b=[-1,1]) { // outside diagonal brace
    hull() {
      translate([loX*b,loY,110*a]) sphere(1);
      translate([ Bx*b, 0 ,110*a]) sphere(1);
    }
  }
  hull() for(b=[-1,1]) translate([ Bx*b, 0 ,110*a]) sphere(1);

  *hull() { // center foot low diag
    translate([ loX,loY, 5*a]) sphere(1);
    translate([-loX,loY,30*a]) sphere(1);
  }
  *hull() {
    translate([-loX,loY,40*a]) sphere(1);
    translate([ loX,loY,70*a]) sphere(1);
  }
  *for (b=[-1,1]) hull() {  // outer low X
    translate([-loX*b,loY,130*a]) sphere(1);
    translate([ loX*b,loY, 70*a]) sphere(1);
  }

  // expanded mesh floor
  color([0,.2,.8,.2]) translate([0,loY+2,0]) cube([2*loX,1,130],center=true);

}

module mainBar() {
  cube([110,5,5],center=true);
  translate([0,Ay,0]) {
    cylinder(r=1.5,h=4,$fn=16,center=true);
    #cylinder(r=AC,h=2,$fn=36,center=true);
    //cylinder(r=AC+2,h=.4,$fn=36,center=true);
  }

}
module legProxy() scale([1,1,12]) {
  legProxy1();
  mirror([1,0,0]) legProxy1();
}

// measurements from drawing, center pixel 600,300, 4 pixels/cm
module legProxy1() {

  hull() {
    translate([0,3.32,0]) cylinder(r=17.5+2,h=1,$fn=36,center=true);
    translate([-250/4, 290/4,0]) node();
    translate([-200/4, 290/4,0]) node();
    translate([-360/4, 120/4,0]) node();
    translate([-500/4,-110/4,0]) node();
    translate([-430/4,-230/4,0]) node();
  }
  hull() {
    translate([-400/4,-220/4  ,0]) node();
    translate([-340/4,-370/4+2,0]) node();
    translate([ -90/4,-370/4+2,0]) node();
    translate([-140/4,-120/4  ,0]) node();
  }
}

module node() cylinder(r=2,h=1,$fn=9,center=true);


changes in library

changes in library

//Objects
module ring(r=5,d=1,h=2) {
	difference() {
		cylinder(r=r,h=h);
		cylinder(r=r-d,h=h);
	}
}
//Translations //expand for z axis
module tr_xy(x,y=0) {
	if(y==0) {
		for(i=[-1,1])for(j=[-1,1])translate([x*i,x*j])children();
	} else {
		for(i=[-1,1])for(j=[-1,1])translate([x*i,y*j])children();
	}
}
module rot_x(x) {
	for(i=[0:3])rotate(a=[0,0,90*i])translate([x,0])children();
}

module ring(r=5,d=1,h=2) {
	difference() {
		cylinder(r=r,h=h);
		cylinder(r=r-d,h=h);
	}
}
module tr_xy(x,y=0) {
	if(y==0) {
		for(i=[-1,1])for(j=[-1,1])translate([x*i,x*j])children();
	} else {
		for(i=[-1,1])for(j=[-1,1])translate([x*i,y*j])children();
	}
}
module rot_x(x) {
	for(i=[0:3])rotate(a=[0,0,90*i])translate([x,0])children();
}