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