chiark / gitweb /
1fd250792f279fff5521260f7f559371137c7862
[reprap-play.git] / powerbank-bike-clamp.scad
1 // -*- C -*-
2
3 // Print one of each:
4 //    Main
5 //    TubeClampRight
6
7 include <utils.scad>
8
9 tube_dia = 22.4;
10
11 hinge_around = 2.5;
12 hinge_pin = 1.8 + 0.75;
13 main_th = 3;
14 minor_wall_min = 1;
15
16 screw = 5.0 + 0.75;
17 screw_head = 8.7 + 1.2;
18 screw_head_space_above = 10;
19 screw_nut_across = 7.9 + 0.75;
20 screw_nut_th = 3.9 + 0.75;
21
22 knob_behind_across = 12.2 + 0.75;
23 behind_knob_th = 5;
24 knob_standout_h = 2;
25
26 clamp_min_width = 20;
27
28 clamp_gap = 2;
29
30 lower_th = 1;
31
32 overlap_l = 0.1;
33
34 bridge_slop = 1.2;
35
36 hinge_lobe_per = 10;
37 hinge_gap_z = 0.75;
38 hinge_gap_xy = 0.75;
39
40 $fs = 0.1;
41 $fa = 5;
42
43 bank_eps_bbox_x = [149, 598];
44 bank_eps_bbox_y = [274, 1452];
45
46 bank_y_sz = 102.25 + 0.50 + 3.2;
47 bank_x_sz = (26.0 + 0.5);
48 bank_recess_y = 5;
49
50 strap_th = 3;
51 strap_w = 5;
52 strap_above = 2.5;
53
54 strap_around_over = 1.0;
55 strap_around_attach = 2.0;
56
57 retainer_walls = [18, 30];
58
59 bank_profile_scale_bodge = 1.0;
60
61 bank_output_ctr = [ 12.5, 11.5 ]; // from nearest corner
62 bank_output_sz  = [ 11.0, 10.5 ];
63
64 mounted_pos_y_offset_lim = -100;
65
66 liner_th = 0.8;
67
68 brace_r = 5;
69 brace_len = 50;
70
71 straps_y_adj = [ 3.5,
72                  0,
73                  0 ];
74
75 // calculated
76
77 straps_y = [ -bank_y_sz * 0.25, // these entries are special and used
78              +bank_y_sz * 0.25, //  for the brace struts
79              0 ];
80
81 screw_head_behind = main_th;
82 endwall_th = main_th;
83
84 bank_recess_dx = minor_wall_min;
85
86 pspt_to_mm = 25.4 / 72;
87
88 main_r = tube_dia/2 + main_th;
89
90 screw_max_y_lhs = -main_r -screw_nut_across/2;
91 screw_max_y_rhs = -main_r -knob_behind_across/2;
92
93 screw_y = min(screw_max_y_lhs,
94               screw_max_y_rhs);
95
96 bot_y = screw_y -max( screw_nut_across/2, knob_behind_across/2 )
97   -minor_wall_min;
98
99 holder_x_sz = bank_x_sz + bank_recess_dx*2;
100 bank_bot_y = strap_above + strap_th;
101 strap_r = strap_th;
102
103 brace_total_len = brace_len + main_th;
104 brace_ctrs_y_nom = [ straps_y[0] - (brace_r + strap_w/2),
105                      straps_y[1] + (brace_r + strap_w/2) ];
106
107 brace_ctrs_y = [ (straps_y + straps_y_adj)[0] + (brace_r + strap_w/2),
108                  (straps_y + straps_y_adj)[1] + (brace_r + strap_w/2) ];
109
110 clamp_width_actual = max(clamp_min_width, holder_x_sz);
111
112 hinge_lobes = floor(clamp_width_actual / hinge_lobe_per);
113 hinge_stride = (clamp_width_actual + hinge_gap_z) / hinge_lobes;
114
115 hinge_outer_r = hinge_around + hinge_pin/2;
116 hinge_y = tube_dia/2 + hinge_outer_r;
117
118 top_cnr_r = min(endwall_th, main_th);
119
120 mounted_pos_y_offset = max(mounted_pos_y_offset_lim,
121                            bot_y - (-(bank_y_sz/2 + endwall_th)));
122
123
124 module TubePlan(){ circle(r = tube_dia/2); }
125 module HingePinPlan(){ translate([0, hinge_y]) circle(r= hinge_pin/2); }
126 module HingeBodyPlan(){ translate([0, hinge_y]) circle(r= hinge_outer_r); }
127
128 module TubeClampLeftPlan(){
129   difference(){
130     union(){
131       polygon([[ 0,                      hinge_y + hinge_outer_r ],
132                [ -(main_r + overlap_l),  hinge_y + hinge_outer_r ],
133                [ -(main_r + overlap_l),  bot_y                   ],
134                [ -clamp_gap/2,           bot_y                   ],
135                [ -clamp_gap/2,           0,                      ],
136                [ 0,                      0,                      ],
137                ]);
138       HingeBodyPlan();
139     }
140     TubePlan();
141     HingePinPlan();
142   }
143 }
144
145 module TubeClampLeft() { ////toplevel
146   linextr(-clamp_width_actual/2, clamp_width_actual/2)
147     TubeClampLeftPlan();
148 }
149
150 module TubeClampRightPlan(){ ////toplevel
151   difference(){
152     difference(){
153       union(){
154         rectfromto([ clamp_gap/2,                   bot_y ],
155                    [ clamp_gap/2 + behind_knob_th,  0     ]);
156         intersection(){
157           circle(r= main_r);
158           union(){
159             rectfromto([0,0],
160                        main_r *  [5,5]);
161             rectfromto([ clamp_gap/2, main_r*5 ],
162                        main_r * [2,-5]);
163           }
164         }
165         HingeBodyPlan();
166       }
167       TubePlan();
168     }
169     HingePinPlan();
170   }
171 }
172
173 module Screws(){
174   linextr_x_yz(-main_r*5, main_r*5)
175     translate([screw_y, 0])
176     circle(r= screw/2);
177
178   translate([0, screw_y, 0]) {
179     linextr_x_yz(-(clamp_gap/2 + screw_nut_th), 0)
180       square([screw_nut_across,
181               screw_nut_across / cos(30) + bridge_slop*2],
182              center=true);
183
184     linextr_x_yz(-(main_r + bank_recess_y + screw_head_space_above),
185                  -(clamp_gap/2 + screw_nut_th + screw_head_behind))
186       square([screw_head, screw_head + bridge_slop*2],
187              center=true);
188   }
189 }
190
191 module SomeClamp(hinge_alt=false){
192   difference(){
193     linextr(-clamp_width_actual/2, clamp_width_actual/2)
194       children(0);
195
196     Screws();
197
198     for (i=[0 : hinge_lobes-1]) {
199       translate([0,
200                  hinge_y,
201                  -clamp_width_actual/2 + i * hinge_stride
202                  + (hinge_alt ? hinge_stride/2 : 0)
203                  ])
204         linextr(-hinge_gap_z, hinge_stride/2)
205         square(hinge_outer_r*2 + hinge_gap_xy, center=true);
206     }
207   }
208 }
209
210 module PowerBankItselfSidePlan(){
211   translate([0, bank_bot_y]){
212     minkowski(){
213       circle($fn=8, r=liner_th);
214       scale( bank_profile_scale_bodge *
215              bank_x_sz / ( (
216                             bank_eps_bbox_x[1] -
217                             bank_eps_bbox_x[0]
218                             ) * pspt_to_mm ))
219         translate(pspt_to_mm *
220                   [-0.5 * (bank_eps_bbox_x[0] +
221                            bank_eps_bbox_x[1]),
222                    -bank_eps_bbox_y[0]])
223         import("powerbank-anker-10000.dxf", convexity=5);
224     }
225   }
226 }
227
228 module PowerBankItself(){ ////toplevel
229   rotate([0,90,0])
230     linextr_y_xz(-bank_y_sz/2,
231                  +bank_y_sz/2)
232     PowerBankItselfSidePlan();
233 }
234
235 module PowerBankSidePlan(){ ////toplevel
236   render() difference(){
237     rectfromto([ -holder_x_sz/2,  0 ],
238                [ +holder_x_sz/2,  bank_recess_y + bank_bot_y ]);
239
240     PowerBankItselfSidePlan();
241   }
242 }
243
244 module PowerBankStrapCut(){ ////toplevel
245   difference(){
246     rectfromto([ -holder_x_sz, -0.05 ],
247                [ +holder_x_sz, strap_th + strap_r ]);
248     hull(){
249       for (sx=[-1,+1]) {
250         translate([sx * (holder_x_sz/2 - strap_r + 0.1),
251                    strap_th + strap_r])
252           circle(strap_r);
253       }
254     }
255   }
256 }
257
258 module PowerBankHolderTest(){ ////toplevel
259   difference(){
260     linextr(-1,5) PowerBankSidePlan();
261     linextr(0, strap_w) PowerBankStrapCut();
262   }
263 }
264
265 module EndRetainer(depth){ ////toplevel
266   translate([0, -bank_y_sz/2, 0]) {
267     linextr_y_xz(-endwall_th, 0)
268     rectfromto([ 0,         -holder_x_sz/2 ],
269                [ -depth,    +holder_x_sz/2 ]);
270     
271     for (m=[0,1]) {
272       mirror([0,0,m]) {
273         linextr(-holder_x_sz/2, -bank_x_sz/2){
274           hull(){
275             rectfromto([ 0, -endwall_th ],
276                        [ depth, 0 ]);
277             rectfromto([ 0, 0 ],
278                        [ 0.1, depth-0.1 ]);
279           }
280         }
281       }
282     }
283   }
284 }
285
286 module BraceTubePlan(){
287   intersection(){
288     circle(r= brace_r);
289     rectfromto(brace_r * [-2,  0],
290                brace_r * [+2, +2]);
291   }
292 }
293
294 module PowerBankHolder(){ ////toplevel
295   difference(){
296     union(){
297       rotate([0,90,0])
298         linextr_y_xz(-(bank_y_sz/2 + 0.1),
299                      +(bank_y_sz/2 + 0.1))
300         PowerBankSidePlan();
301
302       EndRetainer(retainer_walls[0]);
303       mirror([0,1,0]) EndRetainer(retainer_walls[1]);
304
305       translate([0,0, bank_x_sz/2]){
306         for (y = brace_ctrs_y) {
307           translate([0,y,0]) {
308             linextr_x_yz(0, brace_total_len)
309               BraceTubePlan();
310           }
311         }
312         translate([brace_total_len, 0,0])
313           linextr_y_xz(brace_ctrs_y_nom[0] - brace_r,
314                        brace_ctrs_y_nom[1] + brace_r)
315           BraceTubePlan();
316       }
317
318       for (strap_y = straps_y + straps_y_adj) {
319         translate([0, strap_y, 0]) {
320           linextr(-holder_x_sz/2,
321                   +holder_x_sz/2){
322             hull(){
323               for (dy = [-1,+1] *
324                      (strap_w/2 + strap_around_attach - strap_around_over)) {
325                 translate([0, dy, 0])
326                   circle(r=strap_around_over);
327               }
328             }
329           }
330         }
331       }
332     }
333
334     for (strap_y = straps_y + straps_y_adj)
335       translate([0, strap_y, 0])
336         rotate([0,0,-90])
337         rotate([0,90,0])
338         linextr(-strap_w/2,
339                 +strap_w/2)
340         PowerBankStrapCut();
341
342     translate([ bank_bot_y, -bank_y_sz/2, -bank_x_sz/2 ])
343       linextr_y_xz(-50,50)
344        rotate([0,0,90])
345        translate(bank_output_ctr)
346        square(center=true, bank_output_sz);
347
348     translate([0, -(bank_y_sz/2 + endwall_th), 0] + 0.01 * [-1,-1]) {
349       linextr(-200,200){
350         difference(){
351           square(center=true, top_cnr_r*2);
352           translate(top_cnr_r * [1,1])
353             circle(r= top_cnr_r);
354         }
355       }
356     }
357   }
358 }
359
360 module TubeClampLeft() { ////toplevel
361   // We want this to print with the recess overhand to the right
362   // where the workpiece cooling fan is
363   rotate([0,0,180]){
364     difference(){
365       SomeClamp(true)
366         TubeClampLeftPlan();
367
368       Screws();
369     }
370   }
371 }
372
373 module PlacePowerBank(){
374   translate([main_r, -mounted_pos_y_offset, 0])
375     children(0);
376 }
377
378 module Main(){ ////toplevel
379   TubeClampLeft();
380   difference(){
381     PlacePowerBank()
382       PowerBankHolder();
383     rotate([0,0,180])
384       Screws();
385   }
386 }
387
388 module TubeClampRight() { ////toplevel
389   rotate([0,0,180]) {
390     rotate([180,0,0]) {
391       difference(){
392         union(){
393           SomeClamp()
394             TubeClampRightPlan();
395
396           translate([clamp_gap/2 + behind_knob_th, screw_y, 0]) {
397             hull(){
398               linextr_x_yz(-0.1, 0)
399                 square(center=true,
400                        [knob_behind_across,
401                         knob_behind_across + knob_standout_h*2]);
402               linextr_x_yz(0, knob_standout_h)
403                 square(center=true,
404                        knob_behind_across);
405             }
406           }
407         }
408         Screws();
409       }
410     }
411   }
412 }
413
414 module TubeClampDemo() { ////toplevel
415   TubeClampLeft();
416   rotate([180,0,0])
417     TubeClampRight();
418 }
419
420 module Demo() { ////toplevel
421   Main();
422   rotate([180,0,0])
423     TubeClampRight();
424   PlacePowerBank()
425     %PowerBankItself();
426 }