// ============================================
// SaltyLab — Sensor Tower Top
// 120×120×10mm ASA
// Mounts RPLIDAR A1 on top of 2020 spine
// ============================================
include <dimensions.scad>

top_w = 120;
top_d = 120;
top_h = 10;
base_h = 4;

module sensor_tower_top() {
    difference() {
        union() {
            // Circular plate (RPLIDAR needs 360° clearance)
            cylinder(d=top_w, h=base_h, $fn=60);
            
            // RPLIDAR standoffs (4x M2.5 on 67mm bolt circle)
            for (i = [0:3]) {
                angle = i * 90 + 45;  // 45° offset
                translate([cos(angle) * lidar_mount_circle/2,
                           sin(angle) * lidar_mount_circle/2, 0])
                    cylinder(d=6, h=top_h, $fn=25);
            }
            
            // 2020 extrusion socket (bottom center)
            translate([-extrusion_w/2 - wall, -extrusion_w/2 - wall, -15])
                cube([extrusion_w + wall*2, extrusion_w + wall*2, 15]);
        }
        
        // RPLIDAR M2.5 through-holes
        for (i = [0:3]) {
            angle = i * 90 + 45;
            translate([cos(angle) * lidar_mount_circle/2,
                       sin(angle) * lidar_mount_circle/2, -1])
                cylinder(d=lidar_hole_dia, h=top_h + 2, $fn=25);
        }
        
        // Center hole (RPLIDAR motor shaft clearance + cable routing)
        translate([0, 0, -1])
            cylinder(d=25, h=base_h + 2, $fn=40);
        
        // 2020 extrusion socket (square hole)
        translate([-extrusion_w/2 - tol, -extrusion_w/2 - tol, -16])
            cube([extrusion_w + tol*2, extrusion_w + tol*2, 16]);
        
        // Set screw holes for extrusion (M3, 2x perpendicular)
        for (angle = [0, 90]) {
            rotate([0, 0, angle])
                translate([0, extrusion_w/2 + wall, -7.5])
                    rotate([90, 0, 0])
                        cylinder(d=m3_clear, h=wall + 5, $fn=25);
        }
    }
}

sensor_tower_top();
