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