case.scad: different approach
[heater.git] / case.scad
index 6a000e8..a76ae70 100644 (file)
--- a/case.scad
+++ b/case.scad
 
 lowres = 1;
 
+eps = 0.01;
+infty = 300;
+
+wall = 1.5; // generic wall thickness
+
 // 18650 is ~18mm diameter, ~65mm length, 
 batt_diam = 18 + 0.6;
 batt_len = 65 + 1.5;
-wall = 2.2;
-base_h = 3;
+
 cable_sep = 2.5;
 
+// front flat area
+front_flat_len = batt_len + 2*wall + 2*cable_sep;
 
-eps = 0.01;
-infty = 300;
-
-pcb_len = 36 + 1;
-pcb_thick = 1.2 + 0.3;
-pcb_groove = 1;
-pcb_width = 11 + 0.5;
+// PCB-related dimensions
+pcb_len = 36 + 1;      // length of the board
+pcb_width = 11 + 0.5;  // width of the board
+pcb_thick = 1.2 + 0.3;         // thickness of the board
+pcb_comp_h = 2.2;      // height of the components on board
+pcb_groove = 0.5;
 
-batt_clip_h = base_h + pcb_width - pcb_groove;
+body_top_h = 0.30 * batt_diam; // cube-shaped part of the body
 
 wire_thick = 2.2;
 wire_sep = 3.5;
@@ -44,219 +49,147 @@ base_batt_extend = wall + pcb_thick; // extend the base on the battery side
 
 cover_sep = 0.1;
 
-uswitch_diam = 2.5 + 0.5;
+sw_diam = 2.5 + 0.5;
 led_diam = 3 + 0.5;
-s2_xoff = -160 * 25.4/1000;
-led_xoff = 90 * 25.4/1000;
-s1_xoff = 340 * 25.4/1000;
+sw_xoff =  250 * 25.4/1000; // x offset of microswitches
 
 pcb_clip_w = 7;
 pcb_clip_off = led_xoff + pcb_clip_w/2;
 
-module base() {
-       translate([0, 0, base_h/2]) {
-               hull() {
-                       cube([batt_len + 2*wall + 2*cable_sep, batt_diam + 2*wall, base_h], center=true);
-                       // under the PCB
-                       translate([0, -batt_diam/2-wall-pcb_thick/2-wall/2, 0])
-                               cube([batt_len + 2*wall, pcb_thick + wall + eps, base_h], center=true);
-                       // battery-side extension
-                       translate([0, batt_diam/2 + wall + base_batt_extend, 0])
-                               cube([batt_len + 2*wall, eps, base_h], center=true);
-               };
-       };
-}
-module base_protrusions() {
-       // pcb-side side protrusion
-       translate([-pcbside_protrusion_len/2, -batt_diam/2-2*wall-pcb_thick, base_h-pcbside_protrusion_diam/2])
-               rotate([0, 90, 0])
-               cylinder(r = pcbside_protrusion_diam/2, h = pcbside_protrusion_len, $fn = 6);
-       
-       // battery-side side protrusion
-       translate([-battside_protrusion_len/2, batt_diam/2+wall+base_batt_extend, base_h-battside_protrusion_diam/2])
-               rotate([0, 90, 0])
-               cylinder(r = battside_protrusion_diam/2, h = battside_protrusion_len, $fn = 6);
-};
 
-module pcb_clips() {
-       // rear part of the PCB holder (behind S1)
-       translate([pcb_clip_off, -batt_diam/2-wall-pcb_thick+eps, 0])
-               cube([pcb_clip_w, pcb_thick+wall, pcb_width + wall + base_h - pcb_groove]);
-       // side part of the PCB holder (near the battery wires)
-       translate([-pcb_len/2-wall, -batt_diam/2-pcb_thick-2*wall, 0])
-               cube([pcb_groove+wall, pcb_thick+2*wall+eps, pcb_width + wall + base_h - pcb_groove]);
+module battery() {
+       translate([-batt_len/2, 0, 0])
+               rotate([0, 90, 0])
+               cylinder(r=batt_diam/2, h = batt_len);
 };
 
-module batt_clips() {
-       difference() {
-               union() {
-                       // frot + rear part of the battery clip
-                       for (r = [0, 180]) {
-                       rotate([0, 0, r])
-                       translate([batt_len/2+wall/2, 0, batt_clip_h/2+wall/2])
-                               hull() {
-                                       cube([wall, batt_diam + 2*wall, batt_clip_h + wall], center=true); 
-                                       translate([-15/2, 0, -batt_clip_h/2])
-                                       cube([15, batt_diam+2*wall, wall], center=true);
-                               };
-                       }
-                       // middle clips
-                       translate([pcb_clip_off+pcb_clip_w/2, 0, batt_clip_h/2+wall/2])
-                               hull() {
-                                       cube([pcb_clip_w, batt_diam + 2*wall, batt_clip_h + wall], center=true);
-                                       translate([0, 0, -batt_clip_h/2])
-                                       cube([2*pcb_clip_w, batt_diam+2*wall, wall], center=true);
-                               };
-                       // pcb holder - pcb side only
-                       translate([-pcb_len/2-wall, -batt_diam/2-wall, 0])
-                               hull() {
-                                       cube([pcb_groove + wall, batt_diam/2 + wall, base_h + pcb_width + wall - pcb_groove]);
-                                       translate([-3*(pcb_groove+wall), 0, 0])
-                                       cube([4*(pcb_groove+wall), batt_diam/2 + wall, base_h]);
-                               };
-               }
-               // top part rounded
+module case_body() {
+       hull() {
+               translate([-batt_len/2-wall-cable_sep, -batt_diam/2-wall, 0])
+                       cube([batt_len + 2*wall + 2*cable_sep,
+                               batt_diam+2*wall, body_top_h]);
                difference() {
-                       translate([0, 0, infty/4 + wall + batt_diam/2])
-                               cube([infty/2, infty/2, infty/2], center=true);
-                       translate([-infty/2, 0, batt_diam/2+wall])
+                       translate([-batt_len/2-wall-cable_sep, 0, 0])
                                rotate([0, 90, 0])
-                               cylinder(r=batt_diam/2+wall, h = infty);
+                               cylinder(r=batt_diam/2+wall,
+                                       h = batt_len + 2*wall + 2*cable_sep);
+                       translate([-infty/2, -infty/2, eps]) cube(infty);
                };
+               translate([-front_flat_len/2,
+                       batt_diam/2 - pcb_width,
+                       -batt_diam/2-2*pcb_comp_h-pcb_thick-wall])
+                       cube([front_flat_len, pcb_width+wall, eps]);
+/*
+               translate([-batt_len/2 - 2*wall - cable_sep, 0, 0])
+                       rotate([0, 90, 0])
+                       cylinder(r = 1.414*wire_sep + wire_thick,
+                               h = batt_len + 4*wall + 2*cable_sep);
+*/
        };
 };
 
-module battery() {
-       // battery
-       translate([-batt_len/2, 0, batt_diam/2+wall])
-               rotate([0, 90, 0])
-               cylinder(r=batt_diam/2, h = batt_len);
-};
-
-module main() {
+module case() {
        difference() {
-               union() {
-                       base();
-                       base_protrusions();
-                       pcb_clips();
-                       batt_clips();
-               };
-               // the PCB itself
-               translate([0, -batt_diam/2-wall-pcb_thick/2, base_h - pcb_groove + pcb_width/2])
-                       cube([pcb_len, pcb_thick, pcb_width], center=true);
-               // battery
-               battery();
-               // 4 wire holes at the battery ends
-               for (j=[-wire_sep/2, wire_sep/2]) 
-               for (i=[-wire_sep/2, wire_sep/2]) 
-               translate([-infty/2, i, batt_diam/2 + wall+j])
+               case_body();
+               // upper cube-shaped part
+               // rotate([20, 0, 0])
+               translate([-batt_len/2, -batt_diam/2, 0])
+                       cube([batt_len, batt_diam, batt_diam]);
+
+               // battery cylinder for the lower part
+               translate([-batt_len/2, 0, 0])
                        rotate([0, 90, 0])
-                       rotate([0, 0, 90])
-                       cylinder(r=wire_thick/2, h = infty, $fn=6);
+                       cylinder(r=batt_diam/2, h = batt_len);
 
-               // holes for wire from battery to the PCB
-               translate([-infty/2, -batt_diam/2, base_h + wire_thick/2])
-                       rotate([0, 90, 0])
-                       rotate([0, 0, 90])
-                       cylinder(r=wire_thick/2, h = infty, $fn=6);
-               // hole for the cable outlet
-               translate([-pcb_len/2+pcb_groove+cable_out_diam/2, -batt_diam/2-pcb_thick-2*wall, -infty/2])
-                       cylinder(r=cable_out_diam/2, h = infty, $fn=6);
-               // holes for binding to the shoe
-               for (x = [
-                        pcb_len/2 + wall + wire_thick/2 + wire_sep,
-                        pcb_len/2 + wall + wire_thick/2,
-                       -pcb_len/2 - wall - wire_thick/2 - wire_sep,,
-                       -pcb_len/2 - wall - wire_thick/2 ]) {
-                       for (y = [-1,1]) {
-                               translate([x, y*(batt_diam/2 + wall + wire_thick/2), -infty/2])
-                                       cylinder(r=wire_thick/2, h=infty, $fn=6);
+               // hole for PCB
+               translate([-pcb_len/2,
+                       batt_diam/2-pcb_width,
+                       -batt_diam/2-pcb_thick - pcb_comp_h])
+                       cube([pcb_len, pcb_width,
+                               batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
+               // hole under the PCB
+               translate([-pcb_len/2+pcb_groove,
+                       batt_diam/2-pcb_width + pcb_groove,
+                       -batt_diam/2-pcb_thick - 2*pcb_comp_h])
+                       cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
+                               batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
+                // LED hole
+               translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
+                       cylinder(r=led_diam/2, h=infty, $fn=6);
+                       translate([sw_xoff, 0, 0])
+                               cylinder(r=sw_diam/2, h=infty, $fn=6);
+                       translate([-sw_xoff, 0, 0])
+                               cylinder(r=sw_diam/2, h=infty, $fn=6);
+               };
+               // space under the wire holes for battery contacts
+               translate([-batt_len/2-wall-cable_sep-eps, 0, 0])
+                       difference() {
+                               rotate([0, 90, 0])
+                                       cylinder(r = batt_diam/2-wall, h = batt_len + 2*wall + 2*cable_sep + 2*eps);
+                               translate([-infty/2, -infty/2, -body_top_h])
+                                       cube(infty);
                        };
+               // wire holes for battery contacts
+               for (x = [-1, 1])
+               for (y = [-1, 1])
+                       translate([-batt_len/2-wall-eps, x*wire_sep/2, y*wire_sep/2])
+                       rotate([0, 90, 0])
+                               cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
+               // wire hole from PCB to battery contacts
+               // translate([-batt_len/2-wall-eps, 0, -batt_diam/2-pcb_comp_h + wire_thick/2])
+               rotate([40, 0, 0])
+               translate([-batt_len/2-wall-eps, 0, -batt_diam/2 - wall/2 - wire_thick/2])
+                       rotate([0, 90, 0])
+                               cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
+               // hole behind the battery contacts
+               for(x=[1, -1])
+               scale([x, 1, 1]) translate([batt_len/2+wall, 0, 0]) hull() {
+                       translate([0, -batt_diam/2, 0])
+                               cube([cable_sep + eps, batt_diam, infty]);
+                       rotate([0, 90, 0])
+                               cylinder(r = batt_diam/2, h = cable_sep+eps);
+                       translate([0, batt_diam/2 - pcb_width,
+                               -batt_diam/2-pcb_comp_h-pcb_thick])
+                               cube([cable_sep + eps, pcb_width, eps]);
                };
-               // hole for easy opening
-               translate([-battside_protrusion_len/2, batt_diam/2+wall+base_batt_extend, base_h-3*battside_protrusion_diam/2])
-               rotate([0, 90, 0])
-               cylinder(r = battside_protrusion_diam/2, h = battside_protrusion_len, $fn = 4);
-               
        };
 };
 
-module cover_internal() {
-       hull() { 
-               base();
-               // battery + wall + cable space
-               translate([-batt_len/2, 0, batt_diam/2+wall])
+module lid_body() {
+       translate([-batt_len/2 + eps, -batt_diam/2, -batt_diam/2-eps])
+               cube([batt_len - 2*eps, batt_diam, batt_diam/2 - body_top_h + wall + eps]);
+       translate([-batt_len/2 - wall - cable_sep, -batt_diam/2 - wall,
+               -batt_diam/2-wall])
+               cube([batt_len + 2*wall + 2*cable_sep, batt_diam + 2*wall,
+                       wall + batt_diam/2 - body_top_h]);
+       // clip behind the battery contacts
+       for(x=[1, -1])
+               scale([x, 1, 1]) translate([batt_len/2+cable_sep, 0, 0]) hull() {
+                       translate([0, -batt_diam/2, -batt_diam/2])
+                               cube([wall, batt_diam, eps]);
                        rotate([0, 90, 0])
-                       cylinder(r=batt_diam/2, h = batt_len);
-               // battery top
-               translate([0, 0, wall + batt_clip_h])
-                       cube([batt_len+2*wall + cable_sep, batt_diam + 2*wall, eps], center=true);
-               // space for PCB
-               translate([-pcb_len/2-wall, -batt_diam/2-2*wall-pcb_thick, base_h-pcb_groove])
-                       cube([pcb_len+2*wall, wall+pcb_thick, pcb_width+wall]);
-       };
+                               cylinder(r = batt_diam/2, h = wall);
+                       translate([0, batt_diam/2 - pcb_width,
+                               batt_diam/2+pcb_comp_h+pcb_thick])
+                               cube([wall, pcb_width, eps]);
+               };
 };
 
-module cover_hole() {
+module lid() {
        difference() {
-               cover_internal();
-               for (r = [0, 180]) {
-                       rotate([0, 0, r]) 
-                       translate([batt_len/2, -infty/2, wall + batt_clip_h])
-                               cube(infty);
-               }
+               lid_body();
+               translate([-batt_len/2-eps, 0, 0]) rotate([0, 90, 0])
+                       cylinder(r=batt_diam/2, h=batt_len+2*eps);
        };
-       base_protrusions();
 };
 
-module cover() {
-       difference() {
-               minkowski() {
-                       cover_internal();
-                       if (lowres == 1) {
-                               sphere(wall+cover_sep, $fn=6);
-                       } else {
-                               sphere(wall+cover_sep, $fn=16);
-                       }
-               }
-               minkowski() {
-                       cover_hole();
-                       sphere(cover_sep, $fn=8);
-               };
-               // s2 hole
-               translate([s2_xoff, 0, base_h-pcb_groove + pcb_width/2])
-                       rotate([90, 0, 0])
-                       cylinder(r=uswitch_diam/2, h = infty, $fn=6);
-               // LED hole
-               translate([led_xoff, 0, base_h-pcb_groove + pcb_width/2])
-                       rotate([90, 0, 0])
-                       cylinder(r=led_diam/2, h = infty, $fn=6);
-               // s1 hole
-               translate([s1_xoff, 0, base_h-pcb_groove + pcb_width/2])
-                       rotate([90, 0, 0])
-                       cylinder(r=uswitch_diam/2, h = infty, $fn=6);
-               // xy plane
-               translate([0, 0, -infty/2]) cube(infty, center=true);
-       }
-};
-
-translate([0, -19, 0])
-       main($fn=128);
-
 /*
-translate([0, 19, 0])
-       cover_hole();
+color("lightblue", 0.2)
+       translate([-65/2, 0, 0])
+       rotate([0, 90, 0])
+       cylinder(r=18/2, h=65);
 */
+translate([0, 30, 0]) case($fn=128);
+lid($fn=128);
 
-// cover($fn=128);
-// translate([0, 17, batt_diam + 3*wall + cover_sep])
-// rotate([180, 0, 0])
-//     cover($fn=128);
 
-translate([0, 19, 0]) {
-       if (lowres == 1) {
-               cover($fn=16);
-       } else {
-               cover($fn=128);
-       }
-}