include <library/box.scad>

$fn = 100;



smallLenght = 10; 
smallWidth = 10;
wall =2;
circleDia = 27;

//assembly();

module assembly()
{
    fixation();
    translate([18+5,0,-(50-5)])rotate([0,90,0])arm(); 
    translate([10/2+wall,-10,-(100-10)])rotate([-45,90,0])attachment(); 

}



module fixation()
{
    lenght = 20; 
    width = 20;
    height = 10;
     
    exRay = 0; 
    inRay = 2; 

    difference()
    {
        union()
        {
            keyCubeEmpty(lenght,width,height,wall,exRay,inRay,tFlat = true, Iflat = true, ce = true);
            translate([lenght/2+smallLenght/2-wall,0,0])keyCubeEmpty(smallLenght,smallWidth,height,wall,exRay,0,tFlat = true, Iflat = true, ce = true);
        }
        
        rotate([0,0,90])translate([-(smallLenght-wall*2)/2,-width/2,-height/2+wall])cube([smallWidth-wall*2,wall,height-wall]);

        translate([lenght/2+smallLenght-wall*2,0,0])rotate([0,90,0])cylinder(d=2.8,h=wall);
        translate([0,0,-height/2])cylinder(d=3.1,h=wall);
        translate([-(smallWidth-wall*2)/2,width/2-wall,-height/2+wall])rotate([0,0,0])cube([smallWidth-wall*2,wall,height-wall]);
        translate([-(smallWidth-wall*2)/2,-width/2,-height/2+wall])rotate([0,0,0])cube([smallWidth-wall*2,wall,height-wall]);
    }
}

//arm();
module arm() 
{
    lenght = 100; 
    width = smallWidth;
    height = 10;
    wall =2; 
    exRay = 0; 
    inRay = 2; 

    smallLenght = 10; 
    smallWidth = 10;
    difference()
    {
        keyCubeEmpty(lenght,width,height,wall,exRay,inRay,tFlat = true, Iflat = true, ce = true);
        translate([lenght/2 - width/2,0,-height/2+wall/2])cylinder(d = 3.1, h=wall, center = true); 
        translate([-(lenght/2 - width/2),0,-height/2+wall/2])cylinder(d = 3.1, h=wall, center = true); 
        translate([-(lenght/2 - wall/2),0,height/2-2.5])cube([wall*2,5,height/2],center = true); 
        translate([(lenght/2 - wall/2),0,height/2-2.5])cube([wall*2,5,height/2],center = true);
    }
}

attachment(); 
module attachment()
{
    baseHeight = 10;
    cylinder(d=circleDia, h=wall, center= true); 
    
    difference()
    {
        union()
        {
            translate([0,0,wall/2+baseHeight/2])cube([smallLenght,smallWidth,baseHeight],center = true); 
            translate([smallWidth/2,-smallWidth/2,smallLenght+wall/2])rotate([0,-90,0])linear_extrude(smallWidth)polygon(points=[[0,0],[0,smallLenght],[smallWidth,smallWidth]]); 
        }
        translate([0,-2.8/tan(45),smallLenght/2+smallLenght])rotate([45,0,0])cylinder(d=2.8, h= smallLenght*2, center = true); 
        translate([-smallWidth/2,smallWidth/2-smallWidth/2, smallWidth+smallWidth/2+1])cube([smallWidth,smallWidth,smallWidth]); 
    }
}