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