chiark / gitweb /
powerbank-bike-clamp: adjust strap (from v1) and fix
[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
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/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/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 echo(bot_y);
106
107 module TubePlan(){ circle(r = tube_dia/2); }
108 module HingePinPlan(){ translate([0, hinge_y]) circle(r= hinge_pin/2); }
109 module HingeBodyPlan(){ translate([0, hinge_y]) circle(r= hinge_outer_r); }
110
111 module TubeClampLeftPlan(){
112   difference(){
113     union(){
114       polygon([[ 0,                      hinge_y + hinge_outer_r ],
115                [ -(main_r + overlap_l),  hinge_y + hinge_outer_r ],
116                [ -(main_r + overlap_l),  bot_y                   ],
117                [ -clamp_gap/2,           bot_y                   ],
118                [ -clamp_gap/2,           0,                      ],
119                [ 0,                      0,                      ],
120                ]);
121       HingeBodyPlan();
122     }
123     TubePlan();
124     HingePinPlan();
125   }
126 }
127
128 module TubeClampLeft() { ////toplevel
129   linextr(-clamp_width_actual/2, clamp_width_actual/2)
130     TubeClampLeftPlan();
131 }
132
133 module TubeClampRightPlan(){
134   difference(){
135     union(){
136       rectfromto([ clamp_gap/2,                   bot_y ],
137                  [ clamp_gap/2 + behind_knob_th,  0     ]);
138       intersection(){
139         circle(r= main_r);
140         union(){
141           rectfromto([0,0],
142                       main_r *  [5,5]);
143           rectfromto([ clamp_gap/2, main_r*5 ],
144                       main_r * [2,-5]);
145         }
146       }
147       HingeBodyPlan();
148     }
149     TubePlan();
150     HingePinPlan();
151   }
152 }
153
154 module Screws(){
155   linextr_x_yz(-main_r*5, main_r*5)
156     translate([screw_y, 0])
157     circle(r= screw/2);
158
159   translate([0, screw_y, 0]) {
160     linextr_x_yz(-(clamp_gap/2 + screw_nut_th), 0)
161       square([screw_nut_across,
162               screw_nut_across / cos(30) + bridge_slop*2],
163              center=true);
164
165     linextr_x_yz(-200,
166                  -(clamp_gap/2 + screw_nut_th + screw_head_behind))
167       square([screw_head, screw_head + bridge_slop*2],
168              center=true);
169   }
170 }
171
172 module SomeClamp(hinge_alt=false){
173   difference(){
174     linextr(-clamp_width_actual/2, clamp_width_actual/2)
175       children(0);
176
177     Screws();
178
179     for (i=[0 : hinge_lobes-1]) {
180       translate([0,
181                  hinge_y,
182                  -clamp_width_actual/2 + i * hinge_stride
183                  + (hinge_alt ? hinge_stride/2 : 0)
184                  ])
185         linextr(-hinge_gap_z, hinge_stride/2)
186         square(hinge_outer_r*2 + hinge_gap_xy, center=true);
187     }
188   }
189 }
190
191 module PowerBankItselfSidePlan(){
192   translate([0, bank_bot_y]){
193     minkowski(){
194       circle($fn=8, r=liner_th);
195       scale( bank_profile_scale_bodge *
196              bank_x_sz / ( (
197                             bank_eps_bbox_x[1] -
198                             bank_eps_bbox_x[0]
199                             ) * pspt_to_mm ))
200         translate(pspt_to_mm *
201                   [-0.5 * (bank_eps_bbox_x[0] +
202                            bank_eps_bbox_x[1]),
203                    -bank_eps_bbox_y[0]])
204         import("powerbank-anker-10000.dxf", convexity=5);
205     }
206   }
207 }
208
209 module PowerBankItself(){ ////toplevel
210   rotate([0,90,0])
211     linextr_y_xz(-bank_y_sz/2,
212                  +bank_y_sz/2)
213     PowerBankItselfSidePlan();
214 }
215
216 module PowerBankSidePlan(){ ////toplevel
217   render() difference(){
218     rectfromto([ -holder_x_sz/2,  0 ],
219                [ +holder_x_sz/2,  bank_recess_y + bank_bot_y ]);
220
221     PowerBankItselfSidePlan();
222   }
223 }
224
225 module PowerBankStrapCut(){ ////toplevel
226   difference(){
227     rectfromto([ -holder_x_sz, -0.05 ],
228                [ +holder_x_sz, strap_th + strap_r ]);
229     hull(){
230       for (sx=[-1,+1]) {
231         translate([sx * (holder_x_sz/2 - strap_r + 0.1),
232                    strap_th + strap_r])
233           circle(strap_r);
234       }
235     }
236   }
237 }
238
239 module PowerBankHolderTest(){ ////toplevel
240   difference(){
241     linextr(-1,5) PowerBankSidePlan();
242     linextr(0, strap_w) PowerBankStrapCut();
243   }
244 }
245
246 module EndRetainer(depth){ ////toplevel
247   translate([0, -bank_y_sz/2, 0]) {
248     linextr_y_xz(-endwall_th, 0)
249     rectfromto([ 0,         -holder_x_sz/2 ],
250                [ -depth,    +holder_x_sz/2 ]);
251     
252     for (m=[0,1]) {
253       mirror([0,0,m]) {
254         linextr(-holder_x_sz/2, -bank_x_sz/2){
255           hull(){
256             rectfromto([ 0, -endwall_th ],
257                        [ depth, 0 ]);
258             rectfromto([ 0, 0 ],
259                        [ 0.1, depth-0.1 ]);
260           }
261         }
262       }
263     }
264   }
265 }
266
267 module BraceTubePlan(){
268   intersection(){
269     circle(r= brace_r);
270     rectfromto(brace_r * [-2,  0],
271                brace_r * [+2, +2]);
272   }
273 }
274
275 module PowerBankHolder(){ ////toplevel
276   difference(){
277     union(){
278       rotate([0,90,0])
279         linextr_y_xz(-(bank_y_sz/2 + 0.1),
280                      +(bank_y_sz/2 + 0.1))
281         PowerBankSidePlan();
282
283       EndRetainer(retainer_walls[0]);
284       mirror([0,1,0]) EndRetainer(retainer_walls[1]);
285     }
286
287     for (strap_y = straps_y)
288       translate([0, strap_y, 0])
289         rotate([0,0,-90])
290         rotate([0,90,0])
291         linextr(-strap_w/2,
292                 +strap_w/2)
293         PowerBankStrapCut();
294
295     translate([ bank_bot_y, -bank_y_sz/2, -bank_x_sz/2 ])
296       linextr_y_xz(-50,50)
297        rotate([0,0,90])
298        translate(bank_input_ctr)
299        square(center=true, bank_input_sz);
300   }
301
302   translate([0,0, bank_x_sz/2]){
303     for (y = brace_ctrs_y) {
304       translate([0,y,0]) {
305         linextr_x_yz(0, brace_total_len)
306           BraceTubePlan();
307       }
308     }
309     translate([brace_total_len, 0,0])
310       linextr_y_xz(brace_ctrs_y[0] - brace_r,
311                    brace_ctrs_y[1] + brace_r)
312       BraceTubePlan();
313   }
314 }
315
316 module TubeClampLeft() { ////toplevel
317   // We want this to print with the recess overhand to the right
318   // where the workpiece cooling fan is
319   rotate([0,0,180]){
320     difference(){
321       SomeClamp(true)
322         TubeClampLeftPlan();
323
324       Screws();
325     }
326   }
327 }
328
329 module PlacePowerBank(){
330   translate([main_r, -mounted_pos_y_offset, 0])
331     children(0);
332 }
333
334 module Main(){ ////toplevel
335   TubeClampLeft();
336   difference(){
337     PlacePowerBank()
338       PowerBankHolder();
339     rotate([0,0,180])
340       Screws();
341   }
342 }
343
344 module TubeClampRight() { ////toplevel
345   rotate([0,0,180])
346     rotate([180,0,0])
347     SomeClamp()
348     TubeClampRightPlan();
349 }
350
351 module TubeClampDemo() { ////toplevel
352   TubeClampLeft();
353   rotate([180,0,0])
354     TubeClampRight();
355 }
356
357 module Demo() { ////toplevel
358   Main();
359   rotate([180,0,0])
360     TubeClampRight();
361   PlacePowerBank()
362     %PowerBankItself();
363 }