// ============================================================
// rplidar_mount.scad — RPLIDAR A1M8 Anti-Vibration Ring  Rev A
// Agent: sl-mechanical   2026-02-28
// ============================================================
// Flat ring sits between platform and RPLIDAR A1M8.
// Anti-vibration isolation via 4× M3 silicone grommets
// (same type as FC vibration mounts — Ø6 mm silicone, M3).
//
// Bolt stack (bottom → top):
//   M3×30 SHCS → platform (8 mm) → grommet (8 mm) →
//   ring (4 mm) → RPLIDAR bottom (threaded M3, ~6 mm engagement)
//
// RENDER options:
//   "ring"       print-ready flat ring (default)
//   "assembly"   ring in position on platform stub
// ============================================================

RENDER = "ring";

// ── RPLIDAR A1M8 ─────────────────────────────────────────────
RPL_BODY_D  = 70.0;          // body diameter
RPL_BC      = 58.0;          // M3 mounting bolt circle

// ── Mount ring ───────────────────────────────────────────────
RING_OD     = 82.0;          // outer diameter (RPL_BODY_D + 12 mm)
RING_ID     = 30.0;          // inner cutout (cable / airflow)
RING_H      =  4.0;          // ring thickness

BOLT_D      =  3.3;          // M3 clearance through-hole
GROMMET_D   =  7.0;          // silicone grommet OD (seat recess on bottom)
GROMMET_H   =  1.0;          // seating recess depth

$fn = 64;
e   = 0.01;

// ─────────────────────────────────────────────────────────────
module rplidar_ring() {
    difference() {
        cylinder(d = RING_OD, h = RING_H);

        // Central cutout
        translate([0, 0, -e])
            cylinder(d = RING_ID, h = RING_H + 2*e);

        // 4× M3 clearance holes on bolt circle
        for (a = [45, 135, 225, 315]) {
            translate([RPL_BC/2 * cos(a), RPL_BC/2 * sin(a), -e])
                cylinder(d = BOLT_D, h = RING_H + 2*e);
        }

        // Grommet seating recesses — bottom face
        for (a = [45, 135, 225, 315]) {
            translate([RPL_BC/2 * cos(a), RPL_BC/2 * sin(a), -e])
                cylinder(d = GROMMET_D, h = GROMMET_H + e);
        }
    }
}

// ─────────────────────────────────────────────────────────────
// Render selector
// ─────────────────────────────────────────────────────────────
if (RENDER == "ring") {
    rplidar_ring();

} else if (RENDER == "assembly") {
    // Platform stub
    color("Silver", 0.5)
        difference() {
            cylinder(d = 90, h = 8);
            translate([0, 0, -e]) cylinder(d = 25.4, h = 8 + 2*e);
        }
    // Ring floating 8 mm above (grommet gap)
    color("SkyBlue", 0.9)
        translate([0, 0, 8 + 8])
            rplidar_ring();
}
