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