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