// ============================================
// SaltyLab — Battery Shelf
// 200×100×40mm PETG
// Holds 36V battery pack low on the frame
// Mounts to 2020 extrusion spine
// ============================================
include <dimensions.scad>

shelf_w = 200;
shelf_d = 100;
shelf_h = 40;
floor_h = 3;     // Bottom plate

// Battery pocket (with tolerance)
pocket_w = batt_w + tol*2;
pocket_d = batt_d + tol*2;
pocket_h = batt_h + 5;  // Slightly taller than battery

// Velcro strap slots
strap_w = 25;
strap_h = 3;

module battery_shelf() {
    difference() {
        union() {
            // Floor
            translate([-shelf_w/2, -shelf_d/2, 0])
                cube([shelf_w, shelf_d, floor_h]);
            
            // Walls (3 sides — front open for wires)
            // Left wall
            translate([-shelf_w/2, -shelf_d/2, 0])
                cube([wall, shelf_d, shelf_h]);
            // Right wall
            translate([shelf_w/2 - wall, -shelf_d/2, 0])
                cube([wall, shelf_d, shelf_h]);
            // Back wall
            translate([-shelf_w/2, shelf_d/2 - wall, 0])
                cube([shelf_w, wall, shelf_h]);
            
            // Front lip (low, keeps battery from sliding out)
            translate([-shelf_w/2, -shelf_d/2, 0])
                cube([shelf_w, wall, 10]);
            
            // 2020 extrusion mount tabs (top of back wall)
            for (x = [-30, 30]) {
                translate([x - 10, shelf_d/2 - wall, shelf_h - 15])
                    cube([20, wall + 10, 15]);
            }
        }
        
        // Extrusion bolt holes (M5) through back mount tabs
        for (x = [-30, 30]) {
            translate([x, shelf_d/2 + 5, shelf_h - 7.5])
                rotate([90, 0, 0])
                    cylinder(d=m5_clear, h=wall + 15, $fn=30);
        }
        
        // Velcro strap slots (2x through floor for securing battery)
        for (x = [-50, 50]) {
            translate([x - strap_w/2, -20, -1])
                cube([strap_w, strap_h, floor_h + 2]);
        }
        
        // Weight reduction holes in floor
        for (x = [-30, 30]) {
            translate([x, 0, -1])
                cylinder(d=20, h=floor_h + 2, $fn=30);
        }
        
        // Wire routing slot (front wall, centered)
        translate([-20, -shelf_d/2 - 1, floor_h])
            cube([40, wall + 2, 15]);
    }
}

battery_shelf();
