// ============================================
// SaltyLab — RealSense D435i Bracket
// 100×50×40mm PETG
// Adjustable tilt mount on 2020 extrusion
// ============================================
include <dimensions.scad>

bracket_w = 100;
bracket_d = 50;
bracket_h = 40;

// Camera cradle
cradle_w = rs_w + wall*2 + tol*2;
cradle_d = rs_d + wall + tol*2;
cradle_h = rs_h + 5;

module realsense_bracket() {
    // Extrusion clamp base
    difference() {
        union() {
            // Clamp block
            translate([-20, -20, 0])
                cube([40, 40, 15]);
            
            // Tilt arm (vertical, supports camera above)
            translate([-wall, -wall, 0])
                cube([wall*2, wall*2, bracket_h]);
            
            // Camera cradle at top
            translate([-cradle_w/2, -cradle_d/2, bracket_h - 5]) {
                difference() {
                    cube([cradle_w, cradle_d, cradle_h]);
                    
                    // Camera pocket
                    translate([wall, -1, 3])
                        cube([rs_w + tol*2, rs_d + tol*2 + 1, rs_h + tol*2]);
                }
            }
            
            // Tripod mount boss (1/4-20 bolt from bottom of cradle)
            translate([0, 0, bracket_h - 5])
                cylinder(d=15, h=3, $fn=30);
        }
        
        // 2020 extrusion channel
        translate([-extrusion_w/2 - tol, -extrusion_w/2 - tol, -1])
            cube([extrusion_w + tol*2, extrusion_w + tol*2, 17]);
        
        // Clamp bolt (M5, through side)
        translate([-25, 0, 7.5])
            rotate([0, 90, 0])
                cylinder(d=m5_clear, h=50, $fn=30);
        
        // Camera 1/4-20 bolt hole (from bottom of cradle)
        translate([0, 0, bracket_h - 6])
            cylinder(d=rs_mount_dia, h=10, $fn=30);
        
        // Cable routing slot (back of cradle)
        translate([-10, cradle_d/2 - wall - 1, bracket_h])
            cube([20, wall + 2, cradle_h - 2]);
    }
}

realsense_bracket();
