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