chiark / gitweb /
lipo-flat-mount: battery keeper calculated output z
[reprap-play.git] / lipo-flat-mount.scad
1 // -*- C -*-
2
3 include <nutbox.scad>
4 include <utils.scad>
5
6 // pimoroni 3000mAh
7 battery = [ 51.5,
8             81.3,
9             8.0 ];
10
11 battery_wall = 2.0;
12 battery_wall_unsupp = 4.0;
13 battery_wall_top_gap = 0.75;
14
15 battery_keeper_m_th = 4;
16 battery_keeper_m_w = 4;
17 battery_keeper_x_gap = 0.75; // each side
18 battery_keeper_y_gap_overhang = 0.75;
19 battery_keeper_y_gap_nutbox = 1.0;
20 battery_keeper_z_gap_nutbox = 0.50;
21 battery_keeper_z_gap_overhang = 0.75;
22
23 battery_keeper_x_th_min = 1.5 * 1.5;
24 battery_keeper_x_th_max = 2.5 * 1.5;
25 battery_keeper_x_w  = 5;
26 battery_keeper_x_n  = 5;
27
28 battery_keeper_screw_x_off = -2.5;
29
30 battery_wire_y = 4;
31
32 battery_nutbox = nutbox_data_M3;
33
34 // calculated
35
36 battery_fix_sz = NutBox_outer_size(battery_nutbox);
37
38 battery_nutbox_z = max( battery[2] + battery_wall_top_gap,
39                         NutBox_h_base(battery_nutbox) );
40 battery_keeper_overhang_z = battery[2] + battery_keeper_m_th
41   + battery_keeper_z_gap_overhang;
42 battery_keeper_overhang_wall = battery_keeper_m_w;
43 battery_keeper_overhang_th = battery_keeper_m_th;
44
45 // calculated outputs
46
47 battery_keeper_tab_top_z = battery_nutbox_z
48      + battery_keeper_z_gap_nutbox + battery_keeper_m_th;
49 battery_keeper_frame_top_z = battery[2] + battery_keeper_m_th;
50
51 module BatteryPlan(){
52   rectfromto([ -battery[0]/2, 0          ],
53              [ +battery[0]/2, battery[1] ]);
54 }
55
56 module BatteryBase(){ ////toplevel
57   // wall
58   linextr(-0.1, battery[2] - battery_wall_top_gap, convexity=7) {
59     difference(){
60       union(){
61         offset(r=battery_wall) BatteryPlan();
62         rectfromto([ 0,0 ],
63                    [ -(battery[0]/2 + battery_wall_unsupp), battery[1]/3 ]);
64       }
65       BatteryPlan();
66       rectfromto([ battery_fix_sz/2 - 0.5
67                    + battery_keeper_screw_x_off, -30 ],
68                  [ -battery[0], battery_wire_y ]);
69     }
70   }
71
72   // nutbox
73   translate([battery_keeper_screw_x_off, -battery_fix_sz/2, battery_nutbox_z])
74     NutBox(battery_nutbox, battery_nutbox_z + 0.1);
75
76   // overhang for legs at rear
77   for (m=[0,1]) {
78     mirror([m,0,0]) {
79       translate([ battery[0]/2, battery[1], 0]) {
80         difference(){
81           linextr(-0.1,
82                   battery_keeper_overhang_z
83                   + battery_keeper_overhang_th,
84                   convexity=1)
85             rectfromto([ -battery_keeper_m_w*2, -battery_keeper_m_w ],
86                        [ battery_keeper_overhang_wall, battery_wall ]);
87           linextr(-1, battery_keeper_overhang_z,
88                   convexity=1)
89             rectfromto([-20, -20], [0,0]);          
90         }
91       }
92     }
93   }
94 }
95
96 module BatteryKeeper(){ ////toplevel
97   // A-frame
98   translate([0,0, battery[2]]) {
99     linextr(0, battery_keeper_m_th) {
100       intersection(){
101         // main legs
102         translate([0,  +battery[1], 0])
103           multmatrix([[ 1, -battery_keeper_screw_x_off/battery[1], 0, 0, ],
104                       [ 0,1,0, 0, ],
105                       [ 0,0,1, 0, ]])
106           translate([0, -battery[1], 0])
107         for (sx=[-1,+1]) {
108           multmatrix([[ 1,0,0, 0, ],
109                       [ 0,1,0, 0, ],
110                       [ 0,0,1, 0, ]] +
111                      sx *
112                      ( battery[0]/2 - 0.5 * battery_keeper_m_w
113                        - battery_keeper_x_gap ) /
114                      ( battery[1] - 0.5 * battery_keeper_m_w )
115                      *
116                      [[ 0,1,0, 0, ],
117                       [ 0,0,0, 0, ],
118                       [ 0,0,0, 0, ]])
119             rectfromto([ -battery_keeper_m_w/2,
120                          battery_keeper_y_gap_nutbox ],
121                        [ +battery_keeper_m_w/2,
122                          battery[1] - battery_keeper_y_gap_overhang ]);
123         }
124
125         // shape to round off the leg end corners
126         hull(){
127           for (sx=[-1,+1]) {
128             translate([ sx * ( battery[0]/2 - battery_keeper_m_w/2
129                                -battery_keeper_x_gap) ,
130                         battery[1] - battery_keeper_m_w/2
131                         -battery_keeper_y_gap_overhang ])
132               circle(r = battery_keeper_m_w/2);
133           }
134           square(center=true, [ battery[0], 1 ]);
135         }
136       }
137     }
138
139     // x struts
140     for (i=[0 : battery_keeper_x_n-1]) {
141       linextr(0,
142               battery_keeper_x_th_min +
143               (battery_keeper_x_th_max - battery_keeper_x_th_min)
144               * pow( i/(battery_keeper_x_n-1)*2 - 1 , 2)
145               ) {
146         difference(){
147           translate([0, battery[1] * ((i + 0.5) / battery_keeper_x_n)])
148             square(center=true, [ battery[0], battery_keeper_x_w ]);
149           children(0);
150         }
151       }
152     }
153   }
154
155   // tab for screw and nutbox
156   translate([battery_keeper_screw_x_off,
157              0,
158              battery_nutbox_z + battery_keeper_z_gap_nutbox])
159     linextr(0, battery_keeper_m_th, convexity=4) {
160     difference(){
161       rectfromto([ -battery_fix_sz/2, -battery_fix_sz ],
162                  [ +battery_fix_sz/2,
163                    0.5 * battery[1] / battery_keeper_x_n +
164                    0.5 * battery_keeper_m_w ]);
165       translate([ 0, -battery_fix_sz/2 ])
166         circle(r = battery_nutbox[0]/2);
167     }
168   }
169 }
170
171 module BatteryDemo(){ ////toplevel
172   color("grey") BatteryBase();
173   BatteryKeeper() { union(){ } }
174 }
175