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