chiark / gitweb /
toplevel-find: recurse on toplevels-from
[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(){
151   difference(){
152     union(){
153       rectfromto([ clamp_gap/2,                   bot_y ],
154                  [ clamp_gap/2 + behind_knob_th,  0     ]);
155       intersection(){
156         circle(r= main_r);
157         union(){
158           rectfromto([0,0],
159                       main_r *  [5,5]);
160           rectfromto([ clamp_gap/2, main_r*5 ],
161                       main_r * [2,-5]);
162         }
163       }
164       HingeBodyPlan();
165     }
166     TubePlan();
167     HingePinPlan();
168   }
169 }
170
171 module Screws(){
172   linextr_x_yz(-main_r*5, main_r*5)
173     translate([screw_y, 0])
174     circle(r= screw/2);
175
176   translate([0, screw_y, 0]) {
177     linextr_x_yz(-(clamp_gap/2 + screw_nut_th), 0)
178       square([screw_nut_across,
179               screw_nut_across / cos(30) + bridge_slop*2],
180              center=true);
181
182     linextr_x_yz(-(main_r + bank_recess_y + screw_head_space_above),
183                  -(clamp_gap/2 + screw_nut_th + screw_head_behind))
184       square([screw_head, screw_head + bridge_slop*2],
185              center=true);
186   }
187 }
188
189 module SomeClamp(hinge_alt=false){
190   difference(){
191     linextr(-clamp_width_actual/2, clamp_width_actual/2)
192       children(0);
193
194     Screws();
195
196     for (i=[0 : hinge_lobes-1]) {
197       translate([0,
198                  hinge_y,
199                  -clamp_width_actual/2 + i * hinge_stride
200                  + (hinge_alt ? hinge_stride/2 : 0)
201                  ])
202         linextr(-hinge_gap_z, hinge_stride/2)
203         square(hinge_outer_r*2 + hinge_gap_xy, center=true);
204     }
205   }
206 }
207
208 module PowerBankItselfSidePlan(){
209   translate([0, bank_bot_y]){
210     minkowski(){
211       circle($fn=8, r=liner_th);
212       scale( bank_profile_scale_bodge *
213              bank_x_sz / ( (
214                             bank_eps_bbox_x[1] -
215                             bank_eps_bbox_x[0]
216                             ) * pspt_to_mm ))
217         translate(pspt_to_mm *
218                   [-0.5 * (bank_eps_bbox_x[0] +
219                            bank_eps_bbox_x[1]),
220                    -bank_eps_bbox_y[0]])
221         import("powerbank-anker-10000.dxf", convexity=5);
222     }
223   }
224 }
225
226 module PowerBankItself(){ ////toplevel
227   rotate([0,90,0])
228     linextr_y_xz(-bank_y_sz/2,
229                  +bank_y_sz/2)
230     PowerBankItselfSidePlan();
231 }
232
233 module PowerBankSidePlan(){ ////toplevel
234   render() difference(){
235     rectfromto([ -holder_x_sz/2,  0 ],
236                [ +holder_x_sz/2,  bank_recess_y + bank_bot_y ]);
237
238     PowerBankItselfSidePlan();
239   }
240 }
241
242 module PowerBankStrapCut(){ ////toplevel
243   difference(){
244     rectfromto([ -holder_x_sz, -0.05 ],
245                [ +holder_x_sz, strap_th + strap_r ]);
246     hull(){
247       for (sx=[-1,+1]) {
248         translate([sx * (holder_x_sz/2 - strap_r + 0.1),
249                    strap_th + strap_r])
250           circle(strap_r);
251       }
252     }
253   }
254 }
255
256 module PowerBankHolderTest(){ ////toplevel
257   difference(){
258     linextr(-1,5) PowerBankSidePlan();
259     linextr(0, strap_w) PowerBankStrapCut();
260   }
261 }
262
263 module EndRetainer(depth){ ////toplevel
264   translate([0, -bank_y_sz/2, 0]) {
265     linextr_y_xz(-endwall_th, 0)
266     rectfromto([ 0,         -holder_x_sz/2 ],
267                [ -depth,    +holder_x_sz/2 ]);
268     
269     for (m=[0,1]) {
270       mirror([0,0,m]) {
271         linextr(-holder_x_sz/2, -bank_x_sz/2){
272           hull(){
273             rectfromto([ 0, -endwall_th ],
274                        [ depth, 0 ]);
275             rectfromto([ 0, 0 ],
276                        [ 0.1, depth-0.1 ]);
277           }
278         }
279       }
280     }
281   }
282 }
283
284 module BraceTubePlan(){
285   intersection(){
286     circle(r= brace_r);
287     rectfromto(brace_r * [-2,  0],
288                brace_r * [+2, +2]);
289   }
290 }
291
292 module PowerBankHolder(){ ////toplevel
293   difference(){
294     union(){
295       rotate([0,90,0])
296         linextr_y_xz(-(bank_y_sz/2 + 0.1),
297                      +(bank_y_sz/2 + 0.1))
298         PowerBankSidePlan();
299
300       EndRetainer(retainer_walls[0]);
301       mirror([0,1,0]) EndRetainer(retainer_walls[1]);
302
303       translate([0,0, bank_x_sz/2]){
304         for (y = brace_ctrs_y) {
305           translate([0,y,0]) {
306             linextr_x_yz(0, brace_total_len)
307               BraceTubePlan();
308           }
309         }
310         translate([brace_total_len, 0,0])
311           linextr_y_xz(brace_ctrs_y_nom[0] - brace_r,
312                        brace_ctrs_y_nom[1] + brace_r)
313           BraceTubePlan();
314       }
315
316       for (strap_y = straps_y + straps_y_adj) {
317         translate([0, strap_y, 0]) {
318           linextr(-holder_x_sz/2,
319                   +holder_x_sz/2){
320             hull(){
321               for (dy = [-1,+1] *
322                      (strap_w/2 + strap_around_attach - strap_around_over)) {
323                 translate([0, dy, 0])
324                   circle(r=strap_around_over);
325               }
326             }
327           }
328         }
329       }
330     }
331
332     for (strap_y = straps_y + straps_y_adj)
333       translate([0, strap_y, 0])
334         rotate([0,0,-90])
335         rotate([0,90,0])
336         linextr(-strap_w/2,
337                 +strap_w/2)
338         PowerBankStrapCut();
339
340     translate([ bank_bot_y, -bank_y_sz/2, -bank_x_sz/2 ])
341       linextr_y_xz(-50,50)
342        rotate([0,0,90])
343        translate(bank_output_ctr)
344        square(center=true, bank_output_sz);
345
346     translate([0, -(bank_y_sz/2 + endwall_th), 0] + 0.01 * [-1,-1]) {
347       linextr(-200,200){
348         difference(){
349           square(center=true, top_cnr_r*2);
350           translate(top_cnr_r * [1,1])
351             circle(r= top_cnr_r);
352         }
353       }
354     }
355   }
356 }
357
358 module TubeClampLeft() { ////toplevel
359   // We want this to print with the recess overhand to the right
360   // where the workpiece cooling fan is
361   rotate([0,0,180]){
362     difference(){
363       SomeClamp(true)
364         TubeClampLeftPlan();
365
366       Screws();
367     }
368   }
369 }
370
371 module PlacePowerBank(){
372   translate([main_r, -mounted_pos_y_offset, 0])
373     children(0);
374 }
375
376 module Main(){ ////toplevel
377   TubeClampLeft();
378   difference(){
379     PlacePowerBank()
380       PowerBankHolder();
381     rotate([0,0,180])
382       Screws();
383   }
384 }
385
386 module TubeClampRight() { ////toplevel
387   rotate([0,0,180]) {
388     rotate([180,0,0]) {
389       difference(){
390         union(){
391           SomeClamp()
392             TubeClampRightPlan();
393
394           translate([clamp_gap/2 + behind_knob_th, screw_y, 0]) {
395             hull(){
396               linextr_x_yz(-0.1, 0)
397                 square(center=true,
398                        [knob_behind_across,
399                         knob_behind_across + knob_standout_h*2]);
400               linextr_x_yz(0, knob_standout_h)
401                 square(center=true,
402                        knob_behind_across);
403             }
404           }
405         }
406         Screws();
407       }
408     }
409   }
410 }
411
412 module TubeClampDemo() { ////toplevel
413   TubeClampLeft();
414   rotate([180,0,0])
415     TubeClampRight();
416 }
417
418 module Demo() { ////toplevel
419   Main();
420   rotate([180,0,0])
421     TubeClampRight();
422   PlacePowerBank()
423     %PowerBankItself();
424 }