Merge pull request #80 from AxTheB/master
[clinton/prusa3.git] / box_frame / inc / functions.scad
CommitLineData
2159eed1 1// PRUSA iteration3
d3618a65
NZ
2// Functions used in many files
3// GNU GPL v3
2159eed1
VAH
4// Josef Průša <josefprusa@me.com>
5// Václav 'ax' Hůla <axtheb@gmail.com>
4d2a954d 6// Vlnofka <>
d3618a65
NZ
7// http://www.reprap.org/wiki/Prusa_Mendel
8// http://github.com/prusajr/PrusaMendel
9
10
11module nut(d,h,horizontal=true){
c94c2662
VAH
12 cornerdiameter = (d / 2) / cos (180 / 6);
13 cylinder(h = h, r = cornerdiameter, $fn = 6);
14 if(horizontal){
15 for(i = [1:6]){
51fd106d 16 rotate([0,0,60*i]) translate([-cornerdiameter-0.2,0,0]) rotate([0,0,-45]) cube([2,2,h]);
c94c2662
VAH
17 }
18 }
d3618a65
NZ
19}
20
1280d035 21module fillet(radius, height=100, $fn=0) {
c94c2662 22 //this creates acutal fillet
8a18a8c6
VAH
23 translate([-radius, -radius, -height / 2 - 0.02]) difference() {
24 cube([radius * 2, radius * 2, height + 0.04]);
25 if ($fn == 0 && (radius == 2 || radius == 3 || radius == 4)) {
26 cylinder(r=radius, h=height + 0.04, $fn=4 * radius);
27 } else {
28 cylinder(r=radius, h=height + 0.04, $fn=$fn);
c94c2662 29 }
8a18a8c6
VAH
30
31 }
c94c2662
VAH
32}
33
c94c2662
VAH
34module cube_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], center=false, $fn=0){
35 //
4edfdf22 36 if (use_fillets == 1) {
c6265fc0 37 if (center) {
c94c2662 38 cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
c6265fc0
VAH
39 } else {
40 translate([size[0]/2, size[1]/2, size[2]/2])
41 cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
42 }
43 } else {
4edfdf22
VAH
44 if (use_fillets == 2) {
45 if (center) {
46 cube_fillet_inside(size, radius, vertical, top, bottom, 4);
47 } else {
48 translate([size[0]/2, size[1]/2, size[2]/2])
49 cube_fillet_inside(size, radius, vertical, top, bottom, 4);
50 }
51
52 } else {
53 cube(size, center);
54 }
c94c2662 55 }
c6265fc0 56
c94c2662
VAH
57}
58
59module cube_negative_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
60
61 j=[1,0,1,0];
d3618a65 62
c94c2662
VAH
63 for (i=[0:3]) {
64 if (radius > -1) {
65 rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(radius, size[2], $fn=$fn);
66 } else {
67 rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(vertical[i], size[2], $fn=$fn);
68 }
69 rotate([90*i, -90, 0]) translate([size[2]/2, size[j[i]]/2, 0 ]) fillet(top[i], size[1-j[i]], $fn=$fn);
70 rotate([90*(4-i), 90, 0]) translate([size[2]/2, size[j[i]]/2, 0]) fillet(bottom[i], size[1-j[i]], $fn=$fn);
71
72 }
73}
d3618a65 74
c94c2662
VAH
75module cube_fillet_inside(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
76 //makes CENTERED cube with round corners
77 // if you give it radius, it will fillet vertical corners.
78 //othervise use vertical, top, bottom arrays
79 //when viewed from top, it starts in upper right corner (+x,+y quadrant) , goes counterclockwise
1280d035 80 //top/bottom fillet starts in direction of Y axis and goes CCW too
c94c2662
VAH
81
82
83 if (radius == 0) {
84 cube(size, center=true);
85 } else {
86 difference() {
87 cube(size, center=true);
88 cube_negative_fillet(size, radius, vertical, top, bottom, $fn);
89 }
90 }
91}
92
93
0b2e9c87 94module nema17(places=[1,1,1,1], size=15.5, h=10, holes=false, shadow=false, $fn=24){
c94c2662 95 for (i=[0:3]) {
4bdd854d 96 if (places[i] == 1) {
c94c2662
VAH
97 rotate([0, 0, 90*i]) translate([size, size, 0]) {
98 if (holes) {
380e3cfb 99 rotate([0, 0, -90*i]) translate([0,0,-10]) screw(r=1.7, slant=false, head_drop=13, $fn=$fn, h=h+12);
c94c2662
VAH
100 } else {
101 rotate([0, 0, -90*i]) cylinder(h=h, r=5.5, $fn=$fn);
102 }
103 }
104 }
105 }
86222e6a 106 if (shadow != false) {
51fd106d 107 %translate ([0, 0, shadow+21+3]) cube([42,42,42], center = true);
1280d035 108 //flange
28c8b084 109 %translate ([0, 0, shadow+21+3-21-1]) cylinder(r=11,h=2, center = true, $fn=20);
1280d035 110 //shaft
28c8b084 111 %translate ([0, 0, shadow+21+3-21-7]) cylinder(r=2.5,h=14, center = true);
c94c2662
VAH
112 }
113}
114
fdc7f8d6 115module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=i_am_box, poly=false, $fn=0){
c94c2662
VAH
116 //makes screw with head
117 //for substraction as screw hole
118 if (poly) {
119 cylinder_poly(h=h, r=r, $fn=$fn);
120 } else {
121 cylinder(h=h, r=r, $fn=$fn);
122 }
123 if (slant) {
124 translate([0, 0, head_drop-0.01]) cylinder(h=r_head, r2=0, r1=r_head, $fn=$fn);
125 }
126
127 if (head_drop > 0) {
128 translate([0, 0, -0.01]) cylinder(h=head_drop+0.01, r=r_head, $fn=$fn);
129 }
130}
d3618a65 131
01b10514 132module plate_screw(long=0) {
0f6ec51a 133 if (i_am_box == 0) {
8ec81421 134 translate([0, 0, -long]) screw(head_drop=14 + long, h=30 + long, r_head=3.6, r=1.7, $fn=24, slant=false);
0f6ec51a 135 } else {
8ec81421 136 translate([0, 0, -2 - long]) screw(head_drop=14 + long, h=30 + long, r_head=4.5, r=2, $fn=24, slant=true);
0f6ec51a
VAH
137 }
138}
139
690004c7 140//radius of the idler assembly (to surface that touches belt, ignoring guide walls)
4e1cf096
VAH
141function idler_assy_r_inner(idler_bearing) = (idler_bearing[0] / 2) + (6 * single_wall_width + 0.2) * idler_bearing[3];
142//outer radius of the idler assembly (to smooth side of belt)
143function idler_assy_r_outer(idler_bearing) = idler_assy_r_inner(idler_bearing) + belt_thickness + 1;
690004c7
VAH
144
145
146module idler_assy(idler_bearing = [22, 7, 8, 1]) {
147
815fe4ec 148 //bearing axle
1f623fc7 149 translate([0,0,-1]) cylinder(h = 120, r=(idler_bearing[2] + 1) / 2, $fn=small_hole_segments, center=true);
690004c7
VAH
150 //bearing shadow
151 %cylinder(h = idler_bearing[1], r=idler_bearing[0]/2, center=true);
4e1cf096 152 //belt shadow
815fe4ec 153 %cylinder(h = belt_width, r=idler_assy_r_outer(idler_bearing), center=true);
690004c7 154
6229a141 155 cylinder(h = idler_width + 1, r=idler_assy_r_outer(idler_bearing) + 0.5, center=true);
690004c7 156}
44a1d22f 157
875ab7f7
VAH
158module belt(len, side = 0){
159 //belt. To be substracted from model
160 //len is in +Z, smooth side in +X, Y centered
161 translate([-0.5, 0, 0]) maketeeth(len);
01b10514 162 translate([0, -4.5, -0.01]) cube([belt_thickness, 9, len + 0.02]);
875ab7f7 163 if (side != 0) {
01b10514 164 translate([0, -4.5 + side, -0.01]) cube_fillet([belt_thickness, 9, len + 0.02], vertical = [3, 0, 0, 0]);
875ab7f7
VAH
165 }
166}
167
168
44a1d22f 169module maketeeth(len){
875ab7f7 170 //Belt teeth.
44a1d22f 171 for (i = [0 : len / belt_tooth_distance]) {
01b10514 172 translate([0, 0, i * belt_tooth_distance]) cube([2, 9, belt_tooth_distance * belt_tooth_ratio], center = true);
44a1d22f
VAH
173 }
174}