chiark / gitweb /
lipo-flat-mount: tidy so it works here
[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 module BatteryPlan(){
46   rectfromto([ -battery[0]/2, 0          ],
47              [ +battery[0]/2, battery[1] ]);
48 }
49
50 module BatteryBase(){ ////toplevel
51   // wall
52   linextr(-0.1, battery[2] - battery_wall_top_gap, convexity=7) {
53     difference(){
54       union(){
55         offset(r=battery_wall) BatteryPlan();
56         rectfromto([ 0,0 ],
57                    [ -(battery[0]/2 + battery_wall_unsupp), battery[1]/3 ]);
58       }
59       BatteryPlan();
60       rectfromto([ battery_fix_sz/2 - 0.5
61                    + battery_keeper_screw_x_off, -30 ],
62                  [ -battery[0], battery_wire_y ]);
63     }
64   }
65
66   // nutbox
67   translate([battery_keeper_screw_x_off, -battery_fix_sz/2, battery_nutbox_z])
68     NutBox(battery_nutbox, battery_nutbox_z + 0.1);
69
70   // overhang for legs at rear
71   for (m=[0,1]) {
72     mirror([m,0,0]) {
73       translate([ battery[0]/2, battery[1], 0]) {
74         difference(){
75           linextr(-0.1,
76                   battery_keeper_overhang_z
77                   + battery_keeper_overhang_th,
78                   convexity=1)
79             rectfromto([ -battery_keeper_m_w*2, -battery_keeper_m_w ],
80                        [ battery_keeper_overhang_wall, battery_wall ]);
81           linextr(-1, battery_keeper_overhang_z,
82                   convexity=1)
83             rectfromto([-20, -20], [0,0]);          
84         }
85       }
86     }
87   }
88 }
89
90 module BatteryKeeper(){ ////toplevel
91   // A-frame
92   translate([0,0, battery[2]]) {
93     linextr(0, battery_keeper_m_th) {
94       intersection(){
95         // main legs
96         translate([0,  +battery[1], 0])
97           multmatrix([[ 1, -battery_keeper_screw_x_off/battery[1], 0, 0, ],
98                       [ 0,1,0, 0, ],
99                       [ 0,0,1, 0, ]])
100           translate([0, -battery[1], 0])
101         for (sx=[-1,+1]) {
102           multmatrix([[ 1,0,0, 0, ],
103                       [ 0,1,0, 0, ],
104                       [ 0,0,1, 0, ]] +
105                      sx *
106                      ( battery[0]/2 - 0.5 * battery_keeper_m_w
107                        - battery_keeper_x_gap ) /
108                      ( battery[1] - 0.5 * battery_keeper_m_w )
109                      *
110                      [[ 0,1,0, 0, ],
111                       [ 0,0,0, 0, ],
112                       [ 0,0,0, 0, ]])
113             rectfromto([ -battery_keeper_m_w/2,
114                          battery_keeper_y_gap_nutbox ],
115                        [ +battery_keeper_m_w/2,
116                          battery[1] - battery_keeper_y_gap_overhang ]);
117         }
118
119         // shape to round off the leg end corners
120         hull(){
121           for (sx=[-1,+1]) {
122             translate([ sx * ( battery[0]/2 - battery_keeper_m_w/2
123                                -battery_keeper_x_gap) ,
124                         battery[1] - battery_keeper_m_w/2
125                         -battery_keeper_y_gap_overhang ])
126               circle(r = battery_keeper_m_w/2);
127           }
128           square(center=true, [ battery[0], 1 ]);
129         }
130       }
131     }
132
133     // x struts
134     for (i=[0 : battery_keeper_x_n-1]) {
135       linextr(0,
136               battery_keeper_x_th_min +
137               (battery_keeper_x_th_max - battery_keeper_x_th_min)
138               * pow( i/(battery_keeper_x_n-1)*2 - 1 , 2)
139               ) {
140         difference(){
141           translate([0, battery[1] * ((i + 0.5) / battery_keeper_x_n)])
142             square(center=true, [ battery[0], battery_keeper_x_w ]);
143           children(0);
144         }
145       }
146     }
147   }
148
149   // tab for screw and nutbox
150   translate([battery_keeper_screw_x_off,
151              0,
152              battery_nutbox_z + battery_keeper_z_gap_nutbox])
153     linextr(0, battery_keeper_m_th, convexity=4) {
154     difference(){
155       rectfromto([ -battery_fix_sz/2, -battery_fix_sz ],
156                  [ +battery_fix_sz/2,
157                    0.5 * battery[1] / battery_keeper_x_n +
158                    0.5 * battery_keeper_m_w ]);
159       translate([ 0, -battery_fix_sz/2 ])
160         circle(r = battery_nutbox[0]/2);
161     }
162   }
163 }
164
165 module BatteryDemo(){ ////toplevel
166   color("grey") BatteryBase();
167   BatteryKeeper() { union(){ } }
168 }
169