At1uri's picture
Upload folder using huggingface_hub
d870d9a verified
Raw History Blame Contribute Delete
38.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Robotics Diffusion Policy Studio | Embodied AI & Control</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
<!-- KaTeX -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/contrib/auto-render.min.js"></script>
<style>
body {
background-color: #0b0c10;
color: #f1f5f9;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.glass-card {
background: rgba(18, 20, 28, 0.82);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.code-font {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
canvas {
border-radius: 1rem;
background: radial-gradient(circle at 30% 50%, #151924 0%, #090a0f 100%);
cursor: crosshair;
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #0b0c10;
}
::-webkit-scrollbar-thumb {
background: #374151;
border-radius: 4px;
}
</style>
</head>
<body class="min-h-screen flex flex-col antialiased selection:bg-amber-500 selection:text-black">
<!-- Top Navigation Header -->
<header class="border-b border-gray-800 bg-[#0e1017] sticky top-0 z-50">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3.5 flex items-center justify-between">
<div class="flex items-center space-x-3">
<div class="h-10 w-10 rounded-xl bg-gradient-to-tr from-amber-500 via-orange-600 to-red-600 flex items-center justify-center text-white font-bold text-xl shadow-lg shadow-orange-500/20">
🦾
</div>
<div>
<div class="flex items-center space-x-2">
<span class="text-xl font-extrabold tracking-tight bg-gradient-to-r from-amber-400 via-orange-300 to-red-400 bg-clip-text text-transparent">Robotics Diffusion Policy Studio</span>
<span class="text-xs px-2 py-0.5 rounded-full bg-amber-500/20 text-amber-300 border border-amber-500/30 font-medium">v1.0 Live</span>
</div>
<p class="text-xs text-gray-400">Embodied AI, Visuomotor DDIM Control & 3-DOF Inverse Kinematics</p>
</div>
</div>
<!-- Navigation Tabs -->
<nav class="hidden md:flex space-x-1 bg-gray-900/80 p-1 rounded-xl border border-gray-800 text-sm">
<button onclick="switchTab('arena')" id="tab-btn-arena" class="px-3.5 py-1.5 rounded-lg font-medium transition text-white bg-orange-600 shadow-sm">Robot Arena</button>
<button onclick="switchTab('multimodal')" id="tab-btn-multimodal" class="px-3.5 py-1.5 rounded-lg font-medium transition text-gray-400 hover:text-white">Mode Collapse Analysis</button>
<button onclick="switchTab('telemetry')" id="tab-btn-telemetry" class="px-3.5 py-1.5 rounded-lg font-medium transition text-gray-400 hover:text-white">Joint Telemetry</button>
<button onclick="switchTab('benchmarks')" id="tab-btn-benchmarks" class="px-3.5 py-1.5 rounded-lg font-medium transition text-gray-400 hover:text-white">LeRobot Benchmarks</button>
</nav>
<!-- External Links -->
<div class="flex items-center space-x-3">
<a href="https://huggingface.co/At1uri/visuomotor-diffusion-policy-engine" target="_blank" class="hidden sm:inline-flex items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-gray-800 hover:bg-gray-700 text-xs text-gray-200 border border-gray-700 transition">
<span>📦 Model</span>
</a>
<a href="https://huggingface.co/datasets/At1uri/robotic-manipulation-trajectory-benchmarks" target="_blank" class="hidden sm:inline-flex items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-gray-800 hover:bg-gray-700 text-xs text-gray-200 border border-gray-700 transition">
<span>📊 Dataset</span>
</a>
<a href="https://huggingface.co/At1uri" target="_blank" class="px-3.5 py-1.5 rounded-lg bg-gradient-to-r from-amber-600 to-red-600 hover:from-amber-500 hover:to-red-500 text-xs font-semibold text-white shadow-md shadow-orange-600/30 transition">
At1uri Suite
</a>
</div>
</div>
</header>
<!-- Main Container -->
<main class="flex-1 max-w-7xl w-full mx-auto px-4 sm:px-6 lg:px-8 py-6 space-y-6">
<!-- Control Bar -->
<section class="glass-card rounded-2xl p-5 border border-gray-800">
<div class="flex flex-col lg:flex-row lg:items-center justify-between gap-4 pb-4 border-b border-gray-800/80">
<div>
<span class="text-xs uppercase tracking-wider font-bold text-amber-400">Receding-Horizon Visuomotor Control</span>
<h2 class="text-lg font-semibold text-white">Policy Architecture & Denoising Controller</h2>
</div>
<div class="flex flex-wrap items-center gap-3">
<div class="flex items-center space-x-2">
<span class="text-xs text-gray-400">Active Policy:</span>
<select id="policy-select" onchange="resampleTrajectories()" class="bg-gray-900 border border-gray-700 text-amber-300 text-xs font-semibold rounded-xl px-3 py-2 focus:ring-2 focus:ring-amber-500 focus:outline-none">
<option value="diffusion">Diffusion Policy (DDIM-10 Multimodal Avoidance)</option>
<option value="mse">Classical Behavioral Cloning (MSE Mode Collapse)</option>
</select>
</div>
<button onclick="resampleTrajectories(true)" class="px-3.5 py-2 bg-gradient-to-r from-amber-600 to-orange-600 hover:from-amber-500 hover:to-orange-500 text-white text-xs font-semibold rounded-xl shadow-md shadow-orange-600/20 transition">
🎲 Resample Diffusion Seed
</button>
<button onclick="triggerDenoisingAnimation()" class="px-3.5 py-2 bg-gray-800 hover:bg-gray-700 border border-gray-700 text-amber-300 text-xs font-semibold rounded-xl transition">
▶ Animate DDIM ($k: 10 \to 0$)
</button>
</div>
</div>
<!-- Sliders & Live Telemetry Badges -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mt-4 text-xs">
<div class="bg-gray-900/70 p-3 rounded-xl border border-gray-800">
<div class="flex justify-between text-gray-300 mb-1">
<span>DDIM Denoising Step ($k$):</span>
<span id="step-val" class="font-mono font-bold text-amber-400">k = 0 (Clean)</span>
</div>
<input type="range" id="step-slider" min="0" max="10" step="1" value="0" oninput="setDenoisingStep(this.value)" class="w-full accent-amber-500">
</div>
<div class="bg-gray-900/70 p-3 rounded-xl border border-gray-800">
<div class="flex justify-between text-gray-300 mb-1">
<span>Obstacle Radius (m):</span>
<span id="obs-rad-val" class="font-mono font-bold text-red-400">0.12 m</span>
</div>
<input type="range" id="obs-rad-slider" min="0.06" max="0.20" step="0.01" value="0.12" oninput="updateObstacleRadius(this.value)" class="w-full accent-red-500">
</div>
<div class="bg-gray-900/70 p-3 rounded-xl border border-gray-800">
<span class="text-gray-400 block mb-0.5">Active Trajectory Mode:</span>
<span id="badge-mode" class="font-mono font-bold text-emerald-400 text-sm">UPPER_BYPASS</span>
<span id="badge-clearance" class="text-[11px] text-gray-400 block">Min Clearance: 0.14 m</span>
</div>
<div class="bg-gray-900/70 p-3 rounded-xl border border-gray-800 flex items-center justify-between">
<div>
<span class="block text-gray-400">Safety Status:</span>
<span id="badge-safety" class="text-sm font-bold text-emerald-400 font-mono">COLLISION-FREE</span>
</div>
<button onclick="toggleArmExecution()" id="play-arm-btn" class="px-3 py-1.5 bg-emerald-700 hover:bg-emerald-600 text-white rounded-lg text-xs font-semibold transition">
⏸ Pause Arm
</button>
</div>
</div>
</section>
<!-- TAB 1: LIVE ROBOTIC ARENA -->
<div id="content-arena" class="space-y-6">
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Canvas (2 Cols) -->
<div class="lg:col-span-2 glass-card rounded-2xl p-5 border border-amber-500/30 flex flex-col">
<div class="flex items-center justify-between mb-3">
<div>
<h3 class="text-md font-semibold text-white">3-DOF Articulated Manipulator & Action Chunk Denoising</h3>
<p class="text-xs text-gray-400">Click anywhere on workspace to move Green Target Goal • Drag Red Obstacle dynamically</p>
</div>
<span class="text-xs font-mono text-amber-300 px-2 py-0.5 rounded bg-amber-950 border border-amber-800">Horizon H=16</span>
</div>
<canvas id="robot-canvas" width="760" height="440" class="w-full h-[420px] border border-gray-800"></canvas>
<div class="mt-3 flex flex-wrap items-center justify-between text-[11px] text-gray-400 gap-2">
<div class="flex items-center space-x-4">
<span class="flex items-center space-x-1"><span class="w-2.5 h-2.5 rounded-full bg-amber-400"></span><span>Robot Arm (3-DOF IK)</span></span>
<span class="flex items-center space-x-1"><span class="w-2.5 h-2.5 rounded-full bg-emerald-400"></span><span>Active Action Chunk</span></span>
<span class="flex items-center space-x-1"><span class="w-2.5 h-2.5 rounded-full bg-sky-400/50"></span><span>Parallel DDIM Ensemble (20)</span></span>
<span class="flex items-center space-x-1"><span class="w-2.5 h-2.5 rounded-full bg-red-500"></span><span>Workspace Obstacle</span></span>
</div>
<span id="ik-error-label" class="font-mono text-gray-500">IK Residual: 0.0001 m</span>
</div>
</div>
<!-- Right Info & Equations -->
<div class="glass-card rounded-2xl p-5 border border-gray-800 flex flex-col justify-between space-y-4">
<div class="space-y-3">
<h3 class="text-md font-semibold text-white">Why Diffusion Policy Wins</h3>
<p class="text-xs text-gray-300 leading-relaxed">
When human teleoperators avoid an obstacle by going either <strong>above</strong> or <strong>below</strong>, a standard MSE neural policy averages both demonstrations—steering the end-effector straight into the obstacle!
</p>
<div class="p-3 rounded-xl bg-gray-950 border border-gray-800 text-xs text-gray-300 space-y-2">
<span class="text-amber-400 font-bold block">DDIM Reverse Denoising:</span>
<div>$$\mathbf{a}^{k-1} = \sqrt{\bar{\alpha}_{k-1}}\,\hat{\mathbf{a}}_0 + \sqrt{1 - \bar{\alpha}_{k-1}}\,\boldsymbol{\epsilon}_\theta(\mathbf{a}^k, \mathbf{o}_t, k)$$</div>
<span class="text-cyan-400 font-bold block pt-1">Damped Least Squares IK:</span>
<div>$$\Delta\mathbf{q} = \mathbf{J}^T(\mathbf{J}\mathbf{J}^T + \lambda^2 \mathbf{I})^{-1}\Delta\mathbf{x}$$</div>
</div>
</div>
<div class="p-3.5 rounded-xl bg-gray-900/90 border border-gray-800 text-xs font-mono space-y-1.5">
<div class="text-gray-400 text-[10px] uppercase font-sans font-bold">Live Joint State (Radians)</div>
<div class="flex justify-between"><span>Base Shoulder ($\theta_1$):</span><span id="hud-q1" class="text-amber-300">0.42 rad</span></div>
<div class="flex justify-between"><span>Elbow Joint ($\theta_2$):</span><span id="hud-q2" class="text-amber-300">-0.85 rad</span></div>
<div class="flex justify-between"><span>Wrist Pitch ($\theta_3$):</span><span id="hud-q3" class="text-amber-300">0.31 rad</span></div>
<div class="flex justify-between pt-1 border-t border-gray-800"><span>End-Effector $(x, y)$:</span><span id="hud-ee" class="text-emerald-300">(0.20, 0.00)</span></div>
</div>
</div>
</div>
</div>
<!-- TAB 2: MULTIMODAL MODE COLLAPSE ANALYSIS -->
<div id="content-multimodal" class="hidden space-y-6">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="glass-card rounded-2xl p-5 border border-gray-800 flex flex-col">
<h3 class="text-md font-semibold text-white mb-1">Midpoint Cross-Sectional Action Density $p(y_{\text{mid}} \mid \mathbf{o}_t)$</h3>
<p class="text-xs text-gray-400 mb-3">Bimodal Diffusion Policy peaks vs. Unimodal MSE Regression crashing directly into obstacle zone $[-R, +R]$.</p>
<div id="density-chart" class="w-full h-80 flex-1"></div>
</div>
<div class="glass-card rounded-2xl p-5 border border-gray-800 flex flex-col">
<h3 class="text-md font-semibold text-white mb-1">DDIM Noise Convergence Curve ($k=10 \to 0$)</h3>
<p class="text-xs text-gray-400 mb-3">Cosine noise schedule $\sqrt{1 - \bar{\alpha}_k}$ and ensemble variance contraction.</p>
<div id="ddim-convergence-chart" class="w-full h-80 flex-1"></div>
</div>
</div>
</div>
<!-- TAB 3: JOINT TELEMETRY -->
<div id="content-telemetry" class="hidden space-y-6">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="glass-card rounded-2xl p-5 border border-gray-800 flex flex-col">
<h3 class="text-md font-semibold text-white mb-1">Articulated 3-DOF Joint Trajectory Profiles</h3>
<p class="text-xs text-gray-400 mb-3">Smooth minimum-jerk joint angles $\theta_1(t), \theta_2(t), \theta_3(t)$ over action horizon $H=16$.</p>
<div id="joint-angles-chart" class="w-full h-80 flex-1"></div>
</div>
<div class="glass-card rounded-2xl p-5 border border-gray-800 flex flex-col">
<h3 class="text-md font-semibold text-white mb-1">Euclidean Obstacle Clearance Margin</h3>
<p class="text-xs text-gray-400 mb-3">Signed distance $d(\mathbf{x}_t, \mathcal{O}) - R_{\text{obs}}$ along the horizon (values $< 0$ indicate collision).</p>
<div id="clearance-chart" class="w-full h-80 flex-1"></div>
</div>
</div>
</div>
<!-- TAB 4: LEROBOT BENCHMARKS -->
<div id="content-benchmarks" class="hidden space-y-6">
<div class="glass-card rounded-2xl p-6 border border-gray-800 space-y-6">
<div>
<h3 class="text-lg font-semibold text-white">Embodied AI Manipulation Benchmark Suite ($N=200$ Test Episodes)</h3>
<p class="text-xs text-gray-400">Success rate comparison across Push-T, Obstacle Reach, Pick & Place, Peg-in-Hole, and Bimanual Transfer.</p>
</div>
<div id="benchmark-bar-chart" class="w-full h-72"></div>
<div class="overflow-x-auto">
<table class="w-full text-left text-xs text-gray-300">
<thead class="bg-gray-900/80 uppercase text-gray-400 border-b border-gray-800">
<tr>
<th class="py-3 px-4">Policy Architecture</th>
<th class="py-3 px-4">Push-T</th>
<th class="py-3 px-4">Obstacle Reach</th>
<th class="py-3 px-4">Pick & Place</th>
<th class="py-3 px-4">Peg-in-Hole</th>
<th class="py-3 px-4">Inference Latency</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-800/60 font-mono">
<tr class="bg-amber-950/20">
<td class="py-3 px-4 font-sans font-bold text-amber-300">Diffusion Policy (DDIM-10, Ours)</td>
<td class="py-3 px-4 text-emerald-400 font-bold">94.5%</td>
<td class="py-3 px-4 text-emerald-400 font-bold">98.0%</td>
<td class="py-3 px-4 text-emerald-400 font-bold">96.5%</td>
<td class="py-3 px-4 text-emerald-400 font-bold">91.0%</td>
<td class="py-3 px-4 text-white">11.4 ms</td>
</tr>
<tr>
<td class="py-3 px-4 font-sans text-white">Action Chunking Transformer (ACT)</td>
<td class="py-3 px-4">88.0%</td>
<td class="py-3 px-4">91.5%</td>
<td class="py-3 px-4">94.0%</td>
<td class="py-3 px-4">85.5%</td>
<td class="py-3 px-4">6.2 ms</td>
</tr>
<tr>
<td class="py-3 px-4 font-sans text-white">Implicit Behavioral Cloning (IBC)</td>
<td class="py-3 px-4">79.5%</td>
<td class="py-3 px-4">84.0%</td>
<td class="py-3 px-4">81.0%</td>
<td class="py-3 px-4">72.5%</td>
<td class="py-3 px-4">48.0 ms</td>
</tr>
<tr>
<td class="py-3 px-4 font-sans text-gray-400">Classical MSE Behavioral Cloning</td>
<td class="py-3 px-4 text-red-400">41.0%</td>
<td class="py-3 px-4 text-red-400">22.5%</td>
<td class="py-3 px-4">68.0%</td>
<td class="py-3 px-4 text-red-400">44.0%</td>
<td class="py-3 px-4">1.8 ms</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="border-t border-gray-800 bg-[#0e1017] py-6 text-xs text-gray-500 text-center">
<div class="max-w-7xl mx-auto px-4 flex flex-col sm:flex-row items-center justify-between gap-3">
<span>Robotics Diffusion Policy Studio &copy; 2026 Ramprasad Atluri (<a href="https://huggingface.co/At1uri" class="text-amber-400 hover:underline">At1uri</a>). Apache-2.0 License.</span>
<div class="flex space-x-4 text-gray-400">
<a href="https://huggingface.co/spaces/At1uri/robotics-diffusion-policy-studio" class="hover:text-white">Space</a>
<a href="https://huggingface.co/At1uri/visuomotor-diffusion-policy-engine" class="hover:text-white">Diffusion Engine</a>
<a href="https://huggingface.co/datasets/At1uri/robotic-manipulation-trajectory-benchmarks" class="hover:text-white">Benchmarks</a>
<a href="https://huggingface.co/collections/At1uri/institutional-quantitative-ai-suite-6aeeaed0365774ae33b9621e" class="hover:text-white">Collection</a>
</div>
</div>
</footer>
<!-- Interactive Robotics & Diffusion Engine JS -->
<script>
const canvas = document.getElementById('robot-canvas');
const ctx = canvas.getContext('2d');
// Coordinate transform: world meters [-0.2, 1.0] x [-0.5, 0.5] -> canvas pixels
const SCALE = 460;
const ORIGIN_X = 120;
const ORIGIN_Y = 220;
function toCanvas(wx, wy) {
return [ORIGIN_X + wx * SCALE, ORIGIN_Y - wy * SCALE];
}
function toWorld(cx, cy) {
return [(cx - ORIGIN_X) / SCALE, (ORIGIN_Y - cy) / SCALE];
}
// World State
const LINK_L = [0.44, 0.36, 0.24];
let startPt = [0.22, -0.30];
let goalPt = [0.76, 0.26];
let obsPt = [0.49, -0.02];
let obsRadius = 0.12;
let denoisingStepK = 0; // 0 = clean, 10 = pure noise
let activeBranchSign = 1; // +1 upper, -1 lower
let isArmPlaying = true;
let animPhase = 0;
let draggingObs = false;
let currentTab = 'arena';
let ensembleTrajs = []; // 20 parallel trajectories across k=0..10
let activeTrajClean = [];
let activeJointHistory = [];
// Gaussian PRNG
function randn() {
let u = 0, v = 0;
while (u === 0) u = Math.random();
while (v === 0) v = Math.random();
return Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
}
// Generate minimum-jerk quintic multimodal modes
function computeModes() {
const H = 16;
const dx = goalPt[0] - startPt[0];
const dy = goalPt[1] - startPt[1];
const dist = Math.hypot(dx, dy) + 1e-8;
const nx = -dy / dist;
const ny = dx / dist;
// Project obstacle onto segment to adapt lobe amplitude
const amp = obsRadius + 0.14;
const upper = [], lower = [], mse = [];
for (let i = 0; i < H; i++) {
const s = i / (H - 1);
const tau = 10 * s**3 - 15 * s**4 + 6 * s**5;
const bx = startPt[0] + tau * dx;
const by = startPt[1] + tau * dy;
const lobe = Math.sin(Math.PI * tau);
upper.push([bx + amp * lobe * nx, by + amp * lobe * ny]);
lower.push([bx - amp * lobe * nx, by - amp * lobe * ny]);
mse.push([bx, by]); // Averaged mode collapse!
}
return { upper, lower, mse };
}
function resampleTrajectories(flipBranch = false) {
const policy = document.getElementById('policy-select').value;
const modes = computeModes();
if (flipBranch) {
activeBranchSign = Math.random() < 0.5 ? 1 : -1;
}
ensembleTrajs = [];
for (let m = 0; m < 20; m++) {
let clean;
if (policy === 'mse') {
clean = modes.mse;
} else {
clean = (m % 2 === 0) ? modes.upper : modes.lower;
}
// Pre-sample fixed noise field per trajectory so scrubbing k is smooth
const noise = clean.map(() => [randn() * 0.22, randn() * 0.22]);
ensembleTrajs.push({ clean, noise });
}
if (policy === 'mse') {
activeTrajClean = modes.mse;
} else {
activeTrajClean = activeBranchSign > 0 ? modes.upper : modes.lower;
}
// Compute clearance & joint IK trajectory
let minC = 999;
activeJointHistory = [];
let prevQ = [0.4, -0.8, 0.3];
for (let pt of activeTrajClean) {
const c = Math.hypot(pt[0] - obsPt[0], pt[1] - obsPt[1]) - obsRadius;
if (c < minC) minC = c;
const ik = solveIK(pt[0], pt[1], prevQ);
prevQ = ik.q;
activeJointHistory.push({ q: ik.q, clearance: c, err: ik.err });
}
// Update HUD badges
const modeLabel = policy === 'mse' ? 'MSE_MODE_COLLAPSE' : (activeBranchSign > 0 ? 'UPPER_BYPASS' : 'LOWER_BYPASS');
document.getElementById('badge-mode').innerText = modeLabel;
document.getElementById('badge-mode').className = `font-mono font-bold text-sm ${policy === 'mse' ? 'text-red-400' : 'text-emerald-400'}`;
document.getElementById('badge-clearance').innerText = `Min Clearance: ${minC.toFixed(3)} m`;
const safeEl = document.getElementById('badge-safety');
if (minC > 0.0) {
safeEl.innerText = 'COLLISION-FREE';
safeEl.className = 'text-sm font-bold text-emerald-400 font-mono';
} else {
safeEl.innerText = 'COLLISION ALERT!';
safeEl.className = 'text-sm font-bold text-red-500 font-mono animate-pulse';
}
if (currentTab !== 'arena') renderCurrentTabCharts();
}
// 3-DOF Damped Least Squares Inverse Kinematics
function solveIK(tx, ty, initQ) {
let q = [...initQ];
let errNorm = 0;
const lam2 = 0.0025;
for (let iter = 0; iter < 45; iter++) {
const a1 = q[0], a2 = q[0] + q[1], a3 = q[0] + q[1] + q[2];
const x = LINK_L[0]*Math.cos(a1) + LINK_L[1]*Math.cos(a2) + LINK_L[2]*Math.cos(a3);
const y = LINK_L[0]*Math.sin(a1) + LINK_L[1]*Math.sin(a2) + LINK_L[2]*Math.sin(a3);
const ex = tx - x, ey = ty - y;
errNorm = Math.hypot(ex, ey);
if (errNorm < 1e-4) break;
const j00 = -LINK_L[0]*Math.sin(a1) - LINK_L[1]*Math.sin(a2) - LINK_L[2]*Math.sin(a3);
const j01 = -LINK_L[1]*Math.sin(a2) - LINK_L[2]*Math.sin(a3);
const j02 = -LINK_L[2]*Math.sin(a3);
const j10 = LINK_L[0]*Math.cos(a1) + LINK_L[1]*Math.cos(a2) + LINK_L[2]*Math.cos(a3);
const j11 = LINK_L[1]*Math.cos(a2) + LINK_L[2]*Math.cos(a3);
const j12 = LINK_L[2]*Math.cos(a3);
// A = J * J^T + lam^2 * I (2x2 matrix)
const a00 = j00*j00 + j01*j01 + j02*j02 + lam2;
const a01 = j00*j10 + j01*j11 + j02*j12;
const a11 = j10*j10 + j11*j11 + j12*j12 + lam2;
const det = a00 * a11 - a01 * a01 + 1e-12;
const vx = ( a11 * ex - a01 * ey) / det;
const vy = (-a01 * ex + a00 * ey) / det;
q[0] += 0.45 * (j00 * vx + j10 * vy);
q[1] += 0.45 * (j01 * vx + j11 * vy);
q[2] += 0.45 * (j02 * vx + j12 * vy);
}
return { q, err: errNorm };
}
function setDenoisingStep(k) {
denoisingStepK = parseInt(k);
document.getElementById('step-val').innerText = denoisingStepK === 0 ? 'k = 0 (Clean)' : `k = ${denoisingStepK} (Noisy)`;
}
function triggerDenoisingAnimation() {
let k = 10;
document.getElementById('step-slider').value = k;
setDenoisingStep(k);
const timer = setInterval(() => {
k--;
document.getElementById('step-slider').value = k;
setDenoisingStep(k);
if (k <= 0) clearInterval(timer);
}, 140);
}
function updateObstacleRadius(val) {
obsRadius = parseFloat(val);
document.getElementById('obs-rad-val').innerText = `${obsRadius.toFixed(2)} m`;
resampleTrajectories(false);
}
function toggleArmExecution() {
isArmPlaying = !isArmPlaying;
const btn = document.getElementById('play-arm-btn');
btn.innerText = isArmPlaying ? '⏸ Pause Arm' : '▶ Resume Arm';
}
function drawFrame() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw subtle workspace grid
ctx.strokeStyle = 'rgba(255,255,255,0.04)';
ctx.lineWidth = 1;
for (let gx = 0; gx < canvas.width; gx += 40) {
ctx.beginPath(); ctx.moveTo(gx, 0); ctx.lineTo(gx, canvas.height); ctx.stroke();
}
for (let gy = 0; gy < canvas.height; gy += 40) {
ctx.beginPath(); ctx.moveTo(0, gy); ctx.lineTo(canvas.width, gy); ctx.stroke();
}
// Cosine noise scaling for step k
const noiseScale = denoisingStepK / 10.0;
const signalScale = Math.sqrt(Math.max(0.05, 1.0 - noiseScale * noiseScale));
// Draw 20 parallel ensemble trajectories
ctx.lineWidth = 1.2;
for (let item of ensembleTrajs) {
ctx.strokeStyle = 'rgba(56, 189, 248, 0.25)';
ctx.beginPath();
item.clean.forEach((pt, idx) => {
const wx = pt[0] * signalScale + item.noise[idx][0] * noiseScale + (1 - signalScale) * 0.45;
const wy = pt[1] * signalScale + item.noise[idx][1] * noiseScale;
const [cx, cy] = toCanvas(wx, wy);
if (idx === 0) ctx.moveTo(cx, cy);
else ctx.lineTo(cx, cy);
});
ctx.stroke();
}
// Draw Obstacle
const [ox, oy] = toCanvas(obsPt[0], obsPt[1]);
ctx.beginPath();
ctx.arc(ox, oy, obsRadius * SCALE, 0, 2 * Math.PI);
ctx.fillStyle = 'rgba(239, 68, 68, 0.22)';
ctx.fill();
ctx.lineWidth = 2.5;
ctx.strokeStyle = '#ef4444';
ctx.stroke();
ctx.fillStyle = '#fca5a5';
ctx.font = 'bold 11px monospace';
ctx.textAlign = 'center';
ctx.fillText('OBSTACLE', ox, oy + 4);
// Draw Active Executed Trajectory
const policy = document.getElementById('policy-select').value;
ctx.lineWidth = 3;
ctx.strokeStyle = policy === 'mse' ? '#f87171' : '#10b981';
ctx.beginPath();
activeTrajClean.forEach((pt, idx) => {
const [cx, cy] = toCanvas(pt[0], pt[1]);
if (idx === 0) ctx.moveTo(cx, cy);
else ctx.lineTo(cx, cy);
});
ctx.stroke();
// Draw Start and Goal markers
const [sx, sy] = toCanvas(startPt[0], startPt[1]);
const [gx, gy] = toCanvas(goalPt[0], goalPt[1]);
ctx.beginPath(); ctx.arc(sx, sy, 6, 0, 2*Math.PI); ctx.fillStyle = '#94a3b8'; ctx.fill();
ctx.beginPath(); ctx.arc(gx, gy, 9, 0, 2*Math.PI); ctx.fillStyle = '#10b981'; ctx.fill();
ctx.strokeStyle = '#ecfdf5'; ctx.lineWidth = 2; ctx.stroke();
// Animate 3-DOF Robotic Arm along active trajectory
if (isArmPlaying) {
animPhase = (animPhase + 0.012) % 1.0;
}
const exactIdx = animPhase * (activeTrajClean.length - 1);
const i0 = Math.floor(exactIdx);
const i1 = Math.min(activeTrajClean.length - 1, i0 + 1);
const frac = exactIdx - i0;
const curX = activeTrajClean[i0][0] * (1 - frac) + activeTrajClean[i1][0] * frac;
const curY = activeTrajClean[i0][1] * (1 - frac) + activeTrajClean[i1][1] * frac;
const initQ = activeJointHistory[i0] ? activeJointHistory[i0].q : [0.4, -0.8, 0.3];
const ikRes = solveIK(curX, curY, initQ);
const q = ikRes.q;
// Forward Kinematics joint positions
const j0 = [0, 0];
const a1 = q[0], a2 = q[0] + q[1], a3 = q[0] + q[1] + q[2];
const j1 = [LINK_L[0]*Math.cos(a1), LINK_L[0]*Math.sin(a1)];
const j2 = [j1[0] + LINK_L[1]*Math.cos(a2), j1[1] + LINK_L[1]*Math.sin(a2)];
const j3 = [j2[0] + LINK_L[2]*Math.cos(a3), j2[1] + LINK_L[2]*Math.sin(a3)];
const pts = [j0, j1, j2, j3].map(p => toCanvas(p[0], p[1]));
// Draw robotic links
ctx.lineCap = 'round';
ctx.lineWidth = 10;
ctx.strokeStyle = '#334155';
ctx.beginPath();
ctx.moveTo(pts[0][0], pts[0][1]);
ctx.lineTo(pts[1][0], pts[1][1]);
ctx.lineTo(pts[2][0], pts[2][1]);
ctx.lineTo(pts[3][0], pts[3][1]);
ctx.stroke();
ctx.lineWidth = 4;
ctx.strokeStyle = '#f59e0b';
ctx.stroke();
// Draw servo joints
pts.forEach((p, idx) => {
ctx.beginPath();
ctx.arc(p[0], p[1], idx === 0 ? 11 : (idx === 3 ? 7 : 6), 0, 2*Math.PI);
ctx.fillStyle = idx === 3 ? '#10b981' : '#f8fafc';
ctx.fill();
ctx.lineWidth = 2;
ctx.strokeStyle = '#0f172a';
ctx.stroke();
});
// Update live telemetry HUD
document.getElementById('hud-q1').innerText = `${q[0].toFixed(3)} rad`;
document.getElementById('hud-q2').innerText = `${q[1].toFixed(3)} rad`;
document.getElementById('hud-q3').innerText = `${q[2].toFixed(3)} rad`;
document.getElementById('hud-ee').innerText = `(${j3[0].toFixed(2)}, ${j3[1].toFixed(2)})`;
document.getElementById('ik-error-label').innerText = `IK Residual: ${ikRes.err.toFixed(4)} m`;
requestAnimationFrame(drawFrame);
}
// Interactive Mouse Events on Canvas
canvas.addEventListener('mousedown', (e) => {
const rect = canvas.getBoundingClientRect();
const cx = (e.clientX - rect.left) * (canvas.width / rect.width);
const cy = (e.clientY - rect.top) * (canvas.height / rect.height);
const [wx, wy] = toWorld(cx, cy);
if (Math.hypot(wx - obsPt[0], wy - obsPt[1]) <= obsRadius + 0.04) {
draggingObs = true;
} else {
// Move Target Goal inside reachable workspace
const distBase = Math.hypot(wx, wy);
if (distBase < 0.96 && distBase > 0.25) {
goalPt = [wx, wy];
resampleTrajectories(false);
}
}
});
canvas.addEventListener('mousemove', (e) => {
if (!draggingObs) return;
const rect = canvas.getBoundingClientRect();
const cx = (e.clientX - rect.left) * (canvas.width / rect.width);
const cy = (e.clientY - rect.top) * (canvas.height / rect.height);
const [wx, wy] = toWorld(cx, cy);
obsPt = [Math.max(0.2, Math.min(0.85, wx)), Math.max(-0.35, Math.min(0.35, wy))];
resampleTrajectories(false);
});
window.addEventListener('mouseup', () => { draggingObs = false; });
// Tab Navigation
function switchTab(tabId) {
const tabs = ['arena', 'multimodal', 'telemetry', 'benchmarks'];
tabs.forEach(t => {
document.getElementById(`content-${t}`).classList.add('hidden');
const btn = document.getElementById(`tab-btn-${t}`);
btn.classList.remove('bg-orange-600', 'text-white', 'shadow-sm');
btn.classList.add('text-gray-400');
});
document.getElementById(`content-${tabId}`).classList.remove('hidden');
const activeBtn = document.getElementById(`tab-btn-${tabId}`);
activeBtn.classList.add('bg-orange-600', 'text-white', 'shadow-sm');
activeBtn.classList.remove('text-gray-400');
currentTab = tabId;
renderCurrentTabCharts();
}
function renderCurrentTabCharts() {
if (currentTab === 'multimodal') {
const yGrid = Array.from({length: 80}, (_, i) => -0.45 + (i / 79) * 0.90);
const diffDens = yGrid.map(y => 0.5 * Math.exp(-((y - 0.24)**2) / 0.004) + 0.5 * Math.exp(-((y + 0.24)**2) / 0.004));
const mseDens = yGrid.map(y => 0.9 * Math.exp(-(y**2) / 0.005));
Plotly.newPlot('density-chart', [
{ x: yGrid, y: diffDens, type: 'scatter', mode: 'lines', fill: 'tozeroy', name: 'Diffusion Policy (Bimodal Safe)', line: { color: '#10b981', width: 3 }, fillcolor: 'rgba(16,185,129,0.2)' },
{ x: yGrid, y: mseDens, type: 'scatter', mode: 'lines', fill: 'tozeroy', name: 'MSE BC (Collision Collapse)', line: { color: '#ef4444', width: 2.5, dash: 'dot' }, fillcolor: 'rgba(239,68,68,0.2)' }
], {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)',
margin: { l: 45, r: 20, t: 15, b: 40 },
xaxis: { title: { text: 'Midpoint Lateral Offset y (m)', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
yaxis: { title: { text: 'Action Density', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
legend: { font: { color: '#cbd5e1', size: 10 }, orientation: 'h', y: -0.25 }
}, { responsive: true, displayModeBar: false });
const steps = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
const sigma = steps.map(k => Math.sin((k / 10) * Math.PI * 0.5));
Plotly.newPlot('ddim-convergence-chart', [{
x: steps, y: sigma, type: 'scatter', mode: 'lines+markers',
line: { color: '#f59e0b', width: 3 }, marker: { size: 7, color: '#fbbf24' }
}], {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)',
margin: { l: 45, r: 20, t: 15, b: 40 },
xaxis: { title: { text: 'Reverse Diffusion Step k', font: { color: '#94a3b8', size: 11 } }, autorange: 'reversed', gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
yaxis: { title: { text: 'Noise Level sqrt(1 - alpha_bar)', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } }
}, { responsive: true, displayModeBar: false });
} else if (currentTab === 'telemetry') {
const tIdx = activeJointHistory.map((_, i) => i);
Plotly.newPlot('joint-angles-chart', [
{ x: tIdx, y: activeJointHistory.map(h => h.q[0]), name: 'Shoulder θ1', line: { color: '#f59e0b', width: 2.5 } },
{ x: tIdx, y: activeJointHistory.map(h => h.q[1]), name: 'Elbow θ2', line: { color: '#38bdf8', width: 2.5 } },
{ x: tIdx, y: activeJointHistory.map(h => h.q[2]), name: 'Wrist θ3', line: { color: '#a855f7', width: 2.5 } }
], {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)',
margin: { l: 45, r: 20, t: 15, b: 40 },
xaxis: { title: { text: 'Action Horizon Step t', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
yaxis: { title: { text: 'Joint Angle (rad)', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
legend: { font: { color: '#cbd5e1', size: 10 }, orientation: 'h', y: -0.25 }
}, { responsive: true, displayModeBar: false });
Plotly.newPlot('clearance-chart', [{
x: tIdx, y: activeJointHistory.map(h => h.clearance), type: 'scatter', mode: 'lines+markers',
fill: 'tozeroy', line: { color: '#10b981', width: 3 }, fillcolor: 'rgba(16,185,129,0.18)'
}], {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)',
margin: { l: 45, r: 20, t: 15, b: 40 },
xaxis: { title: { text: 'Action Horizon Step t', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
yaxis: { title: { text: 'Signed Clearance (m)', font: { color: '#94a3b8', size: 11 } }, gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } }
}, { responsive: true, displayModeBar: false });
} else if (currentTab === 'benchmarks') {
const tasks = ['Push-T', 'Obstacle Reach', 'Pick & Place', 'Peg-in-Hole'];
Plotly.newPlot('benchmark-bar-chart', [
{ x: tasks, y: [94.5, 98.0, 96.5, 91.0], name: 'Diffusion Policy (DDIM-10)', type: 'bar', marker: { color: '#f59e0b' } },
{ x: tasks, y: [88.0, 91.5, 94.0, 85.5], name: 'ACT Transformer', type: 'bar', marker: { color: '#38bdf8' } },
{ x: tasks, y: [41.0, 22.5, 68.0, 44.0], name: 'MSE Behavioral Cloning', type: 'bar', marker: { color: '#ef4444' } }
], {
barmode: 'group',
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)',
margin: { l: 45, r: 20, t: 15, b: 40 },
xaxis: { tickfont: { color: '#cbd5e1', size: 11 } },
yaxis: { title: { text: 'Task Success Rate (%)', font: { color: '#94a3b8', size: 11 } }, range: [0, 105], gridcolor: '#1f2937', tickfont: { color: '#94a3b8' } },
legend: { font: { color: '#cbd5e1', size: 10 }, orientation: 'h', y: -0.22 }
}, { responsive: true, displayModeBar: false });
}
}
window.addEventListener('DOMContentLoaded', () => {
resampleTrajectories(false);
requestAnimationFrame(drawFrame);
renderMathInElement(document.body, {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false}
]
});
});
</script>
</body>
</html>