macbot 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- macbot/__init__.py +3 -0
- macbot/cameras/__init__.py +239 -0
- macbot/cameras/swift/uvc_stream.swift +83 -0
- macbot/cli.py +179 -0
- macbot/collect/__init__.py +0 -0
- macbot/collect/checks.py +36 -0
- macbot/collect/server.py +371 -0
- macbot/config.py +56 -0
- macbot/data/__init__.py +0 -0
- macbot/data/export.py +116 -0
- macbot/data/health.py +67 -0
- macbot/default.yaml +55 -0
- macbot/doctor.py +86 -0
- macbot/i18n.py +10 -0
- macbot/policy/__init__.py +0 -0
- macbot/policy/bench.py +28 -0
- macbot/policy/executors.py +222 -0
- macbot/policy/gripper.py +47 -0
- macbot/policy/models.py +158 -0
- macbot/policy/runner.py +345 -0
- macbot/robot/__init__.py +3 -0
- macbot/robot/fake.py +63 -0
- macbot/robot/gravity.py +108 -0
- macbot/robot/rebot.py +223 -0
- macbot/system.py +97 -0
- macbot/viz/__init__.py +0 -0
- macbot/viz/replay.py +113 -0
- macbot/viz/video.py +83 -0
- macbot/web/__init__.py +85 -0
- macbot/web/static/common.js +139 -0
- macbot/web/static/fonts/JetBrainsMono.ttf +0 -0
- macbot/web/static/fonts/OFL-JetBrainsMono.txt +93 -0
- macbot/web/static/logo-dark.svg +1 -0
- macbot/web/static/logo-mark.svg +1 -0
- macbot/web/static/logo.svg +1 -0
- macbot/web/static/theme.css +200 -0
- macbot/web/templates/_head.html +5 -0
- macbot/web/templates/collect.html +223 -0
- macbot/web/templates/replay.html +132 -0
- macbot/web/templates/run.html +124 -0
- macbot-0.1.0.dist-info/METADATA +183 -0
- macbot-0.1.0.dist-info/RECORD +46 -0
- macbot-0.1.0.dist-info/WHEEL +5 -0
- macbot-0.1.0.dist-info/entry_points.txt +2 -0
- macbot-0.1.0.dist-info/licenses/LICENSE +202 -0
- macbot-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
{{head}}
|
|
5
|
+
<title>macbot · collect</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<header class="topbar">
|
|
9
|
+
{{brand}}
|
|
10
|
+
<span class="crumb"><span data-i18n="collect">collect</span> · {{task}}</span>
|
|
11
|
+
<span id="badge" class="badge idle" data-i18n="connecting">connecting</span>
|
|
12
|
+
<span id="timer" class="num"></span>
|
|
13
|
+
<span class="spacer"></span>
|
|
14
|
+
<span class="chip" id="total"></span>
|
|
15
|
+
<button class="ghost lang" id="lang">中文</button>
|
|
16
|
+
<button class="danger" id="quit" data-i18n="quit">Quit & home</button>
|
|
17
|
+
</header>
|
|
18
|
+
|
|
19
|
+
<div class="wrap">
|
|
20
|
+
<div class="layout">
|
|
21
|
+
<div class="stack">
|
|
22
|
+
<div class="views" id="views"></div>
|
|
23
|
+
<div class="card" id="replay" style="display:none">
|
|
24
|
+
<h2 id="rtitle">replay</h2>
|
|
25
|
+
<div class="btn-row" style="align-items:center">
|
|
26
|
+
<button id="rplay" class="primary" data-i18n="play">Play</button>
|
|
27
|
+
<select id="rspeed"><option value="1">1×</option><option value="2">2×</option><option value="4">4×</option></select>
|
|
28
|
+
<input type="range" id="rslider" min="0" value="0" style="flex:1">
|
|
29
|
+
<span class="num" id="rpos"></span>
|
|
30
|
+
<button id="rclose" data-i18n="back_live">Back to live</button>
|
|
31
|
+
</div>
|
|
32
|
+
<div style="margin-top:12px"><svg class="plot" id="plot" viewBox="0 0 1000 190" preserveAspectRatio="none"></svg></div>
|
|
33
|
+
<div class="legend" id="legend"></div>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="card">
|
|
36
|
+
<h2 data-i18n="episodes">episodes</h2>
|
|
37
|
+
<div class="table-wrap"><table>
|
|
38
|
+
<thead><tr><th>#</th><th data-i18n="th_len"></th><th data-i18n="th_frames"></th><th data-i18n="th_ins"></th><th data-i18n="th_saved"></th><th data-i18n="th_check"></th><th></th></tr></thead>
|
|
39
|
+
<tbody id="eps"></tbody>
|
|
40
|
+
</table></div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<div class="stack">
|
|
45
|
+
<div class="card">
|
|
46
|
+
<h2 data-i18n="instruction">instruction</h2>
|
|
47
|
+
<textarea id="ins" spellcheck="false"></textarea>
|
|
48
|
+
<div class="btn-grid" style="margin-top:12px">
|
|
49
|
+
<button class="primary wide" id="bStart"><span data-i18n="record">Record</span> <kbd>S</kbd></button>
|
|
50
|
+
<button class="go" id="bSave"><span data-i18n="save">Save</span> <kbd>↵</kbd></button>
|
|
51
|
+
<button class="danger" id="bDiscard"><span data-i18n="discard">Discard</span> <kbd>←</kbd></button>
|
|
52
|
+
<button class="ghost wide" id="bIns" data-i18n="set_ins">Set instruction</button>
|
|
53
|
+
</div>
|
|
54
|
+
<div class="msg" id="msg"></div>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
<div class="card">
|
|
58
|
+
<h2 data-i18n="progress">progress</h2>
|
|
59
|
+
<div class="hp" id="hp"></div>
|
|
60
|
+
<div class="num" id="progN" style="font-size:12px;color:var(--mid)"></div>
|
|
61
|
+
<dl class="kv" id="camkv" style="margin-top:12px"></dl>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div class="card">
|
|
65
|
+
<h2><span data-i18n="joints">joints</span> <span class="hint" data-i18n="joints_hint"></span></h2>
|
|
66
|
+
<div id="joints"></div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<footer>macbot · <span data-i18n="tagline"></span></footer>
|
|
72
|
+
|
|
73
|
+
<script>
|
|
74
|
+
let S = null, epsKey = "", replay = null, insDirty = false, camsBuilt = false;
|
|
75
|
+
|
|
76
|
+
async function cmd(action, extra = {}) { render(await post("/api/cmd", { action, ...extra })); }
|
|
77
|
+
|
|
78
|
+
function buildViews(names, cams) {
|
|
79
|
+
layoutViews($("views"), names, c => cams[c].size);
|
|
80
|
+
for (const c of names) $("cam-" + c).onerror = () => { if (!replay) setTimeout(() => { if (!replay) $("cam-" + c).src = liveSrc(c); }, 1000); };
|
|
81
|
+
camsBuilt = true;
|
|
82
|
+
startLive();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function render(s) {
|
|
86
|
+
S = s;
|
|
87
|
+
if (!camsBuilt) buildViews(s.cam_names, s.cams);
|
|
88
|
+
const rec = s.phase === "recording";
|
|
89
|
+
const b = $("badge");
|
|
90
|
+
b.className = "badge " + (rec ? "rec" : (!s.ready ? "idle" : (s.fake ? "warn" : "live")));
|
|
91
|
+
b.textContent = t(rec ? "rec" : (s.ready ? (s.fake ? "simulated" : "ready") : "not_ready"));
|
|
92
|
+
$("timer").textContent = rec ? `${fmtTime(s.elapsed)} · ${s.frames} ${t("frames")}` : (s.saving ? t("saving") : "");
|
|
93
|
+
$("views").classList.toggle("hot", rec && !replay);
|
|
94
|
+
$("bStart").disabled = rec || !s.ready;
|
|
95
|
+
$("bSave").disabled = !rec; $("bDiscard").disabled = !rec;
|
|
96
|
+
$("bIns").disabled = rec; $("ins").disabled = rec;
|
|
97
|
+
if (!insDirty && document.activeElement !== $("ins")) $("ins").value = s.instruction;
|
|
98
|
+
$("msg").textContent = L(s.msg);
|
|
99
|
+
renderHP($("hp"), s.count / s.target);
|
|
100
|
+
$("progN").textContent = t("eps_of", s.count, s.target, s.fps);
|
|
101
|
+
$("total").textContent = t("saved_n", s.count);
|
|
102
|
+
$("camkv").innerHTML = s.cam_names.map(c => {
|
|
103
|
+
const i = s.cams[c];
|
|
104
|
+
return `<dt>${camLabel(c)}</dt><dd>${i.size[0]}×${i.size[1]}${i.crop ? ` · ${t("crop")} ${i.crop.join(",")}` : ` · ${t("full")}`}</dd>`;
|
|
105
|
+
}).join("") + `<dt>${t("data")}</dt><dd>${esc(s.out)}</dd>`;
|
|
106
|
+
for (const c of s.cam_names) {
|
|
107
|
+
const a = s.cam_age ? s.cam_age[c] : null;
|
|
108
|
+
if (!replay) camTag($("tag-" + c), c, a, s.stall_s);
|
|
109
|
+
$("age-" + c).textContent = a == null || replay ? "" : `${Math.round(a * 1000)} ms`;
|
|
110
|
+
}
|
|
111
|
+
renderJoints($("joints"), s.names, s.q, s.cmd, s.limits);
|
|
112
|
+
const key = JSON.stringify(s.episodes.map(e => [e.idx, e.frames, e.check]));
|
|
113
|
+
if (key !== epsKey) { epsKey = key; renderEps(s.episodes); }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function chk(c) {
|
|
117
|
+
if (!c) return `<td>–</td>`;
|
|
118
|
+
const detail = esc([...c.errors, ...c.warnings].map(L).join(LANG === "zh" ? ";" : "; "));
|
|
119
|
+
if (!c.ok) return `<td title="${detail}"><span class="pill bad">${t("fail")}</span> <small>${detail}</small></td>`;
|
|
120
|
+
if (c.warnings.length) return `<td title="${detail}"><span class="pill warn">${t("warn")}</span> <small>${detail}</small></td>`;
|
|
121
|
+
return `<td><span class="pill ok">${t("ok")}</span></td>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function renderEps(eps) {
|
|
125
|
+
if (!eps.length) { $("eps").innerHTML = `<tr><td colspan="7" class="empty">${t("no_eps")}</td></tr>`; return; }
|
|
126
|
+
$("eps").innerHTML = eps.map(e =>
|
|
127
|
+
`<tr data-idx="${e.idx}" class="${replay && replay.idx === e.idx ? "sel" : ""}">` +
|
|
128
|
+
`<td class="num">${String(e.idx).padStart(3, "0")}</td><td class="num">${(+e.dur).toFixed(1)} s</td>` +
|
|
129
|
+
`<td class="num">${e.frames}</td><td class="ins" title="${esc(e.instruction)}">${esc(e.instruction)}</td>` +
|
|
130
|
+
`<td class="num" style="color:var(--mid)">${esc(e.time)}</td>` + chk(e.check) +
|
|
131
|
+
`<td class="acts"><button data-act="play">${t("replay_btn")}</button> <button class="ghost" data-act="del">${t("del")}</button></td></tr>`
|
|
132
|
+
).join("");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
$("eps").addEventListener("click", ev => {
|
|
136
|
+
const b = ev.target.closest("button"); if (!b) return;
|
|
137
|
+
const idx = +b.closest("tr").dataset.idx;
|
|
138
|
+
if (b.dataset.act === "play") openReplay(idx);
|
|
139
|
+
if (b.dataset.act === "del" && confirm(t("confirm_del", idx))) {
|
|
140
|
+
if (replay && replay.idx === idx) closeReplay();
|
|
141
|
+
cmd("delete", { idx });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const liveSrc = c => `/stream/${c}.mjpg?t=${Date.now()}`;
|
|
146
|
+
function startLive() { if (S) for (const c of S.cam_names) $("cam-" + c).src = liveSrc(c); }
|
|
147
|
+
|
|
148
|
+
async function openReplay(idx) {
|
|
149
|
+
const d = await (await fetch(`/api/episode/${idx}`)).json();
|
|
150
|
+
replay = { idx, d, k: 0, playing: false };
|
|
151
|
+
$("replay").style.display = "";
|
|
152
|
+
$("views").classList.remove("hot");
|
|
153
|
+
$("rtitle").textContent = t("replay_title", String(idx).padStart(3, "0"), d.ts.at(-1).toFixed(1));
|
|
154
|
+
for (const c of S.cam_names) { $("tag-" + c).textContent = `${camLabel(c)} · ${t("replay")}`; $("tag-" + c).classList.remove("bad"); }
|
|
155
|
+
$("rslider").max = d.ts.length - 1;
|
|
156
|
+
drawTraces($("plot"), $("legend"), d.qpos, d.action, S.names);
|
|
157
|
+
seek(0);
|
|
158
|
+
renderEps(S.episodes);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function closeReplay() {
|
|
162
|
+
replay = null;
|
|
163
|
+
$("replay").style.display = "none";
|
|
164
|
+
$("rplay").textContent = t("play");
|
|
165
|
+
startLive();
|
|
166
|
+
renderEps(S.episodes);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function seek(k) {
|
|
170
|
+
if (!replay) return;
|
|
171
|
+
const n = replay.d.ts.length; k = Math.max(0, Math.min(n - 1, k)); replay.k = k;
|
|
172
|
+
for (const c of S.cam_names) $("cam-" + c).src = `/api/episode/${replay.idx}/${c}/${k}`;
|
|
173
|
+
$("rslider").value = k;
|
|
174
|
+
$("rpos").textContent = `${replay.d.ts[k].toFixed(2)} s · #${k}`;
|
|
175
|
+
moveCursor($("plot"), k, n);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
$("plot").addEventListener("click", ev => {
|
|
179
|
+
if (!replay) return;
|
|
180
|
+
const r = $("plot").getBoundingClientRect();
|
|
181
|
+
seek(Math.round((ev.clientX - r.left) / r.width * (replay.d.ts.length - 1)));
|
|
182
|
+
});
|
|
183
|
+
$("rslider").addEventListener("input", e => seek(+e.target.value));
|
|
184
|
+
$("rclose").onclick = closeReplay;
|
|
185
|
+
$("rplay").onclick = () => {
|
|
186
|
+
if (!replay) return;
|
|
187
|
+
replay.playing = !replay.playing; $("rplay").textContent = t(replay.playing ? "pause" : "play");
|
|
188
|
+
if (replay.playing && replay.k >= replay.d.ts.length - 1) seek(0);
|
|
189
|
+
};
|
|
190
|
+
setInterval(() => {
|
|
191
|
+
if (!replay || !replay.playing) return;
|
|
192
|
+
const last = replay.d.ts.length - 1;
|
|
193
|
+
if (replay.k >= last) { replay.playing = false; $("rplay").textContent = t("play"); return; }
|
|
194
|
+
seek(Math.min(last, replay.k + 2 * +$("rspeed").value)); // 30 fps data, 15 Hz timer
|
|
195
|
+
}, 1000 / 15);
|
|
196
|
+
|
|
197
|
+
$("bStart").onclick = () => cmd("start");
|
|
198
|
+
$("bSave").onclick = () => cmd("save");
|
|
199
|
+
$("bDiscard").onclick = () => cmd("discard");
|
|
200
|
+
$("bIns").onclick = () => { insDirty = false; cmd("instruction", { text: $("ins").value }); };
|
|
201
|
+
$("ins").addEventListener("input", () => { insDirty = true; });
|
|
202
|
+
$("quit").onclick = () => { if (confirm(t("confirm_quit"))) cmd("quit"); };
|
|
203
|
+
|
|
204
|
+
document.addEventListener("keydown", e => {
|
|
205
|
+
if (["INPUT", "SELECT", "TEXTAREA"].includes(e.target.tagName) || e.repeat) return;
|
|
206
|
+
if (e.key === "s" || e.key === "S") { if (replay) closeReplay(); cmd("start"); }
|
|
207
|
+
else if (e.key === "Enter" || e.key === "ArrowRight") { e.preventDefault(); document.activeElement?.blur?.(); cmd("save"); }
|
|
208
|
+
else if (e.key === "ArrowLeft") { e.preventDefault(); cmd("discard"); }
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
let lost = false;
|
|
212
|
+
async function poll() {
|
|
213
|
+
try {
|
|
214
|
+
render(await (await fetch("/api/status")).json());
|
|
215
|
+
if (lost) { lost = false; if (!replay) startLive(); }
|
|
216
|
+
} catch (e) { lost = true; $("badge").className = "badge idle"; $("badge").textContent = t("disconnected"); }
|
|
217
|
+
setTimeout(poll, 200);
|
|
218
|
+
}
|
|
219
|
+
window.onLang = () => { if (!S) return; epsKey = ""; render(S); if (replay) { const d = replay.d; drawTraces($("plot"), $("legend"), d.qpos, d.action, S.names); moveCursor($("plot"), replay.k, d.ts.length); $("rplay").textContent = t(replay.playing ? "pause" : "play"); } };
|
|
220
|
+
poll();
|
|
221
|
+
</script>
|
|
222
|
+
</body>
|
|
223
|
+
</html>
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
{{head}}
|
|
5
|
+
<title>macbot · replay</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<header class="topbar">
|
|
9
|
+
{{brand}}
|
|
10
|
+
<span class="crumb"><span data-i18n="replay">replay</span> · {{task}}</span>
|
|
11
|
+
<span id="badge" class="badge idle"></span>
|
|
12
|
+
<span class="spacer"></span>
|
|
13
|
+
<button class="ghost lang" id="lang">中文</button>
|
|
14
|
+
</header>
|
|
15
|
+
|
|
16
|
+
<div class="wrap">
|
|
17
|
+
<div class="layout">
|
|
18
|
+
<div class="stack">
|
|
19
|
+
<div class="views" id="views"></div>
|
|
20
|
+
<div class="card">
|
|
21
|
+
<h2 id="rtitle"></h2>
|
|
22
|
+
<div class="btn-row">
|
|
23
|
+
<button id="rplay" class="primary"><span data-i18n="play">Play</span> <kbd>␣</kbd></button>
|
|
24
|
+
<select id="rspeed"><option value="0.5">0.5×</option><option value="1" selected>1×</option><option value="2">2×</option><option value="4">4×</option></select>
|
|
25
|
+
<input type="range" id="rslider" min="0" value="0" style="flex:1">
|
|
26
|
+
<span class="num" id="rpos"></span>
|
|
27
|
+
</div>
|
|
28
|
+
<div style="margin-top:14px"><svg class="plot" id="plot" viewBox="0 0 1000 190" preserveAspectRatio="none"></svg></div>
|
|
29
|
+
<div class="legend" id="legend"></div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<div class="stack">
|
|
34
|
+
<div class="card">
|
|
35
|
+
<h2 data-i18n="status">status</h2>
|
|
36
|
+
<div class="tiles" id="tiles"></div>
|
|
37
|
+
<dl class="kv" id="info" style="margin-top:12px"></dl>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="card">
|
|
40
|
+
<h2 data-i18n="rollouts">rollouts</h2>
|
|
41
|
+
<div class="table-wrap"><table>
|
|
42
|
+
<thead><tr><th>#</th><th data-i18n="result"></th><th data-i18n="length"></th><th></th></tr></thead>
|
|
43
|
+
<tbody id="list"></tbody>
|
|
44
|
+
</table></div>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
<footer>macbot · <span data-i18n="tagline"></span></footer>
|
|
50
|
+
|
|
51
|
+
<script>
|
|
52
|
+
let LIST = [], R = null, name = null, k = 0, playing = false, timer = null;
|
|
53
|
+
const tile = (key, v, u = "") => `<div class="tile"><div class="k">${t(key)}</div><div class="v">${v}<small> ${u}</small></div></div>`;
|
|
54
|
+
|
|
55
|
+
function renderList() {
|
|
56
|
+
$("list").innerHTML = LIST.length ? LIST.map(r =>
|
|
57
|
+
`<tr data-n="${r.name}" class="${r.name === name ? "sel" : ""}" style="cursor:pointer">` +
|
|
58
|
+
`<td class="num">${r.name.split("_")[1]}</td>` +
|
|
59
|
+
`<td><span class="pill ${r.result === "success" ? "ok" : "bad"}">${t(r.result || "failure")}</span></td>` +
|
|
60
|
+
`<td class="num">${r.s} s</td><td class="acts"><button>${t("replay_btn")}</button></td></tr>`).join("")
|
|
61
|
+
: `<tr><td colspan="4" class="empty">${t("no_rollouts")}</td></tr>`;
|
|
62
|
+
}
|
|
63
|
+
$("list").addEventListener("click", e => { const tr = e.target.closest("tr[data-n]"); if (tr) openRollout(tr.dataset.n); });
|
|
64
|
+
|
|
65
|
+
async function openRollout(n) {
|
|
66
|
+
stop();
|
|
67
|
+
name = n;
|
|
68
|
+
R = await (await fetch(`/api/rollout/${n}`)).json();
|
|
69
|
+
layoutViews($("views"), R.cams, c => R.sizes[c]);
|
|
70
|
+
for (const c of R.cams) $("tag-" + c).textContent = `${camLabel(c)} · ${t("replay")}`;
|
|
71
|
+
const n0 = R.t.length, T = R.t.at(-1) || 1;
|
|
72
|
+
const marks = R.chunk_t.map(ct => { const x = (1000 * ct / T).toFixed(1);
|
|
73
|
+
return `<line x1="${x}" x2="${x}" y1="182" y2="190" stroke="currentColor" stroke-width="1" opacity=".45" vector-effect="non-scaling-stroke"/>`; }).join("");
|
|
74
|
+
drawTraces($("plot"), $("legend"), R.q, R.cmd, R.meta.joint_names, marks);
|
|
75
|
+
$("legend").innerHTML += `<span style="--c:transparent">${t("chunk_marks")}</span>`;
|
|
76
|
+
$("rslider").max = n0 - 1;
|
|
77
|
+
info();
|
|
78
|
+
renderList();
|
|
79
|
+
seek(0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function info() {
|
|
83
|
+
if (!R) return;
|
|
84
|
+
const m = R.meta, ok = m.result === "success";
|
|
85
|
+
$("badge").className = "badge " + (ok ? "live" : "rec");
|
|
86
|
+
$("badge").textContent = t(m.result || "failure");
|
|
87
|
+
$("rtitle").textContent = `${name} · ${(R.t.at(-1) || 0).toFixed(1)} s`;
|
|
88
|
+
$("tiles").innerHTML = tile("length", (R.t.at(-1) || 0).toFixed(1), "s") + tile("chunks", R.chunks) +
|
|
89
|
+
tile("infer", R.infer_ms == null ? "–" : Math.round(R.infer_ms), "ms") + tile("speed", `×${m.speed}`);
|
|
90
|
+
const p = String(m.policy || "").split("/").slice(-2).join("/");
|
|
91
|
+
$("info").innerHTML = `<dt>${t("policy")}</dt><dd>${esc(p)}</dd><dt>${t("executor")}</dt><dd>${esc(m.executor || m.mode || "")}</dd>` +
|
|
92
|
+
`<dt>${t("th_saved")}</dt><dd>${esc(m.saved_at || "")}</dd><dt>${t("instruction")}</dt><dd>${esc(m.instruction || "")}</dd>`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function seek(i) {
|
|
96
|
+
if (!R) return;
|
|
97
|
+
k = Math.max(0, Math.min(i, R.t.length - 1));
|
|
98
|
+
for (const c of R.cams) $("cam-" + c).src = `/api/rollout/${name}/${c}/${k}`;
|
|
99
|
+
$("rslider").value = k;
|
|
100
|
+
$("rpos").textContent = `${R.t[k].toFixed(2)} s`;
|
|
101
|
+
moveCursor($("plot"), k, R.t.length);
|
|
102
|
+
}
|
|
103
|
+
function stop() { playing = false; clearInterval(timer); $("rplay").firstElementChild.textContent = t("play"); }
|
|
104
|
+
function play() {
|
|
105
|
+
if (!R) return;
|
|
106
|
+
if (playing) return stop();
|
|
107
|
+
if (k >= R.t.length - 1) seek(0);
|
|
108
|
+
playing = true; $("rplay").firstElementChild.textContent = t("pause");
|
|
109
|
+
const fps = R.meta.fps || 30, sp = +$("rspeed").value, step = Math.max(1, Math.round(sp * fps / 15));
|
|
110
|
+
timer = setInterval(() => { if (k >= R.t.length - 1) return stop(); seek(k + step); }, 1000 * step / (sp * fps));
|
|
111
|
+
}
|
|
112
|
+
$("rplay").onclick = play;
|
|
113
|
+
$("rspeed").onchange = () => { if (playing) { stop(); play(); } };
|
|
114
|
+
$("rslider").oninput = e => { stop(); seek(+e.target.value); };
|
|
115
|
+
$("plot").addEventListener("click", e => { if (!R) return; const b = e.currentTarget.getBoundingClientRect();
|
|
116
|
+
stop(); seek(Math.round((e.clientX - b.left) / b.width * (R.t.length - 1))); });
|
|
117
|
+
document.addEventListener("keydown", e => {
|
|
118
|
+
if (["INPUT", "SELECT"].includes(e.target.tagName)) return;
|
|
119
|
+
if (e.key === " ") { e.preventDefault(); play(); }
|
|
120
|
+
else if (e.key === "ArrowRight") { stop(); seek(k + 1); } else if (e.key === "ArrowLeft") { stop(); seek(k - 1); }
|
|
121
|
+
});
|
|
122
|
+
window.onLang = () => { renderList(); if (R) { info(); for (const c of R.cams) $("tag-" + c).textContent = `${camLabel(c)} · ${t("replay")}`; } };
|
|
123
|
+
|
|
124
|
+
(async () => {
|
|
125
|
+
const r = await (await fetch("/api/rollouts")).json();
|
|
126
|
+
LIST = r.items;
|
|
127
|
+
renderList();
|
|
128
|
+
if (LIST.length) openRollout(LIST[0].name);
|
|
129
|
+
})();
|
|
130
|
+
</script>
|
|
131
|
+
</body>
|
|
132
|
+
</html>
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
{{head}}
|
|
5
|
+
<title>macbot · run</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<header class="topbar">
|
|
9
|
+
{{brand}}
|
|
10
|
+
<span class="crumb"><span data-i18n="run">run</span> · {{task}}</span>
|
|
11
|
+
<span id="badge" class="badge idle" data-i18n="connecting">connecting</span>
|
|
12
|
+
<span id="timer" class="num"></span>
|
|
13
|
+
<span class="spacer"></span>
|
|
14
|
+
<span class="chip" id="pol"></span>
|
|
15
|
+
<button class="ghost lang" id="lang">中文</button>
|
|
16
|
+
<button class="danger" id="quit" data-i18n="quit">Quit & home</button>
|
|
17
|
+
</header>
|
|
18
|
+
|
|
19
|
+
<div class="wrap">
|
|
20
|
+
<div class="layout">
|
|
21
|
+
<div class="stack">
|
|
22
|
+
<div class="views" id="views"></div>
|
|
23
|
+
<div class="card">
|
|
24
|
+
<div class="btn-row">
|
|
25
|
+
<button class="go" onclick="cmd('start')"><span data-i18n="start">Start</span> <kbd>S</kbd></button>
|
|
26
|
+
<button class="stop" onclick="cmd('pause')"><span data-i18n="hold">Pause</span> <kbd>␣</kbd></button>
|
|
27
|
+
<button onclick="cmd('home')"><span data-i18n="home">Home</span> <kbd>H</kbd></button>
|
|
28
|
+
<span class="spacer"></span>
|
|
29
|
+
<button class="primary" onclick="cmd('save_ok')"><span data-i18n="succ">Success</span> <kbd>Y</kbd></button>
|
|
30
|
+
<button onclick="cmd('save_fail')"><span data-i18n="failb">Failure</span> <kbd>N</kbd></button>
|
|
31
|
+
<button class="ghost" onclick="cmd('discard')" data-i18n="drop">Discard run</button>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="msg" id="msg"></div>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="card">
|
|
36
|
+
<h2><span data-i18n="recent">recent</span> <span class="hint" data-i18n="legend"></span></h2>
|
|
37
|
+
<svg class="plot" id="plot" viewBox="0 0 1000 190" preserveAspectRatio="none"></svg>
|
|
38
|
+
<div class="legend" id="legend"></div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="stack">
|
|
43
|
+
<div class="card">
|
|
44
|
+
<h2 data-i18n="status">status</h2>
|
|
45
|
+
<div class="tiles" id="tiles"></div>
|
|
46
|
+
<dl class="kv" style="margin-top:12px">
|
|
47
|
+
<dt data-i18n="executor">executor</dt><dd id="exec"></dd>
|
|
48
|
+
<dt data-i18n="policy">policy</dt><dd id="polp"></dd>
|
|
49
|
+
</dl>
|
|
50
|
+
</div>
|
|
51
|
+
<div class="card">
|
|
52
|
+
<h2><span data-i18n="joints">joints</span> <span class="hint" data-i18n="joints_hint"></span></h2>
|
|
53
|
+
<div id="joints"></div>
|
|
54
|
+
</div>
|
|
55
|
+
<div class="card">
|
|
56
|
+
<h2 data-i18n="trials">trials</h2>
|
|
57
|
+
<div class="table-wrap"><table><tbody id="saved"></tbody></table></div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
<footer>macbot · <span data-i18n="tagline"></span></footer>
|
|
63
|
+
|
|
64
|
+
<script>
|
|
65
|
+
let S = null, built = false, HQ = [], HC = [];
|
|
66
|
+
const HIST = 75; // samples kept for the trace (~15 s at the 200 ms poll)
|
|
67
|
+
const LIM = { shoulder_pan: [-145, 145], shoulder_lift: [-170, 0], elbow_flex: [-200, 0], wrist_flex: [-90, 80],
|
|
68
|
+
wrist_yaw: [-90, 90], wrist_roll: [-90, 90], gripper: [-270, 0] };
|
|
69
|
+
async function cmd(a) { render(await post("/api/cmd", { action: a })); }
|
|
70
|
+
|
|
71
|
+
function build(s) {
|
|
72
|
+
layoutViews($("views"), s.cam_names, c => s.cam_size[c]);
|
|
73
|
+
for (const c of s.cam_names) {
|
|
74
|
+
$("cam-" + c).src = `/stream/${c}.mjpg`;
|
|
75
|
+
$("cam-" + c).onerror = () => setTimeout(() => { $("cam-" + c).src = `/stream/${c}.mjpg?t=${Date.now()}`; }, 1000);
|
|
76
|
+
}
|
|
77
|
+
built = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function render(s) {
|
|
81
|
+
S = s;
|
|
82
|
+
if (!built) build(s);
|
|
83
|
+
const cls = { running: "run", paused: "warn", homing: "idle" }[s.mode] || "idle";
|
|
84
|
+
$("badge").className = "badge " + cls;
|
|
85
|
+
$("badge").textContent = t(s.mode) + (s.fake ? ` · ${t("simulated")}` : "");
|
|
86
|
+
$("views").classList.toggle("go", s.mode === "running");
|
|
87
|
+
$("timer").textContent = s.rec_s ? `${fmtTime(s.rec_s)}` : "";
|
|
88
|
+
$("msg").textContent = L(s.msg);
|
|
89
|
+
$("pol").textContent = s.policy;
|
|
90
|
+
$("exec").textContent = s.executor;
|
|
91
|
+
$("polp").textContent = s.policy;
|
|
92
|
+
const tile = (k, v, u = "") => `<div class="tile"><div class="k">${t(k)}</div><div class="v">${v}<small> ${u}</small></div></div>`;
|
|
93
|
+
$("tiles").innerHTML = tile("chunks", s.chunks) + tile("infer", s.infer_ms == null ? "–" : Math.round(s.infer_ms), "ms") +
|
|
94
|
+
tile("run_time", s.rec_s, "s") + tile("speed", `×${s.speed}`) + tile("next", `#${String(s.next).padStart(3, "0")}`);
|
|
95
|
+
for (const c of s.cam_names) {
|
|
96
|
+
const a = s.cam_age[c];
|
|
97
|
+
camTag($("tag-" + c), c, a, s.stall_s);
|
|
98
|
+
$("age-" + c).textContent = a == null ? "" : `${Math.round(a * 1000)} ms`;
|
|
99
|
+
}
|
|
100
|
+
renderJoints($("joints"), s.names, s.q, s.cmd, LIM);
|
|
101
|
+
if (s.mode === "running") { HQ.push(s.q); HC.push(s.cmd); if (HQ.length > HIST) { HQ.shift(); HC.shift(); } }
|
|
102
|
+
if (HQ.length > 1) { drawTraces($("plot"), $("legend"), HQ, HC, s.names.slice(0, 6)); $("legend").lastElementChild.remove(); moveCursor($("plot"), HQ.length - 1, HQ.length); }
|
|
103
|
+
$("saved").innerHTML = s.saved.length ? s.saved.slice().reverse().map(r =>
|
|
104
|
+
`<tr><td class="num">${r.name}</td><td><span class="pill ${r.result === "success" ? "ok" : "bad"}">${t(r.result)}</span></td><td class="num">${r.s} s</td></tr>`).join("")
|
|
105
|
+
: `<tr><td class="empty">${t("no_trials")}</td></tr>`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
$("quit").onclick = () => { if (confirm(t("confirm_quit"))) cmd("quit"); };
|
|
109
|
+
document.addEventListener("keydown", e => {
|
|
110
|
+
if (["INPUT", "SELECT", "TEXTAREA"].includes(e.target.tagName) || e.repeat) return;
|
|
111
|
+
const k = e.key.toLowerCase();
|
|
112
|
+
if (k === "s") cmd("start"); else if (k === " ") { e.preventDefault(); cmd("pause"); }
|
|
113
|
+
else if (k === "h") cmd("home"); else if (k === "y") cmd("save_ok"); else if (k === "n") cmd("save_fail");
|
|
114
|
+
});
|
|
115
|
+
window.onLang = () => { if (S) { for (const c of S.cam_names) $("tag-" + c).textContent = camLabel(c); render(S); } };
|
|
116
|
+
async function poll() {
|
|
117
|
+
try { render(await (await fetch("/api/status")).json()); }
|
|
118
|
+
catch (e) { $("badge").className = "badge idle"; $("badge").textContent = t("disconnected"); }
|
|
119
|
+
setTimeout(poll, 200);
|
|
120
|
+
}
|
|
121
|
+
poll();
|
|
122
|
+
</script>
|
|
123
|
+
</body>
|
|
124
|
+
</html>
|