Merge branch 'master' of git://github.com/Thav/Prusa3 into Thav-master
[clinton/prusa3.git] / box_frame / inc / functions.scad
index 262f448..bdf217f 100644 (file)
@@ -5,7 +5,7 @@
 // Václav 'ax' Hůla <axtheb@gmail.com>
 // Vlnofka <>
 // http://www.reprap.org/wiki/Prusa_Mendel
-// http://github.com/prusajr/PrusaMendel
+// http://github.com/josefprusa/Prusa3
 
 
 module nut(d,h,horizontal=true){
@@ -18,18 +18,6 @@ module nut(d,h,horizontal=true){
     }
 }
 
-// Based on nophead research
-module polyhole(d, h, center=false) {
-    n = max(round(2 * d),3);
-    rotate([0,0,180])
-        cylinder(h = h, r = (d / 2) / cos (180 / n), $fn = n);
-}
-
-// make it interchangeable between this and cylinder
-module cylinder_poly(r, h, center=false){
-    polyhole(d=r*2, h=h, center=center);
-}
-
 module fillet(radius, height=100, $fn=0) {
     //this creates acutal fillet
     translate([-radius, -radius, -height / 2 - 0.02]) difference() {
@@ -45,7 +33,7 @@ module fillet(radius, height=100, $fn=0) {
 
 module cube_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], center=false, $fn=0){
     //
-    if (use_fillets) {
+    if (use_fillets == 1) {
         if (center) {
             cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
         } else {
@@ -53,7 +41,17 @@ module cube_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0
                 cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
         }
     } else {
-        cube(size, center);
+        if (use_fillets == 2) {
+            if (center) {
+                cube_fillet_inside(size, radius, vertical, top, bottom, 4);
+            } else {
+                translate([size[0]/2, size[1]/2, size[2]/2])
+                    cube_fillet_inside(size, radius, vertical, top, bottom, 4);
+            }
+
+        } else {
+            cube(size, center);
+        }
     }
 
 }
@@ -131,32 +129,46 @@ module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=i_am_box, poly=false, $fn
     }
 }
 
-module plate_screw() {
+module plate_screw(long=0) {
     if (i_am_box == 0) {
-        screw(head_drop=14, h=20, r_head=3.6, r=1.7, $fn=24, slant=false);
+        translate([0, 0, -long]) screw(head_drop=14 + long, h=30 + long, r_head=3.6, r=1.7, $fn=24, slant=false);
     } else {
-        translate([0, 0, -2]) screw(head_drop=14, h=20, r_head=4.5, r=2, $fn=24, slant=true);
+        translate([0, 0, -2 - long]) screw(head_drop=14 + long, h=30 + long, r_head=4.5, r=2, $fn=24, slant=true);
     }
 }
 
 //radius of the idler assembly (to surface that touches belt, ignoring guide walls)
-function idler_assy_r_inner(idler_bearing) = (idler_bearing[0] / 2) + 4 * single_wall_width * idler_bearing[3];
-//radius of the idler assembly (to smooth side of belt)
-function idler_assy_r_outer(idler_bearing) = (idler_bearing[0] / 2) + (idler_bearing[3] ? (5.5 * idler_bearing[3]) : 3);
+function idler_assy_r_inner(idler_bearing) = (idler_bearing[0] / 2) + (6 * single_wall_width + 0.2) * idler_bearing[3];
+//outer radius of the idler assembly (to smooth side of belt) 
+function idler_assy_r_outer(idler_bearing) = idler_assy_r_inner(idler_bearing) + belt_thickness + 1;
 
 
 module idler_assy(idler_bearing = [22, 7, 8, 1]) {
 
-    translate([0,0,-1]) cylinder(h = 120, r=(idler_bearing[2] + 1) / 2, $fn=7, center=true);
+    //bearing axle
+    translate([0,0,-1]) cylinder(h = 120, r=(idler_bearing[2] + 1) / 2, $fn=small_hole_segments, center=true);
     //bearing shadow
     %cylinder(h = idler_bearing[1], r=idler_bearing[0]/2, center=true);
+    //belt shadow
+    %cylinder(h = belt_width, r=idler_assy_r_outer(idler_bearing), center=true);
 
     cylinder(h = idler_width + 1, r=idler_assy_r_outer(idler_bearing) + 0.5, center=true);
 }
 
+module belt(len, side = 0){
+    //belt. To be substracted from model
+    //len is in +Z, smooth side in +X, Y centered
+    translate([-0.5, 0, 0]) maketeeth(len);
+    translate([0, -4.5, -0.01]) cube([belt_thickness, 9, len + 0.02]);
+    if (side != 0) {
+    translate([0, -4.5 + side, -0.01]) cube_fillet([belt_thickness, 9, len + 0.02], vertical = [3, 0, 0, 0]);
+    }
+}
+
+
 module maketeeth(len){
-    //Belt teeth. To be substracted from model
+    //Belt teeth. 
     for (i = [0 : len / belt_tooth_distance]) {
-        translate([0, 0, i * belt_tooth_distance]) cube([2, 10, belt_tooth_distance * belt_tooth_ratio], center = true);
+        translate([0, 0, i * belt_tooth_distance]) cube([2, 9, belt_tooth_distance * belt_tooth_ratio], center = true);
     }
 }