chiark / gitweb /
adafruit-powerboost: reorganise layerframes
[reprap-play.git] / adafruit-powerboost-common.scad
1 // -*- C -*-
2
3 include <nutbox.scad>
4 include <utils.scad>
5
6 psu_sz  = psu_sz_nom + [ 0.11, 0.44 ] + [ 0.25, 0.25 ];
7
8 psu_hole_pos = [ 2.05, // from back edge of psu_sz[0]
9                  0.55 * 0.5 * 25.4, // from centreline
10                  ];
11
12 psu_th = 1.70 + 0.25;
13 psu_th_for_clamp = 1.50;
14
15 psu_hole_dia = 2.5 - 0.5;
16 psu_connector_z = 2.9 + 0.1;
17 psu_connector_z_overlap = 0.15;
18 psu_connector_depth = 6.25;
19 psu_connector_w = 8.0 + 0.5;
20 psu_usb_protr = 0.6;
21
22 psu_clamp_th = 4.0 + 0.75;
23 psu_clamp_w = 8.0;
24 psu_clamp_gap = 0.4;
25
26 psu_board_clamp_ovlp = 4.5;
27 psu_board_nutbox = nutbox_data_M3;
28
29 psu_board_gap = 0.5;
30 psu_board_support_wall = 2;
31 psu_board_support_ovlp = 4.5;
32 psu_board_support_ovlp_ceil = 2;
33 psu_board_support_z = 2;
34
35 psu_baffle_gap = 1.0 + 0.5;
36
37 psu_y = +psu_sz[1]/2 + psu_usb_protr;
38
39 psu_usba_v_apart = 7.0;
40 psu_usba_v_from_edge = 4.86;
41 psu_usba_v_space_below = 1.5;
42 psu_usba_v_space_w = 1.7;
43 psu_usba_v_space_l = 3.0;
44
45 psu_test_ceil = 2.5;
46
47 // ----- calculated -----
48
49 psu_z = NutBox_h_base(psu_board_nutbox);
50 psu_z_down = psu_z + 0.1;
51 psu_fix_sz = NutBox_outer_size(psu_board_nutbox);
52 psu_board_nutbox_y = psu_sz[1]/2 + psu_board_nutbox[0]/2;
53
54 psu_mount_outer_sz_x = psu_sz[0] + psu_board_support_wall * 2; // centred
55 psu_mount_outer_sz_y = psu_y + max(psu_board_support_wall, // at psu_y
56                                    psu_board_nutbox_y + psu_fix_sz/2);
57
58 module PsuBoardRepresentation(){
59   linear_extrude(height= psu_th)
60     square(center=true, [psu_sz[0],psu_sz[1]]);
61 }
62
63 module PsuRepresentation(){
64   PsuBoardRepresentation();
65   translate([0, -psu_sz[1]/2, -psu_connector_z])
66     linear_extrude(height= psu_connector_z + psu_connector_z_overlap)
67     rectfromto([ -psu_connector_w/2, -10 ],
68                [ +psu_connector_w/2, psu_connector_depth ]);
69 }
70
71 module AtPsuMountCorner(mx,my){
72   mirror([mx,0,0])
73     mirror([0,my,0])
74       translate(-0.5 * [psu_sz[0], psu_sz[1], 0]
75                 -1 * [0,0, psu_z_down])
76         children();
77 }
78
79 module PsuMountCornerExtrude(mx,my, plus_z=psu_board_support_z){
80   AtPsuMountCorner(mx,my){
81     linear_extrude(height= psu_z_down + plus_z, convexity=10) {
82       children();
83     }
84   }
85 }
86
87 module PsuUsbAVSpacePlan(){
88   for (x= [-1,+1] * psu_usba_v_apart/2) {
89     translate([x, -psu_usba_v_from_edge ]) {
90       hull(){
91         for (y= [-1,+1] * 0.5 * (psu_usba_v_space_l - psu_usba_v_space_w)) {
92           translate([0,y])
93             circle(r= psu_usba_v_space_w);
94         }
95       }
96     }
97   }
98 }
99
100 module PsuMountPositiveMain(){
101   for (mx=[0,1]) {
102     for (my=[0,1]) {
103       PsuMountCornerExtrude(mx,my){
104         rectfromto(-[1,1]*psu_board_support_wall,
105                    +[1,1]*psu_board_support_ovlp);
106       }
107     }
108     // mount above at plug end
109     PsuMountCornerExtrude(mx,0, psu_th + psu_board_support_wall){
110       rectfromto(-[1,1]*psu_board_support_wall,
111                  [psu_board_support_ovlp,
112                   psu_board_support_ovlp_ceil]);
113     }
114   }
115   translate([0,0, -psu_z_down])
116     linear_extrude(psu_z_down - psu_baffle_gap, convexity=10)
117       PsuLedBafflePlan();
118 }
119
120 module PsuMountNegative(){
121   axis = [0, -psu_sz[1]/2, psu_th];
122   PsuRepresentation();
123   translate(axis)
124     rotate([atan(2 * psu_board_support_z / psu_sz[1]),
125             0,0])
126     translate(-axis)
127     PsuBoardRepresentation();
128 }
129
130 module PsuMountPositive(){
131   difference(){
132     intersection(){
133       PsuMountPositiveMain();
134       linextr_y_xz(-psu_y, psu_sz[1]*2) square(100, center=true);
135     }
136     PsuMountNegative();
137     intersection(){
138       hull(){
139         PsuBoardRepresentation();
140         translate([0,0,5]) PsuBoardRepresentation();
141       }
142       translate([-20,0,-20]) cube(40);
143     }
144   }
145   for (mx=[0,1]) {
146     PsuMountCornerExtrude(mx,1){
147       translate([psu_sz[0]/2 - psu_hole_pos[1],
148                  psu_hole_pos[0]]
149                 + psu_board_gap * [1,1] )
150         circle(r= psu_hole_dia/2);
151     }
152   }
153   difference(){
154     translate([0, psu_board_nutbox_y, 0])
155       rotate([0,0,180])
156       NutBox(psu_board_nutbox, psu_z_down);
157     translate([0, psu_sz[1]/2, 0])
158       linextr(-psu_usba_v_space_below, +10)
159       PsuUsbAVSpacePlan();
160   }
161 }
162
163 module PsuClamp(){ ////toplevel
164   rotate([180,0,0]) difference(){
165     linear_extrude(height=psu_clamp_th + psu_th_for_clamp, convexity=5) {
166       difference(){
167         hull(){
168           circle(r = psu_fix_sz/2);
169           translate([ -psu_board_nutbox[0]/2, 0])
170             square(center=true, [ psu_board_clamp_ovlp*2, psu_clamp_w ]);
171         }
172         circle(r = psu_board_nutbox[0]/2);
173       }
174     }
175     translate([0,0,-1]) linear_extrude(height=psu_th_for_clamp+1) {
176       translate([ -psu_board_nutbox[0]/2 + psu_clamp_gap, 0 ])
177         mirror([1,0])
178         translate([0,-20]) square(40);
179     }
180     linextr(-10,10) {
181       rotate(-90)
182         translate([0, -psu_board_nutbox[0]/2])
183         PsuUsbAVSpacePlan();
184     }
185   }
186 }
187
188 module PsuLedWindowsPlan(){
189   difference(){
190     PsuLedWindowsPlanCore();
191     PsuLedBafflePlan();
192   }
193 }
194
195 module PsuMountWindowsNegative(ceil){
196   linextr(-10, 0.1)
197     PsuLedWindowsPlan();
198   translate([0, 0, -psu_z - ceil])
199     linextr(-1, psu_initial_layer_thick)
200     offset(delta=psu_window_ledge + psu_multicolour_gap)
201     PsuLedWindowsPlan();
202 }
203
204 module PsuMountDemo() { ////toplevel
205   ceil = psu_test_ceil;
206
207   translate([0, psu_y, psu_z]) {
208     difference(){
209       PsuMountPositive();
210       linextr(-20, 0.1)
211         PsuLedWindowsPlan();
212     }
213     %PsuMountNegative();
214
215     color("yellow") translate([0,0, -psu_z - ceil])
216       linear_extrude(height=0.4, convexity=10)
217       PsuLedWindowsPlan();
218
219     color("blue") translate([0,0, -psu_z - ceil])
220       linear_extrude(height=0.4, convexity=10)
221       PsuLedLegendsPlan();
222
223     translate([0, psu_board_nutbox_y, 10])
224       rotate([180,0,0])
225       rotate([0,0,-90])
226       PsuClamp();
227   }
228 }
229
230 module PsuMountTest() { ////toplevel
231   ceil = psu_test_ceil;
232   $fs = 0.1;
233   $fa = 3;
234   difference(){
235     union(){
236       translate([0, psu_y, psu_z])
237         PsuMountPositive();
238       difference(){
239
240         // rectangular box with wall
241         linextr_x_yz(-psu_mount_outer_sz_x/2,
242                      +psu_mount_outer_sz_x/2) {
243           difference(){
244             rectfromto([0, -ceil],
245                        [psu_mount_outer_sz_y, psu_z + 10]);
246             rectfromto([ceil,0], 400*[1,1]);
247           }
248         }
249
250         translate([0, psu_y, psu_z]) {
251           PsuMountNegative();
252         }
253
254         translate([0, psu_y, -ceil]) {
255           linextr(-1, psu_initial_layer_thick) {
256             offset(delta=psu_multicolour_gap)
257               PsuLedLegendsPlan();
258           }
259         }
260       }
261     }
262     translate([0, psu_y, psu_z])
263       PsuMountWindowsNegative(ceil);
264   }
265 }
266
267 psu_multicolour_gap = 0.075;
268 psu_initial_layer_thick = 0.400;
269 psu_initial_layer_width = 0.750;
270 psu_window_ledge = 0.50; // each side
271
272 psu_frame_gap = 1.0;
273
274 module PsuMountLayerFrame(bl, tr, ix) {
275   gap0 = [1,1] * (psu_frame_gap + psu_initial_layer_width*(ix+0));
276   gap1 = [1,1] * (psu_frame_gap + psu_initial_layer_width*(ix+1));
277   linextr(0, psu_initial_layer_thick) {
278     difference(){
279       rectfromto(bl-gap1, tr+gap1);
280       rectfromto(bl-gap0, tr+gap0);
281     }
282   }
283 }
284
285 module PsuMountTestFullLayerFrame(ix) {
286   PsuMountLayerFrame([-0.5 * psu_mount_outer_sz_x, 0],
287                      [+0.5 * psu_mount_outer_sz_x,
288                       psu_mount_outer_sz_y],
289                      ix);
290 }
291
292 module PsuMountTestFullMain() { ////toplevel
293   ceil = psu_test_ceil;
294
295   PsuMountTestFullLayerFrame(2);
296   
297   difference(){
298     translate([0,0, ceil])
299       PsuMountTest();
300   }
301 }
302
303 module PsuMountTestFullOneLayer(ix) {
304   PsuMountTestFullLayerFrame(ix);
305   linextr(0, psu_initial_layer_thick) {
306     translate([0, psu_y]) children();
307   }
308 }
309
310 module PsuMountTestFullText() { ////toplevel
311   PsuMountTestFullOneLayer(0)
312     PsuLedLegendsPlan();
313 }
314 module PsuMountTestFullWindows() { ////toplevel
315   PsuMountTestFullOneLayer(1)
316     offset(delta=psu_window_ledge)
317     PsuLedWindowsPlan();
318 }
319
320 module PsuMountTestFullDemo() { ////toplevel
321   color("blue") PsuMountTestFullMain();
322   color("yellow") PsuMountTestFullText();
323   %PsuMountTestFullWindows();
324 }