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