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