-
Notifications
You must be signed in to change notification settings - Fork 4
/
PeristalticPump.jscad
328 lines (271 loc) · 16.2 KB
/
PeristalticPump.jscad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
Parameterizeable peristaltic pump
If you think this code was useful BTC
contributions are welcome at
19sKN38N4yxWZXoZeAdXZb5rq9xk32aDP4
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
include('/mechanics/stepper28byj_48.jscad');
include('/mechanics/isothread.jscad');
function getParameterDefinitions() {
return [
{ name : 'pipeod', title : 'Pipe outer diameter', type : 'float', default : 6 },
{ name : 'pipeid', title : 'Pipe inner diameter', type : 'float', default : 4 },
{ name : 'squeezeStretch', title : 'Additional squeeze space stretching', type : 'float', default : 1 },
{ name : 'rollerOD', title : 'Roller outer diameter', type : 'float', default : 22 },
{ name : 'rollerID', title : 'Roller inner diameter', type : 'float', default : 6 },
{ name : 'rollerH', title : 'Roller height', type : 'float', default : 7 },
{ name : 'rollerScrewMetric', title : 'Roller screw metric (Mx)', type : 'int', default : 8 },
{ name : 'rollerWallContact', title: 'Roller contact wall (only inside correction)', type : 'checkbox', checked : true },
{ name : 'washerThickness', title : 'Washer thickness', type : 'float', default : 1 },
{ name : 'rotorDiameter', type : 'float', default : 50 },
{ name : 'nBearings' , type : 'int', default : 2},
{ name : 'nDivisions', type : 'int', default : 3 },
{ name : 'minWallThickness', type : 'float', default : 1 },
{ name : 'cableGrooveDepth', type : 'float', default : 2 },
{ name : 'cableGrooveWidth', type : 'float', default : 5 },
{ name : 'cableHoleWidth', type : 'float', default : 5 },
{ name : 'cableHoleHeight', type : 'float', default : 2 },
{ name : 'enableRotor', title : 'Enable rotor model', type : 'checkbox', checked : true },
{ name : 'enableStator1', title : 'Enable stator top model', type : 'checkbox', checked : true },
{ name : 'enableStator2', title : 'Enable stator bottom model', type : 'checkbox', checked : true },
{ name : 'setCutModelStato1', title : 'Display cut model of stator 1', type : 'checkbox', checked : false },
{ name : 'viewStepper', title : 'View stepper motor model', type : 'checkbox', checked : false },
{ name : 'viewBearings', title : 'View bearings', type : 'checkbox', checked : false },
{ name : 'scale', type : 'float', default : 1.0 },
{ name : 'fn', type : 'int', default : 32 },
{ name : 'correctionInsideDiameter', type : 'float', default : 0 },
{ name : 'correctionOutsideDiameter', type : 'float', default : 0 }
]
}
function rotor(params) {
var pipeod = params['pipeod'];
var pipeid = params['pipeid'];
var rollerod = params['rollerOD'];
var rollerid = params['rollerID'];
var rollerheight = params['rollerH'];
var rollerScrewMetric = params['rollerScrewMetric'];
var squeezeStretch = params['squeezeStretch'];
var rotorDiameter = params['rotorDiameter'];
var minWallThickness = params['minWallThickness'];
var ndivisions = params['nDivisions'];
var nbearingsstacked = params['nBearings'];
var washerThickness = params['washerThickness'];
var rotorHeight = 2 * minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'];
var fnSteps = params['fn'];
if(pipeod <= pipeid) { alert("Pipe outer or inner diameter invalid. Using defaults (6/4)"); pipeod = 6; pipeid = 4; }
if(rollerod <= rollerid) { alert("Roller inner or outer diameter invalid. Using defaults (22/8)"); rollerod = 22; rollerid = 8; }
var diameterPipe = (pipeod - pipeid) / 2.0;
var minPipeThickness = (2*diameterPipe);
var minSpacingAndInset = minPipeThickness/2.0;
var rollerExpose = (pipeod - minSpacingAndInset) * squeezeStretch;
var rollerOffset = rotorDiameter/2 - (rollerod/2 - rollerExpose);
if((rollerod/2 - rollerExpose - rollerid/2) < minWallThickness) { alert("Warning: Cannot guarantee minimum wall thickness"); }
if((rollerod/2 - rollerExpose - rollerid/2) < 0) { alert("Cannot realize design"); return; }
var printer = params;
/*
Generate array of ball bearings
*/
var ballbearings = [];
var bearingCutTool = [];
for(var anglestep = 0; anglestep < ndivisions; anglestep++) {
for(var bearingstep = 0; bearingstep < nbearingsstacked; bearingstep++) {
ballbearings.push(
difference(
cylinder({d : rollerod + params['correctionInsideDiameter'], h : rollerheight, center : true, fn : fnSteps}),
cylinder({d : rollerid - params['correctionInsideDiameter'], h : rollerheight, center : true, fn : fnSteps})
).translate([rollerOffset,0,rollerheight/2 + rollerheight * bearingstep - (nbearingsstacked * rollerheight)/2]).rotateZ(360 / ndivisions * anglestep).setColor([1,0,0])
);
}
bearingCutTool.push(
union(
cube({ size : [ rollerod + params['correctionInsideDiameter'], rollerod + params['correctionInsideDiameter'], rollerheight * nbearingsstacked + 2 * washerThickness + params['correctionInsideDiameter'] ], center : true }).translate([rollerOffset + rollerod/2,0,0]).rotateZ(360 / ndivisions * anglestep),
cylinder({ d : rollerod + params['correctionInsideDiameter'], h : rollerheight * nbearingsstacked + 2 * washerThickness + params['correctionInsideDiameter'], center : true, fn : fnSteps }).translate([rollerOffset,0,0]).rotateZ(360 / ndivisions * anglestep)
)
);
}
/*
Generate roller
*/
var nutTpl = new window.jscad.tspi.isoNut(params, { m : rollerScrewMetric });
var roller = difference(
cylinder({ h : nutTpl.getHeight() + 2 * minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'], d : rotorDiameter, center : true, fn : fnSteps }).translate([0,0,-nutTpl.getHeight()/2]),
union(bearingCutTool)
);
var nutcut = [];
var screwcut = [];
for(var anglestep = 0; anglestep < ndivisions; anglestep++) {
nutcut.push(nutTpl.getModel().translate([rollerOffset,0,-nutTpl.getHeight()/2 - (rollerheight * nbearingsstacked)/2 - washerThickness - minWallThickness - params['correctionInsideDiameter']/2]).rotateZ(360 / ndivisions * anglestep).setColor([0,0,1]));
nutcut.push(cylinder({ r : nutTpl.getRadiusThreadCore()/2, h : nutTpl.getHeight(), center : true, fn : fnSteps }).translate([rollerOffset,0,-nutTpl.getHeight()/2 - (rollerheight * nbearingsstacked)/2 - washerThickness - minWallThickness - params['correctionInsideDiameter']/2]).rotateZ(360 / ndivisions * anglestep).setColor([0,0,1]));
screwcut.push(cylinder({d : nutTpl.getThroughholeCoarse(), h : nutTpl.getHeight() + 2*minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'], fn : fnSteps}).translate([rollerOffset,0,-nutTpl.getHeight()/2 - (rollerheight * nbearingsstacked)/2 - washerThickness - minWallThickness - params['correctionInsideDiameter']/2]).rotateZ(360 / ndivisions * anglestep).setColor([0,0,1]));
}
roller = difference(
roller,
union(nutcut)
);
roller = difference(
roller,
union(screwcut)
);
if(params['viewBearings']) {
roller = union(
roller,
union(ballbearings)
);
}
var stepper = new window.jscad.tspi.mechanics.stepper28BYJ_48(printer, {});
var roller = difference(
roller.translate([0,0,nutTpl.getHeight()]),
stepper.getModel().translate([0,0,-rotorHeight/2-1.5]).scale(1.01)
);
if(params['viewStepper']) {
roller = union(roller, stepper.getModel().translate([0,0,-rotorHeight/2-1.5]));
}
return roller;
}
function stator01(params) {
var pipeod = params['pipeod'];
var pipeid = params['pipeid'];
var rollerod = params['rollerOD'];
var rollerid = params['rollerID'];
var rollerheight = params['rollerH'];
var rollerScrewMetric = params['rollerScrewMetric'];
var squeezeStretch = params['squeezeStretch'];
var rotorDiameter = params['rotorDiameter'];
var minWallThickness = params['minWallThickness'];
var ndivisions = params['nDivisions'];
var nbearingsstacked = params['nBearings'];
var washerThickness = params['washerThickness'];
var rotorHeight = 2 * minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'];
var fnSteps = params['fn'];
if(pipeod <= pipeid) { alert("Pipe outer or inner diameter invalid. Using defaults (6/4)"); pipeod = 6; pipeid = 4; }
if(rollerod <= rollerid) { alert("Roller inner or outer diameter invalid. Using defaults (22/8)"); rollerod = 22; rollerid = 8; }
var diameterPipe = (pipeod - pipeid) / 2.0;
var pipeFlatWidth = pipeod * 3.15 / 2.0;
var minPipeThickness = (2*diameterPipe);
var minSpacingAndInset = minPipeThickness/2.0;
var rollerExpose = (pipeod - minSpacingAndInset) * squeezeStretch;
var rollerOffset = rotorDiameter/2 - (rollerod/2 - rollerExpose);
var mainBlockSizeA = rotorDiameter + 2 * minWallThickness + 2*rollerExpose + 4*minSpacingAndInset;
var mainBlockSizeB = rotorDiameter + 2 * minWallThickness + 2*rollerExpose + 4*minSpacingAndInset;
if((rollerod/2 - rollerExpose - rollerid/2) < minWallThickness) { alert("Warning: Cannot guarantee minimum wall thickness"); }
if((rollerod/2 - rollerExpose - rollerid/2) < 0) { alert("Cannot realize design"); return; }
var nutTpl = new window.jscad.tspi.isoNut(params, { m : rollerScrewMetric });
var rotorHeightReal = nutTpl.getHeight() + 2 * minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'];
// Space in which the rallers roll
var basisBlock = cube({ size : [ mainBlockSizeA, mainBlockSizeB, rotorHeightReal + nutTpl.getHeight()/2], center : true }).translate([0,0,-nutTpl.getHeight()/2]);
if(!(params['rollerWallContact'])) {
basisBlock = difference(
basisBlock,
cylinder({ d : rotorDiameter + params['correctionInsideDiameter'] + 2*rollerExpose + 2*minSpacingAndInset, h : rotorHeightReal + nutTpl.getHeight() + 0.5, center : true, fn : fnSteps }).translate([0,0,-0.5]) // Constant: 0.5 is spacing between rotor and stator at bottom ...
);
} else {
basisBlock = difference(
basisBlock,
cylinder({ d : rotorDiameter + params['correctionInsideDiameter'] + 2*rollerExpose, h : rotorHeightReal + nutTpl.getHeight() + 0.5, center : true, fn : fnSteps }).translate([0,0,-0.5]) // Constant: 0.5 is spacing between rotor and stator at bottom ...
);
}
// Groove in which the pipe is squeezed
var pipeFlatDiameter = rotorDiameter + params['correctionInsideDiameter'] + 2*rollerExpose + 4*minSpacingAndInset;
basisBlock = difference(
basisBlock,
cylinder({ d : pipeFlatDiameter, h : pipeFlatWidth, center : true, fn : fnSteps})
);
// Feed holes for pipe
var pipeCut = cylinder({ d : pipeod + params['correctionInsideDiameter'], h : mainBlockSizeA/2, center : true}).rotateY(90);
basisBlock = difference(
basisBlock,
pipeCut.translate([mainBlockSizeA/4, pipeFlatDiameter/2 - (pipeod+params['correctionInsideDiameter'])/2, 0]).rotateZ(-90)
);
basisBlock = difference(
basisBlock,
pipeCut.translate([mainBlockSizeA/4, -1 * (pipeFlatDiameter/2 - (pipeod+params['correctionInsideDiameter'])/2), 0]).rotateZ(-90)
);
// Rendering a cut model to illustrate goove layout:
if(params['setCutModelStato1']) {
basisBlock = difference(
basisBlock.translate([0,0,0]),
cube({ size : [ 100, 100, 100 ]}).translate([0,0,-50])
);
}
basisBlock = basisBlock.translate([0,0,nutTpl.getHeight()]);
var stepper = new window.jscad.tspi.mechanics.stepper28BYJ_48(params, {});
basisBlock = difference(
basisBlock,
stepper.getModel().translate([0,0,-rotorHeight/2-1.5]).scale(1.01)
);
return basisBlock;
}
function stator02(params) {
var pipeod = params['pipeod'];
var pipeid = params['pipeid'];
var rotorDiameter = params['rotorDiameter'];
var minWallThickness = params['minWallThickness'];
var squeezeStretch = params['squeezeStretch'];
var nbearingsstacked = params['nBearings'];
var washerThickness = params['washerThickness'];
var rollerheight = params['rollerH'];
var rollerScrewMetric = params['rollerScrewMetric'];
var cableGrooveDepth = params['cableGrooveDepth'];
var cableGrooveWidth = params['cableGrooveWidth'];
var diameterPipe = (pipeod - pipeid) / 2.0;
var minPipeThickness = (2*diameterPipe);
var minSpacingAndInset = minPipeThickness/2.0;
var rollerExpose = (pipeod - minSpacingAndInset) * squeezeStretch;
var rotorHeight = 2 * minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'];
var mainBlockSizeA = rotorDiameter + 2 * minWallThickness + 2*rollerExpose + 4*minSpacingAndInset;
var mainBlockSizeB = rotorDiameter + 2 * minWallThickness + 2*rollerExpose + 4*minSpacingAndInset;
var nutTpl = new window.jscad.tspi.isoNut(params, { m : rollerScrewMetric });
var rotorHeightReal = nutTpl.getHeight() + 2 * minWallThickness + rollerheight * nbearingsstacked + 2*washerThickness + params['correctionInsideDiameter'];
var stepper = new window.jscad.tspi.mechanics.stepper28BYJ_48(params, {});
var stepperHeight = 19;
var cHeight = (19 + minWallThickness)*1.01;
var block = cube({size : [ mainBlockSizeA, mainBlockSizeB, cHeight+cableGrooveDepth+2], center : true}).translate([0, 0, (-1*(rotorHeightReal + nutTpl.getHeight()/2)/2 + nutTpl.getHeight()/2) - cHeight/2.0 - cableGrooveDepth]);
block = difference(block, stepper.getModel().translate([0,0,-rotorHeight/2-1.5]).scale(1.01));
// Electronics pocket
block = difference(block, cube({ size : [ mainBlockSizeA - 2 * minWallThickness, mainBlockSizeB/2 - 2 * minWallThickness, cHeight - minWallThickness], center : true }).translate([0, mainBlockSizeB/4 - minWallThickness, (-1*(rotorHeightReal + nutTpl.getHeight()/2)/2 + nutTpl.getHeight()/2) - cHeight/2.0 + minWallThickness]));
// Cable groove
var grooveLength = mainBlockSizeA - 2 * minWallThickness;
var grooveWidth = cableGrooveWidth;
block = difference(block, cube({ size : [grooveWidth, grooveLength, cableGrooveDepth+5], center : false }).translate([-grooveWidth/2, -grooveLength/2, (-1*(rotorHeightReal + nutTpl.getHeight()/2)/2 + nutTpl.getHeight()/2) - cHeight - cableGrooveDepth/4]));
// Cable hole
var holeLength = params['cableHoleWidth'];
var holeHeight = params['cableHoleHeight'];
block = difference(block, cube(( { size : [holeLength, 2*minWallThickness, holeHeight]})).translate([-holeLength/2, mainBlockSizeB/2 - 2*minWallThickness, (-1*(rotorHeightReal + nutTpl.getHeight()/2)/2 + nutTpl.getHeight()/2) - cHeight - cableGrooveDepth/4]).setColor([0,1,0]));
if(params['viewStepper']) {
block = union(block, stepper.getModel().translate([0,0,-rotorHeight/2-1.5]));
}
return block;
}
function main(params) {
var parts = [];
if(params['enableRotor']) { parts.push(rotor(params)); }
if(params['enableStator1']) { parts.push(stator01(params)); }
if(params['enableStator2']) { parts.push(stator02(params)); }
return union(parts);
/* union(
stator01(params),
rotor(params)
); */
}