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