Merge pull request #49 from AxTheB/master
[clinton/prusa3.git] / box_frame / inc / functions.scad
index c81554d..7b61a41 100644 (file)
@@ -32,21 +32,30 @@ module cylinder_poly(r, h, center=false){
 
 module fillet(radius, height=100, $fn=0) {
     //this creates acutal fillet
-    translate([-radius, -radius, -height/2-0.01])
-        difference() {
-            cube([radius*2, radius*2, height+0.02]);
-            cylinder(r=radius, h=height+0.02, $fn=$fn);
+    translate([-radius, -radius, -height / 2 - 0.02]) difference() {
+        cube([radius * 2, radius * 2, height + 0.04]);
+        if ($fn == 0 && (radius == 2 || radius == 3 || radius == 4)) {
+            cylinder(r=radius, h=height + 0.04, $fn=4 * radius);
+        } else {
+            cylinder(r=radius, h=height + 0.04, $fn=$fn);
         }
+
+    }
 }
 
 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 (center) {
-        cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
-    } else {
-        translate([size[0]/2, size[1]/2, size[2]/2])
+    if (use_fillets) {
+        if (center) {
             cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
+        } else {
+            translate([size[0]/2, size[1]/2, size[2]/2])
+                cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
+        }
+    } else {
+        cube(size, center);
     }
+
 }
 
 module cube_negative_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
@@ -89,7 +98,7 @@ module nema17(places=[1,1,1,1], size=15.5, h=10, holes=false, shadow=false, $fn=
         if (places[i] == 1) {
             rotate([0, 0, 90*i]) translate([size, size, 0]) {
                 if (holes) {
-                    #rotate([0, 0, -90*i])  translate([0,0,-10]) screw(r=1.7, slant=false, head_drop=13, $fn=$fn, h=h+12);
+                    rotate([0, 0, -90*i])  translate([0,0,-10]) screw(r=1.7, slant=false, head_drop=13, $fn=$fn, h=h+12);
                 } else {
                     rotate([0, 0, -90*i]) cylinder(h=h, r=5.5, $fn=$fn);
                 }
@@ -105,7 +114,7 @@ module nema17(places=[1,1,1,1], size=15.5, h=10, holes=false, shadow=false, $fn=
     }
 }
 
-module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=true, poly=false, $fn=0){
+module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=i_am_box, poly=false, $fn=0){
     //makes screw with head
     //for substraction as screw hole
     if (poly) {
@@ -122,5 +131,43 @@ module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=true, poly=false, $fn=0){
     }
 }
 
-//cube_fillet([10,20,30], vertical=[3,2,0,0], top=[3,2,0,5], bottom=[3,2,0,5]);
-//cube_fillet([10,20,30], radius=2, top=[7,2,7,2]);
+module plate_screw(long=0) {
+    if (i_am_box == 0) {
+        translate([0, 0, -long]) screw(head_drop=14 + long, h=20 + long, r_head=3.6, r=1.7, $fn=24, slant=false);
+    } else {
+        translate([0, 0, -2 - long]) screw(head_drop=14 + long, h=20 + 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);
+
+
+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 shadow
+    %cylinder(h = idler_bearing[1], r=idler_bearing[0]/2, 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. 
+    for (i = [0 : len / belt_tooth_distance]) {
+        translate([0, 0, i * belt_tooth_distance]) cube([2, 9, belt_tooth_distance * belt_tooth_ratio], center = true);
+    }
+}