620 lines
24 KiB
HTML
620 lines
24 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
|
|
<title>Microduck UNO Q Controller</title>
|
|
<style>
|
|
:root {
|
|
--bg: #0f1117;
|
|
--panel: #191d27;
|
|
--ink: #f6f4ed;
|
|
--muted: #98a2b3;
|
|
--accent: #ff7a2f;
|
|
--accent-dark: #c95212;
|
|
--danger: #e53935;
|
|
--ok: #2ecc71;
|
|
--warn: #f39c12;
|
|
--border: #2a3142;
|
|
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
}
|
|
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
|
body {
|
|
margin: 0;
|
|
background: var(--bg);
|
|
color: var(--ink);
|
|
font-family: var(--mono);
|
|
overflow-x: hidden;
|
|
min-height: 100vh;
|
|
}
|
|
.topbar {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
padding: 10px 14px;
|
|
background: var(--panel);
|
|
border-bottom: 2px solid var(--border);
|
|
}
|
|
.brand { font-weight: 700; font-size: 15px; letter-spacing: 0.04em; color: var(--accent); }
|
|
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }
|
|
.badge {
|
|
padding: 3px 8px;
|
|
border-radius: 999px;
|
|
border: 1px solid var(--border);
|
|
background: #12151d;
|
|
}
|
|
.badge.ok { border-color: var(--ok); color: var(--ok); }
|
|
.badge.warn { border-color: var(--warn); color: var(--warn); }
|
|
.badge.danger { border-color: var(--danger); color: var(--danger); }
|
|
.tabs { display: flex; gap: 6px; }
|
|
.tab-btn {
|
|
padding: 6px 12px;
|
|
background: #12151d;
|
|
color: var(--muted);
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
font-family: inherit;
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
}
|
|
.tab-btn.active { background: var(--accent); color: #08080c; border-color: var(--accent); }
|
|
.safety-bar {
|
|
display: grid;
|
|
grid-template-columns: 1.3fr 1.2fr 1fr 1fr;
|
|
gap: 8px;
|
|
padding: 10px 14px;
|
|
background: #141821;
|
|
border-bottom: 1px solid var(--border);
|
|
align-items: center;
|
|
}
|
|
@media (max-width: 720px) {
|
|
.safety-bar { grid-template-columns: 1fr 1fr; }
|
|
}
|
|
button.btn {
|
|
font-family: inherit;
|
|
font-weight: 700;
|
|
font-size: 13px;
|
|
border-radius: 8px;
|
|
border: 1px solid var(--border);
|
|
padding: 10px 12px;
|
|
background: var(--panel);
|
|
color: var(--ink);
|
|
cursor: pointer;
|
|
}
|
|
button.btn:active { transform: translateY(1px); }
|
|
button.btn:disabled { opacity: 0.4; cursor: not-allowed; }
|
|
button.btn-estop {
|
|
background: var(--danger);
|
|
border-color: #ff6b6b;
|
|
color: #fff;
|
|
font-size: 15px;
|
|
letter-spacing: 0.06em;
|
|
}
|
|
button.btn-stand {
|
|
background: var(--accent);
|
|
border-color: #ffa573;
|
|
color: #08080c;
|
|
}
|
|
.toggle-box, .slider-box {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
font-size: 11px;
|
|
color: var(--muted);
|
|
background: var(--panel);
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
padding: 6px 10px;
|
|
}
|
|
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--ink); font-size: 12px; }
|
|
.main { padding: 12px 14px; }
|
|
.hidden { display: none !important; }
|
|
.control-grid {
|
|
display: grid;
|
|
grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr);
|
|
gap: 14px;
|
|
align-items: stretch;
|
|
}
|
|
@media (max-width: 700px) {
|
|
.control-grid { grid-template-columns: 1fr; }
|
|
}
|
|
.card {
|
|
background: var(--panel);
|
|
border: 1px solid var(--border);
|
|
border-radius: 10px;
|
|
padding: 12px;
|
|
}
|
|
.card-title { font-size: 12px; color: var(--muted); margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.06em; }
|
|
.stick-zone {
|
|
position: relative;
|
|
height: 250px;
|
|
border-radius: 10px;
|
|
background: radial-gradient(circle at center, #202636 0%, #11151f 75%);
|
|
border: 1px dashed #374151;
|
|
touch-action: none;
|
|
user-select: none;
|
|
overflow: hidden;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.stick-hint { color: var(--muted); font-size: 12px; pointer-events: none; text-align: center; padding: 12px; }
|
|
.stick-base {
|
|
position: absolute;
|
|
width: 112px;
|
|
height: 112px;
|
|
border-radius: 50%;
|
|
border: 2px solid rgba(255, 122, 47, 0.75);
|
|
background: rgba(255, 122, 47, 0.08);
|
|
transform: translate(-50%, -50%);
|
|
pointer-events: none;
|
|
}
|
|
.stick-knob {
|
|
position: absolute;
|
|
width: 44px;
|
|
height: 44px;
|
|
border-radius: 50%;
|
|
background: var(--accent);
|
|
box-shadow: 0 0 16px rgba(255, 122, 47, 0.5);
|
|
transform: translate(-50%, -50%);
|
|
pointer-events: none;
|
|
}
|
|
.vel-readout { margin-top: 8px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
|
|
.skills-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
gap: 8px;
|
|
}
|
|
.skill-btn.active { background: var(--accent); color: #08080c; border-color: #ffa573; }
|
|
.head-panel { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
|
.calib-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
|
|
.joint-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
.joint-table th, .joint-table td { border-bottom: 1px solid var(--border); padding: 6px 4px; text-align: left; }
|
|
.joint-table input[type="number"] {
|
|
width: 64px;
|
|
background: #0f1117;
|
|
color: var(--ink);
|
|
border: 1px solid var(--border);
|
|
border-radius: 4px;
|
|
padding: 3px 5px;
|
|
font-family: inherit;
|
|
font-size: 12px;
|
|
}
|
|
.mini-btn {
|
|
padding: 4px 7px;
|
|
font-size: 11px;
|
|
border-radius: 5px;
|
|
border: 1px solid var(--border);
|
|
background: #12151d;
|
|
color: var(--ink);
|
|
font-family: inherit;
|
|
cursor: pointer;
|
|
}
|
|
.mini-btn:hover { border-color: var(--accent); }
|
|
.log-line { margin-top: 8px; font-size: 11px; color: var(--muted); word-break: break-word; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header class="topbar">
|
|
<div class="brand">MICRODUCK // UNO Q</div>
|
|
<div class="badges">
|
|
<span id="badge-life" class="badge warn">IDLE</span>
|
|
<span id="badge-mode" class="badge">Idle</span>
|
|
<span id="badge-ws" class="badge">WS ...</span>
|
|
<span id="badge-imu" class="badge">IMU --</span>
|
|
<span id="badge-batt" class="badge">--.-V</span>
|
|
<span id="badge-temp" class="badge">--C</span>
|
|
<span id="badge-hz" class="badge">--Hz</span>
|
|
</div>
|
|
<div class="tabs">
|
|
<button id="tab-ctrl" class="tab-btn active" type="button">Control</button>
|
|
<button id="tab-cal" class="tab-btn" type="button">Calibration</button>
|
|
</div>
|
|
</header>
|
|
|
|
<section class="safety-bar">
|
|
<button id="btn-estop" class="btn btn-estop" type="button">E-STOP (TORQUE OFF)</button>
|
|
<button id="btn-stand" class="btn btn-stand" type="button">Prepare Stand (1.5s)</button>
|
|
<label class="toggle-box">
|
|
<span>Recovery Policy</span>
|
|
<span class="toggle-row">
|
|
<span>Auto Stand on Fall</span>
|
|
<input id="chk-auto-stand" type="checkbox" />
|
|
</span>
|
|
</label>
|
|
<label class="slider-box">
|
|
<span>Speed Scale: <strong id="lbl-speed">50%</strong></span>
|
|
<input id="rng-speed" type="range" min="10" max="100" step="5" value="50" />
|
|
</label>
|
|
</section>
|
|
|
|
<main class="main">
|
|
<section id="view-control" class="control-grid">
|
|
<div class="card">
|
|
<h2 class="card-title">Virtual Joystick (Hold & Drag)</h2>
|
|
<div id="stick-zone" class="stick-zone">
|
|
<div id="stick-hint" class="stick-hint">Touch or drag anywhere here to walk / turn</div>
|
|
<div id="stick-base" class="stick-base hidden"></div>
|
|
<div id="stick-knob" class="stick-knob hidden"></div>
|
|
</div>
|
|
<div class="vel-readout">
|
|
<span id="lbl-vx">vx norm: 0.00</span>
|
|
<span id="lbl-wz">wz norm: 0.00</span>
|
|
</div>
|
|
|
|
<div id="head-panel" class="head-panel hidden">
|
|
<label class="slider-box">Neck Pitch <input id="hd-0" type="range" min="-1" max="1" step="0.05" value="0" /></label>
|
|
<label class="slider-box">Head Pitch <input id="hd-1" type="range" min="-1" max="1" step="0.05" value="0" /></label>
|
|
<label class="slider-box">Head Yaw <input id="hd-2" type="range" min="-1" max="1" step="0.05" value="0" /></label>
|
|
<label class="slider-box">Head Roll <input id="hd-3" type="range" min="-1" max="1" step="0.05" value="0" /></label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2 class="card-title">Skills & Modes</h2>
|
|
<div class="skills-grid">
|
|
<button class="btn skill-btn" data-action="sitStand" type="button">Sit / Stand</button>
|
|
<button class="btn skill-btn" data-action="head" id="btn-head" type="button">Head Mode</button>
|
|
<button class="btn skill-btn" data-action="kickL" type="button">Kick Left</button>
|
|
<button class="btn skill-btn" data-action="kickR" type="button">Kick Right</button>
|
|
<button class="btn skill-btn" data-action="groundPick" type="button">Ground Pick</button>
|
|
<button class="btn skill-btn" data-action="roll" id="btn-roll" type="button">Roll / Trick</button>
|
|
<button class="btn skill-btn" data-action="rollers" id="btn-rollers" type="button">Feet / Rollers</button>
|
|
<button class="btn skill-btn hidden" data-action="script" id="btn-script" type="button">Custom Script</button>
|
|
</div>
|
|
<div id="ctrl-log" class="log-line">Ready. Tap "Prepare Stand" when the robot is upright on the floor.</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section id="view-calib" class="card hidden">
|
|
<h2 class="card-title">Hardware Profile & Servo Calibration (IDLE Required for Joint Test)</h2>
|
|
<div class="calib-actions">
|
|
<button id="btn-ping" class="btn" type="button">Ping Servos (1-20)</button>
|
|
<button id="btn-imu-zero" class="btn" type="button">IMU Bias Zero (Keep Still)</button>
|
|
<button id="btn-exit-cal" class="btn" type="button">Exit Calibration (Torque Off)</button>
|
|
<button id="btn-save-prof" class="btn btn-stand" type="button">Save Profile to Robot</button>
|
|
</div>
|
|
<div id="calib-status" class="log-line">No ping scan yet.</div>
|
|
<div style="overflow-x:auto; margin-top:10px;">
|
|
<table class="joint-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Joint</th>
|
|
<th>ID</th>
|
|
<th>Sign</th>
|
|
<th>Offset</th>
|
|
<th>Live Tick</th>
|
|
<th>Live Rad</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="joint-tbody"></tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<script>
|
|
(() => {
|
|
const $ = (id) => document.getElementById(id);
|
|
let ws = null;
|
|
let reconnectTimer = null;
|
|
let profile = null;
|
|
let latestStatus = null;
|
|
const stickState = { active: false, pointerId: null, originX: 0, originY: 0, nx: 0, nwz: 0 };
|
|
const MAX_RADIUS = 56;
|
|
|
|
function log(msg) {
|
|
$("ctrl-log").textContent = msg;
|
|
}
|
|
|
|
async function apiPost(path, body) {
|
|
const res = await fetch(path, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body || {}),
|
|
});
|
|
const data = await res.json();
|
|
if (!res.ok || data.ok === false) {
|
|
throw new Error(data.error || `HTTP ${res.status}`);
|
|
}
|
|
return data;
|
|
}
|
|
|
|
function setTab(tab) {
|
|
const isCtrl = tab === "ctrl";
|
|
$("view-control").classList.toggle("hidden", !isCtrl);
|
|
$("view-calib").classList.toggle("hidden", isCtrl);
|
|
$("tab-ctrl").classList.toggle("active", isCtrl);
|
|
$("tab-cal").classList.toggle("active", !isCtrl);
|
|
if (!isCtrl) loadProfile();
|
|
}
|
|
|
|
$("tab-ctrl").onclick = () => setTab("ctrl");
|
|
$("tab-cal").onclick = () => setTab("cal");
|
|
|
|
function sendWs(obj) {
|
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
ws.send(JSON.stringify(obj));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function updateStatusUI(st) {
|
|
latestStatus = st;
|
|
const lifeEl = $("badge-life");
|
|
lifeEl.textContent = st.lifecycle || "UNKNOWN";
|
|
lifeEl.className = "badge " + (st.lifecycle === "ACTIVE" ? "ok" : st.lifecycle === "FALL_SAFE" ? "danger" : "warn");
|
|
$("badge-mode").textContent = st.mode_label || st.skill_mode || "-";
|
|
$("badge-imu").textContent = st.imu_ok ? "IMU OK" : "IMU ERR";
|
|
$("badge-imu").className = "badge " + (st.imu_ok ? "ok" : "danger");
|
|
$("badge-batt").textContent = `${Number(st.voltage_v || 0).toFixed(2)}V`;
|
|
$("badge-temp").textContent = `${Number(st.max_temp_c || 0).toFixed(0)}C`;
|
|
$("badge-hz").textContent = `${Number(st.ctrl_hz || 0).toFixed(0)}Hz`;
|
|
|
|
$("chk-auto-stand").checked = !!st.auto_stand_on_fall;
|
|
const spdPct = Math.round((st.speed_scale || 0.5) * 100);
|
|
if (document.activeElement !== $("rng-speed")) {
|
|
$("rng-speed").value = String(spdPct);
|
|
$("lbl-speed").textContent = `${spdPct}%`;
|
|
}
|
|
|
|
$("btn-head").classList.toggle("active", !!st.head_mode);
|
|
$("head-panel").classList.toggle("hidden", !st.head_mode);
|
|
$("btn-rollers").disabled = !st.rollers_enabled;
|
|
$("btn-rollers").classList.toggle("active", st.loco === "rollers");
|
|
const hasScript = !!(st.custom_move && st.custom_move.slot === "script");
|
|
$("btn-script").classList.toggle("hidden", !hasScript);
|
|
if (st.error) log(`Error: ${st.error}`);
|
|
|
|
if (st.ticks && st.joint_pos_rad && profile) {
|
|
Object.keys(profile.joints).forEach((name, idx) => {
|
|
const tCell = document.getElementById(`live-tick-${name}`);
|
|
const rCell = document.getElementById(`live-rad-${name}`);
|
|
if (tCell) tCell.textContent = String(st.ticks[idx] ?? "-");
|
|
if (rCell) rCell.textContent = Number(st.joint_pos_rad[idx] ?? 0).toFixed(3);
|
|
});
|
|
}
|
|
}
|
|
|
|
function connectWs() {
|
|
if (reconnectTimer) clearTimeout(reconnectTimer);
|
|
const proto = location.protocol === "https:" ? "wss:" : "ws:";
|
|
ws = new WebSocket(`${proto}//${location.host}/ws/control`);
|
|
ws.onopen = () => {
|
|
$("badge-ws").textContent = "WS LIVE";
|
|
$("badge-ws").className = "badge ok";
|
|
};
|
|
ws.onclose = () => {
|
|
$("badge-ws").textContent = "WS OFF";
|
|
$("badge-ws").className = "badge danger";
|
|
reconnectTimer = setTimeout(connectWs, 1000);
|
|
};
|
|
ws.onmessage = (evt) => {
|
|
try {
|
|
const msg = JSON.parse(evt.data);
|
|
if (msg.type === "telemetry") updateStatusUI(msg);
|
|
} catch (_) {}
|
|
};
|
|
}
|
|
|
|
// Safety & Skill controls
|
|
$("btn-estop").onclick = async () => {
|
|
sendWs({ type: "estop" });
|
|
try { updateStatusUI(await apiPost("/api/estop")); log("E-STOP activated (torque off)"); } catch (e) { log(e.message); }
|
|
};
|
|
$("btn-stand").onclick = async () => {
|
|
try { updateStatusUI(await apiPost("/api/stand")); log("Soft-start stand engaged..."); } catch (e) { log(e.message); }
|
|
};
|
|
$("chk-auto-stand").onchange = async (e) => {
|
|
try { updateStatusUI(await apiPost("/api/settings", { auto_stand_on_fall: e.target.checked })); } catch (err) { log(err.message); }
|
|
};
|
|
$("rng-speed").oninput = (e) => {
|
|
$("lbl-speed").textContent = `${e.target.value}%`;
|
|
};
|
|
$("rng-speed").onchange = async (e) => {
|
|
try { updateStatusUI(await apiPost("/api/settings", { speed_scale: Number(e.target.value) / 100 })); } catch (err) { log(err.message); }
|
|
};
|
|
|
|
document.querySelectorAll(".skill-btn").forEach((btn) => {
|
|
btn.onclick = async () => {
|
|
const action = btn.dataset.action;
|
|
try {
|
|
const res = await apiPost("/api/action", { action });
|
|
if (res.status) updateStatusUI(res.status);
|
|
log(res.ok ? `Triggered ${action}` : `Action '${action}' rejected in current state`);
|
|
} catch (e) { log(e.message); }
|
|
};
|
|
});
|
|
|
|
const sendHead = () => {
|
|
sendWs({
|
|
type: "head",
|
|
neck_pitch: Number($("hd-0").value),
|
|
head_pitch: Number($("hd-1").value),
|
|
head_yaw: Number($("hd-2").value),
|
|
head_roll: Number($("hd-3").value),
|
|
});
|
|
};
|
|
["hd-0", "hd-1", "hd-2", "hd-3"].forEach((id) => { $(id).oninput = sendHead; });
|
|
|
|
// Floating virtual joystick
|
|
const zone = $("stick-zone");
|
|
const base = $("stick-base");
|
|
const knob = $("stick-knob");
|
|
const hint = $("stick-hint");
|
|
|
|
function updateStickVisual(x, y) {
|
|
if (!stickState.active) {
|
|
base.classList.add("hidden");
|
|
knob.classList.add("hidden");
|
|
hint.classList.remove("hidden");
|
|
return;
|
|
}
|
|
hint.classList.add("hidden");
|
|
base.classList.remove("hidden");
|
|
knob.classList.remove("hidden");
|
|
base.style.left = `${stickState.originX}px`;
|
|
base.style.top = `${stickState.originY}px`;
|
|
knob.style.left = `${x}px`;
|
|
knob.style.top = `${y}px`;
|
|
}
|
|
|
|
function applyStickCoords(clientX, clientY) {
|
|
const rect = zone.getBoundingClientRect();
|
|
const px = clientX - rect.left;
|
|
const py = clientY - rect.top;
|
|
const dx = px - stickState.originX;
|
|
const dy = py - stickState.originY;
|
|
const dist = Math.hypot(dx, dy);
|
|
const clamped = dist > MAX_RADIUS ? MAX_RADIUS / dist : 1.0;
|
|
const cx = stickState.originX + dx * clamped;
|
|
const cy = stickState.originY + dy * clamped;
|
|
stickState.nx = -((cy - stickState.originY) / MAX_RADIUS);
|
|
stickState.nwz = -((cx - stickState.originX) / MAX_RADIUS);
|
|
$("lbl-vx").textContent = `vx norm: ${stickState.nx.toFixed(2)}`;
|
|
$("lbl-wz").textContent = `wz norm: ${stickState.nwz.toFixed(2)}`;
|
|
updateStickVisual(cx, cy);
|
|
}
|
|
|
|
function releaseStick() {
|
|
stickState.active = false;
|
|
stickState.pointerId = null;
|
|
stickState.nx = 0;
|
|
stickState.nwz = 0;
|
|
$("lbl-vx").textContent = "vx norm: 0.00";
|
|
$("lbl-wz").textContent = "wz norm: 0.00";
|
|
updateStickVisual(0, 0);
|
|
sendWs({ type: "input", vx: 0, wz: 0, speed_scale: Number($("rng-speed").value) / 100 });
|
|
}
|
|
|
|
zone.addEventListener("pointerdown", (e) => {
|
|
const rect = zone.getBoundingClientRect();
|
|
stickState.active = true;
|
|
stickState.pointerId = e.pointerId;
|
|
stickState.originX = e.clientX - rect.left;
|
|
stickState.originY = e.clientY - rect.top;
|
|
zone.setPointerCapture(e.pointerId);
|
|
applyStickCoords(e.clientX, e.clientY);
|
|
});
|
|
zone.addEventListener("pointermove", (e) => {
|
|
if (!stickState.active || e.pointerId !== stickState.pointerId) return;
|
|
applyStickCoords(e.clientX, e.clientY);
|
|
});
|
|
zone.addEventListener("pointerup", (e) => {
|
|
if (e.pointerId === stickState.pointerId) releaseStick();
|
|
});
|
|
zone.addEventListener("pointercancel", releaseStick);
|
|
|
|
setInterval(() => {
|
|
if (stickState.active) {
|
|
sendWs({
|
|
type: "input",
|
|
vx: stickState.nx,
|
|
wz: stickState.nwz,
|
|
speed_scale: Number($("rng-speed").value) / 100,
|
|
});
|
|
}
|
|
}, 50);
|
|
|
|
// Calibration helpers
|
|
function renderJointTable() {
|
|
const tbody = $("joint-tbody");
|
|
tbody.innerHTML = "";
|
|
if (!profile || !profile.joints) return;
|
|
Object.entries(profile.joints).forEach(([name, cfg]) => {
|
|
const tr = document.createElement("tr");
|
|
tr.innerHTML = `
|
|
<td>${name}</td>
|
|
<td><input type="number" min="0" max="253" value="${cfg.id}" data-j="${name}" data-f="id" /></td>
|
|
<td><button class="mini-btn" type="button" data-flip="${name}">${cfg.sign > 0 ? "+1" : "-1"}</button></td>
|
|
<td><input type="number" min="-4096" max="4096" value="${cfg.zero_offset_ticks}" data-j="${name}" data-f="zero_offset_ticks" /></td>
|
|
<td id="live-tick-${name}">-</td>
|
|
<td id="live-rad-${name}">0.000</td>
|
|
<td>
|
|
<button class="mini-btn" type="button" data-zero="${name}">Zero</button>
|
|
<button class="mini-btn" type="button" data-test="${name}" data-rad="-0.2">-0.2</button>
|
|
<button class="mini-btn" type="button" data-test="${name}" data-rad="0">0</button>
|
|
<button class="mini-btn" type="button" data-test="${name}" data-rad="0.2">+0.2</button>
|
|
</td>
|
|
`;
|
|
tbody.appendChild(tr);
|
|
});
|
|
|
|
tbody.querySelectorAll("input[data-j]").forEach((inp) => {
|
|
inp.onchange = () => {
|
|
profile.joints[inp.dataset.j][inp.dataset.f] = Number(inp.value);
|
|
};
|
|
});
|
|
tbody.querySelectorAll("button[data-flip]").forEach((btn) => {
|
|
btn.onclick = () => {
|
|
const j = profile.joints[btn.dataset.flip];
|
|
j.sign = j.sign > 0 ? -1 : 1;
|
|
btn.textContent = j.sign > 0 ? "+1" : "-1";
|
|
};
|
|
});
|
|
tbody.querySelectorAll("button[data-zero]").forEach((btn) => {
|
|
btn.onclick = async () => {
|
|
try {
|
|
const res = await apiPost("/api/calibrate/joint_zero", { joint: btn.dataset.zero });
|
|
profile = res.profile;
|
|
renderJointTable();
|
|
$("calib-status").textContent = `Captured current tick as zero for ${btn.dataset.zero}`;
|
|
} catch (e) { $("calib-status").textContent = `Error: ${e.message}`; }
|
|
};
|
|
});
|
|
tbody.querySelectorAll("button[data-test]").forEach((btn) => {
|
|
btn.onclick = async () => {
|
|
try {
|
|
await apiPost("/api/calibrate/test_joint", { joint: btn.dataset.test, rad: Number(btn.dataset.rad) });
|
|
$("calib-status").textContent = `Commanded ${btn.dataset.test} -> ${btn.dataset.rad} rad`;
|
|
} catch (e) { $("calib-status").textContent = `Error: ${e.message}`; }
|
|
};
|
|
});
|
|
}
|
|
|
|
async function loadProfile() {
|
|
const res = await fetch("/api/profile");
|
|
const data = await res.json();
|
|
profile = data.profile;
|
|
renderJointTable();
|
|
}
|
|
|
|
$("btn-ping").onclick = async () => {
|
|
try {
|
|
const res = await apiPost("/api/calibrate/ping", { max_id: 20 });
|
|
$("calib-status").textContent = `Responding IDs (${res.ids.length}): [${res.ids.join(", ")}]`;
|
|
} catch (e) { $("calib-status").textContent = `Ping error: ${e.message}`; }
|
|
};
|
|
$("btn-imu-zero").onclick = async () => {
|
|
try {
|
|
$("calib-status").textContent = "Sampling IMU bias (keep robot stationary)...";
|
|
const res = await apiPost("/api/calibrate/imu_zero", { samples: 200 });
|
|
if (profile) profile.imu = res.imu;
|
|
$("calib-status").textContent = `IMU gyro bias updated: [${res.imu.gyro_bias_rad_s.map((x) => x.toFixed(4)).join(", ")}]`;
|
|
} catch (e) { $("calib-status").textContent = `IMU zero error: ${e.message}`; }
|
|
};
|
|
$("btn-exit-cal").onclick = async () => {
|
|
try { updateStatusUI(await apiPost("/api/calibrate/exit")); $("calib-status").textContent = "Exited calibration (torque off)"; } catch (e) { $("calib-status").textContent = e.message; }
|
|
};
|
|
$("btn-save-prof").onclick = async () => {
|
|
if (!profile) return;
|
|
try {
|
|
const res = await apiPost("/api/profile", profile);
|
|
profile = res.profile;
|
|
renderJointTable();
|
|
$("calib-status").textContent = "Saved hardware_profile.json to UNO Q.";
|
|
} catch (e) { $("calib-status").textContent = `Save error: ${e.message}`; }
|
|
};
|
|
|
|
fetch("/api/status").then((r) => r.json()).then(updateStatusUI).catch(() => {});
|
|
connectWs();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|