chiark / gitweb /
powerbank-bike-clamp: fix overlap
[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 // calculated
56
57 straps_y = [ -bank_y_sz * 0.25,
58              +bank_y_sz * 0.25 ];
59
60 endwall_th = main_th;
61
62 bank_recess_dx = minor_wall_min;
63
64 pspt_to_mm = 25.4 / 72;
65
66 hinge_stride = (clamp_width + hinge_gap_z) / hinge_lobes;
67
68 main_r = tube_dia/2 + main_th;
69
70 hinge_outer_r = hinge_around + hinge_pin/2;
71 hinge_y = tube_dia/2 + hinge_outer_r;
72
73 screw_max_y_lhs = -main_r -screw_nut_across/2;
74 screw_max_y_rhs = -main_r -knob_behind_across/2;
75
76 screw_y = min(screw_max_y_lhs,
77               screw_max_y_rhs);
78
79 bot_y = screw_y -max( screw_nut_across, knob_behind_across/2 )
80   -minor_wall_min;
81
82 holder_x_sz = bank_x_sz + bank_recess_dx*2;
83 bank_bot_y = strap_above + strap_th;
84 strap_r = strap_th;
85
86 echo(bot_y);
87
88 module TubePlan(){ circle(r = tube_dia/2); }
89 module HingePinPlan(){ translate([0, hinge_y]) circle(r= hinge_pin/2); }
90 module HingeBodyPlan(){ translate([0, hinge_y]) circle(r= hinge_outer_r); }
91
92 module TubeClampLeftPlan(){
93   difference(){
94     union(){
95       polygon([[ 0,                      hinge_y + hinge_outer_r ],
96                [ -(main_r + overlap_l),  hinge_y + hinge_outer_r ],
97                [ -(main_r + overlap_l),  bot_y                   ],
98                [ -clamp_gap/2,           bot_y                   ],
99                [ -clamp_gap/2,           0,                      ],
100                [ 0,                      0,                      ],
101                ]);
102       HingeBodyPlan();
103     }
104     TubePlan();
105     HingePinPlan();
106   }
107 }
108
109 module TubeClampLeft() { ////toplevel
110   linextr(-clamp_width/2, clamp_width/2)
111     TubeClampLeftPlan();
112 }
113
114 module TubeClampRightPlan(){
115   difference(){
116     union(){
117       rectfromto([ clamp_gap/2,                   bot_y ],
118                  [ clamp_gap/2 + behind_knob_th,  0     ]);
119       intersection(){
120         circle(r= main_r);
121         union(){
122           rectfromto([0,0],
123                       main_r *  [5,5]);
124           rectfromto([ clamp_gap/2, main_r*5 ],
125                       main_r * [2,-5]);
126         }
127       }
128       HingeBodyPlan();
129     }
130     TubePlan();
131     HingePinPlan();
132   }
133 }
134
135 module SomeClamp(hinge_alt=false){
136   difference(){
137     linextr(-clamp_width/2, clamp_width/2)
138       children(0);
139
140     linextr_x_yz(-main_r*5, main_r*5)
141       translate([screw_y, 0])
142       circle(r= screw/2);
143
144     for (i=[0 : hinge_lobes-1]) {
145       translate([0,
146                  hinge_y,
147                  -clamp_width/2 + i * hinge_stride
148                  + (hinge_alt ? hinge_stride/2 : 0)
149                  ])
150         linextr(-hinge_gap_z, hinge_stride/2)
151         square(hinge_outer_r*2 + hinge_gap_xy, center=true);
152     }
153   }
154 }
155
156 module PowerBankItselfSidePlan(){
157   translate([0, bank_bot_y])
158     scale( bank_profile_scale_bodge *
159            bank_x_sz / ( (
160                           bank_eps_bbox_x[1] -
161                           bank_eps_bbox_x[0]
162                           ) * pspt_to_mm ))
163     translate(pspt_to_mm *
164               [-0.5 * (bank_eps_bbox_x[0] +
165                        bank_eps_bbox_x[1]),
166                -bank_eps_bbox_y[0]])
167     import("powerbank-anker-10000.dxf", convexity=5);
168 }
169
170 module PowerBankItself(){ ////toplevel
171   rotate([0,90,0])
172     linextr_y_xz(-bank_y_sz/2,
173                  +bank_y_sz/2)
174     PowerBankItselfSidePlan();
175 }
176
177 module PowerBankSidePlan(){ ////toplevel
178   render() difference(){
179     rectfromto([ -holder_x_sz/2,  0 ],
180                [ +holder_x_sz/2,  bank_recess_y + bank_bot_y ]);
181
182     PowerBankItselfSidePlan();
183   }
184 }
185
186 module PowerBankStrapCut(){ ////toplevel
187   difference(){
188     rectfromto([ -holder_x_sz, -0.05 ],
189                [ +holder_x_sz, strap_th + strap_r ]);
190     hull(){
191       for (sx=[-1,+1]) {
192         translate([sx * (holder_x_sz/2 - strap_r + 0.1),
193                    strap_th + strap_r])
194           circle(strap_r);
195       }
196     }
197   }
198 }
199
200 module PowerBankHolderTest(){ ////toplevel
201   difference(){
202     linextr(-1,5) PowerBankSidePlan();
203     linextr(0, strap_th) PowerBankStrapCut();
204   }
205 }
206
207 module EndRetainer(depth){ ////toplevel
208   translate([0, -bank_y_sz/2, 0]) {
209     linextr_y_xz(-endwall_th, 0)
210     rectfromto([ 0,         -holder_x_sz/2 ],
211                [ -depth,    +holder_x_sz/2 ]);
212     
213     for (m=[0,1]) {
214       mirror([0,0,m]) {
215         linextr(-holder_x_sz/2, -bank_x_sz/2){
216           hull(){
217             rectfromto([ 0, -endwall_th ],
218                        [ depth, 0 ]);
219             rectfromto([ 0, 0 ],
220                        [ 0.1, depth-0.1 ]);
221           }
222         }
223       }
224     }
225   }
226 }
227
228 module PowerBankHolder(){ ////toplevel
229   difference(){
230     union(){
231       rotate([0,90,0])
232         linextr_y_xz(-(bank_y_sz/2 + 0.1),
233                      +(bank_y_sz/2 + 0.1))
234         PowerBankSidePlan();
235
236       EndRetainer(retainer_walls[0]);
237       mirror([0,1,0]) EndRetainer(retainer_walls[1]);
238     }
239
240     for (strap_y = straps_y)
241       translate([0, strap_y, 0])
242         rotate([0,0,-90])
243         rotate([0,90,0])
244         linextr(-strap_th/2,
245                 +strap_th/2)
246         PowerBankStrapCut();
247
248     translate([ bank_bot_y, -bank_y_sz/2, -bank_x_sz/2 ])
249       linextr_y_xz(-50,50)
250        rotate([0,0,90])
251        translate(bank_input_ctr)
252        square(center=true, bank_input_sz);
253   }
254 }
255
256 module TubeClampLeft() { ////toplevel
257   // We want this to print with the recess overhand to the right
258   // where the workpiece cooling fan is
259   rotate([0,0,180]){
260     difference(){
261       SomeClamp(true)
262         TubeClampLeftPlan();
263
264       translate([0, screw_y, 0]) {
265         linextr_x_yz(-(clamp_gap/2 + screw_nut_th), 0)
266           square([screw_nut_across,
267                   screw_nut_across / cos(30) + bridge_slop*2],
268                  center=true);
269
270         linextr_x_yz(-main_r, -main_r + screw_head_h)
271           square([screw_head, screw_head + bridge_slop*2],
272                  center=true);
273       }
274     }
275   }
276 }
277
278 module Main(){ ////toplevel
279   translate([-main_r, 0,0])
280     TubeClampLeft();
281   PowerBankHolder();
282 }
283
284 module TubeClampRight() { ////toplevel
285   rotate([0,0,180])
286     rotate([180,0,0])
287     SomeClamp()
288     TubeClampRightPlan();
289 }
290
291 module TubeClampDemo() { ////toplevel
292   TubeClampLeft();
293   rotate([180,0,0])
294     TubeClampRight();
295 }