chiark / gitweb /
adafruit-powerboost: battery legend wip test
[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.3;
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 module PsuBoardRepresentation(){
55   linear_extrude(height= psu_th)
56     square(center=true, [psu_sz[0],psu_sz[1]]);
57 }
58
59 module PsuRepresentation(){
60   PsuBoardRepresentation();
61   translate([0, -psu_sz[1]/2, -psu_connector_z])
62     linear_extrude(height= psu_connector_z + psu_connector_z_overlap)
63     rectfromto([ -psu_connector_w/2, -10 ],
64                [ +psu_connector_w/2, psu_connector_depth ]);
65 }
66
67 module AtPsuMountCorner(mx,my){
68   mirror([mx,0,0])
69     mirror([0,my,0])
70       translate(-0.5 * [psu_sz[0], psu_sz[1], 0]
71                 -1 * [0,0, psu_z_down])
72         children();
73 }
74
75 module PsuMountCornerExtrude(mx,my, plus_z=psu_board_support_z){
76   AtPsuMountCorner(mx,my){
77     linear_extrude(height= psu_z_down + plus_z, convexity=10) {
78       children();
79     }
80   }
81 }
82
83 module PsuUsbAVSpacePlan(){
84   for (x= [-1,+1] * psu_usba_v_apart/2) {
85     translate([x, -psu_usba_v_from_edge ]) {
86       hull(){
87         for (y= [-1,+1] * 0.5 * (psu_usba_v_space_l - psu_usba_v_space_w)) {
88           translate([0,y])
89             circle(r= psu_usba_v_space_w);
90         }
91       }
92     }
93   }
94 }
95
96 module PsuMountPositiveMain(){
97   for (mx=[0,1]) {
98     for (my=[0,1]) {
99       PsuMountCornerExtrude(mx,my){
100         rectfromto(-[1,1]*psu_board_support_wall,
101                    +[1,1]*psu_board_support_ovlp);
102       }
103     }
104     // mount above at plug end
105     PsuMountCornerExtrude(mx,0, psu_th + psu_board_support_wall){
106       rectfromto(-[1,1]*psu_board_support_wall,
107                  [psu_board_support_ovlp,
108                   psu_board_support_ovlp_ceil]);
109     }
110   }
111   translate([0,0, -psu_z_down])
112     linear_extrude(psu_z_down - psu_baffle_gap, convexity=10)
113       PsuLedBafflePlan();
114 }
115
116 module PsuMountNegative(){
117   axis = [0, -psu_sz[1]/2, psu_th];
118   PsuRepresentation();
119   translate(axis)
120     rotate([atan(2 * psu_board_support_z / psu_sz[1]),
121             0,0])
122     translate(-axis)
123     PsuBoardRepresentation();
124 }
125
126 module PsuMountPositive(){
127   difference(){
128     intersection(){
129       PsuMountPositiveMain();
130       linextr_y_xz(-psu_y, psu_sz[1]*2) square(100, center=true);
131     }
132     PsuMountNegative();
133     intersection(){
134       hull(){
135         PsuBoardRepresentation();
136         translate([0,0,5]) PsuBoardRepresentation();
137       }
138       translate([-20,0,-20]) cube(40);
139     }
140   }
141   for (mx=[0,1]) {
142     PsuMountCornerExtrude(mx,1){
143       translate([psu_sz[0]/2 - psu_hole_pos[1],
144                  psu_hole_pos[0]]
145                 + psu_board_gap * [1,1] )
146         circle(r= psu_hole_dia/2);
147     }
148   }
149   difference(){
150     translate([0, psu_board_nutbox_y, 0])
151       rotate([0,0,180])
152       NutBox(psu_board_nutbox, psu_z_down);
153     translate([0, psu_sz[1]/2, 0])
154       linextr(-psu_usba_v_space_below, +10)
155       PsuUsbAVSpacePlan();
156   }
157 }
158
159 module PsuClamp(){ ////toplevel
160   rotate([180,0,0]) difference(){
161     linear_extrude(height=psu_clamp_th + psu_th_for_clamp, convexity=5) {
162       difference(){
163         hull(){
164           circle(r = psu_fix_sz/2);
165           translate([ -psu_board_nutbox[0]/2, 0])
166             square(center=true, [ psu_board_clamp_ovlp*2, psu_clamp_w ]);
167         }
168         circle(r = psu_board_nutbox[0]/2);
169       }
170     }
171     translate([0,0,-1]) linear_extrude(height=psu_th_for_clamp+1) {
172       translate([ -psu_board_nutbox[0]/2 + psu_clamp_gap, 0 ])
173         mirror([1,0])
174         translate([0,-20]) square(40);
175     }
176     linextr(-10,10) {
177       rotate(-90)
178         translate([0, -psu_board_nutbox[0]/2])
179         PsuUsbAVSpacePlan();
180     }
181   }
182 }
183
184 module PsuLedWindowsPlan(){
185   difference(){
186     PsuLedWindowsPlanCore();
187     PsuLedBafflePlan();
188   }
189 }
190
191 module PsuMountDemo() { ////toplevel
192   ceil = psu_test_ceil;
193
194   translate([0, psu_y, psu_z]) {
195     difference(){
196       PsuMountPositive();
197       linextr(-20, 0.1)
198         PsuLedWindowsPlan();
199     }
200     %PsuMountNegative();
201
202     color("yellow") translate([0,0, -psu_z - ceil])
203       linear_extrude(height=0.4, convexity=10)
204       PsuLedWindowsPlan();
205
206     color("blue") translate([0,0, -psu_z - ceil])
207       linear_extrude(height=0.4, convexity=10)
208       PsuLedLegendsPlan();
209
210     translate([0, psu_board_nutbox_y, 10])
211       rotate([180,0,0])
212       rotate([0,0,-90])
213       PsuClamp();
214   }
215 }
216
217 module PsuMountTest() { ////toplevel
218   ceil = psu_test_ceil;
219   $fs = 0.1;
220   $fa = 3;
221   difference(){
222     union(){
223       translate([0, psu_y, psu_z])
224         PsuMountPositive();
225       difference(){
226         linextr_x_yz(-(psu_sz[0]/2 + 5),
227                      +(psu_sz[0]/2 + 5)){
228           difference(){
229             rectfromto([0, -ceil], [psu_sz[1] + 10, psu_z + 10]);
230             rectfromto([ceil,0], 400*[1,1]);
231           }
232         }
233         translate([0, psu_y, psu_z]) {
234           PsuMountNegative();
235         }
236       }
237     }
238     translate([0, psu_y, psu_z]) {
239       linextr(-10, 0.1)
240         PsuLedWindowsPlan();
241     }
242   }
243 }
244
245 psu_multicolour_gap = 0.075;
246 psu_initial_layer_thick = 0.400;
247 psu_initial_layer_width = 0.750;
248 psu_window_ledge = 0.50; // each side
249
250 module PsuMountTestFullLayerFrame(ix) {
251   sz = psu_sz*2 + [1,1]*psu_initial_layer_width*(3+ix);
252   translate([0, psu_y]) difference(){
253     square(center=true, sz + psu_multicolour_gap*2*[1,1]);
254     square(center=true, sz);
255   }
256 }
257
258
259 module PsuMountTestFullMain() { ////toplevel
260   ceil = psu_test_ceil;
261
262   linextr(0, psu_initial_layer_thick)
263     PsuMountTestFullLayerFrame(2);
264   
265   difference(){
266     translate([0,0, ceil])
267       PsuMountTest();
268
269     translate([0, psu_y, 0]) {
270       linextr(-1, psu_initial_layer_thick) {
271         offset(delta=psu_window_ledge + psu_multicolour_gap)
272           PsuLedWindowsPlan();
273         offset(delta=psu_multicolour_gap)
274           PsuLedLegendsPlan();
275       }
276     }
277   }
278 }
279
280 module PsuMountTestFullOneLayer(ix) {
281   linextr(0, psu_initial_layer_thick) {
282     PsuMountTestFullLayerFrame(ix);
283     translate([0, psu_y]) children();
284   }
285 }
286
287 module PsuMountTestFullText() { ////toplevel
288   PsuMountTestFullOneLayer(0)
289     offset(delta=psu_window_ledge)
290     PsuLedLegendsPlan();
291 }
292 module PsuMountTestFullWindows() { ////toplevel
293   PsuMountTestFullOneLayer(1)
294     PsuLedWindowsPlan();
295 }
296
297 module PsuMountTestFullDemo() { ////toplevel
298   color("blue") PsuMountTestFullMain();
299   color("yellow") PsuMountTestFullText();
300   %PsuMountTestFullWindows();
301 }