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