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