board rotation - fix 0

This commit is contained in:
chk
2026-06-10 18:08:18 +02:00
parent 9105dc5eac
commit b1950ffa5a
5 changed files with 104 additions and 25 deletions

View File

@@ -354,6 +354,27 @@ async function loadBoardTable() {
// ── Board ─────────────────────────────────────────────────────────────────────
/** Befüllt alle Set-Dropdowns aus /api/robot/board-sets */
async function populateBoardSetDropdowns() {
let sets = [];
try {
const r = await fetch('/api/robot/board-sets');
if (r.ok) sets = (await r.json()).sets ?? [];
} catch { /* kein Server / noch keine Sets → leere Dropdowns */ }
// Hilfsfunktion: <select> mit Optionen füllen
function fill(selId, placeholder, selected = '') {
const sel = document.getElementById(selId);
if (!sel) return;
sel.innerHTML = `<option value="">${placeholder}</option>` +
sets.map(s => `<option value="${s}"${s === selected ? ' selected' : ''}>${s}</option>`).join('');
}
fill('board-ref-set', 'alle');
fill('act-align-fixed', ' bleibt ');
fill('act-align-move', ' verschoben ');
}
function initBoard() {
const logBoard = document.getElementById('log-board');
@@ -363,15 +384,23 @@ function initBoard() {
logBoard.scrollTop = logBoard.scrollHeight;
}
// Dropdowns mit Sets aus robot.json befüllen
populateBoardSetDropdowns();
// Tabelle beim ersten Öffnen des Tabs befüllen
loadBoardTable();
document.getElementById('btn-board-run').addEventListener('click', async () => {
logB('Board-Erkennung wird gestartet …');
const refSet = document.getElementById('board-ref-set')?.value ?? '';
logB(`Board-Erkennung wird gestartet … Referenz: ${refSet || 'alle'}`);
const btn = document.getElementById('btn-board-run');
btn.disabled = true;
try {
const response = await fetch('/api/board/run', { method: 'POST' });
const response = await fetch('/api/board/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ refSet: refSet || undefined }),
});
if (!response.ok) {
const raw = await response.text().catch(() => '');
let msg;
@@ -390,8 +419,9 @@ function initBoard() {
if (frame?.contentWindow) {
frame.contentWindow.postMessage({ type: 'reload' }, '*');
}
// Marker-Tabelle aktualisieren
// Marker-Tabelle + Set-Dropdowns aktualisieren
loadBoardTable();
populateBoardSetDropdowns();
}
} else {
logB(`❌ Beendet mit Exit-Code ${evt.exitCode}`);
@@ -484,11 +514,15 @@ function initBoard() {
// ── Aktion 3: Sets justieren (Kabsch 2D+Z) ─────────────────────────────────
document.getElementById('btn-act-align').addEventListener('click', async () => {
const setToMove = document.getElementById('act-align-set').value.trim();
const setFixed = document.getElementById('act-align-fixed').value;
const setToMove = document.getElementById('act-align-move').value;
const result = document.getElementById('act-result');
if (!setToMove) {
result.innerHTML = '<span style="color:#f87171">⚠ Bitte Set-Name eingeben (z.B. "rail").</span>'; return;
result.innerHTML = '<span style="color:#f87171">⚠ Bitte Set auswählen, das verschoben werden soll.</span>'; return;
}
if (setFixed && setFixed === setToMove) {
result.innerHTML = '<span style="color:#f87171">⚠ "Bleibt" und "verschoben" dürfen nicht dasselbe Set sein.</span>'; return;
}
result.innerHTML = '<span style="color:#555b6e">Justierung läuft …</span>';
@@ -496,7 +530,7 @@ function initBoard() {
const r = await fetch('/api/robot/align-sets', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ setToMove }),
body: JSON.stringify({ setFixed: setFixed || undefined, setToMove }),
});
const data = await r.json();
if (!r.ok || data.error) {
@@ -505,7 +539,7 @@ function initBoard() {
const t = data.transform;
result.innerHTML =
`<span style="color:#22c55e">✅ Set "${setToMove}": ${data.numChanged} Marker verschoben` +
` (${data.numMatchingPts} Messpunkte)</span>` +
` (${data.numMatchingPts} Messpunkte)${setFixed ? ` "${setFixed}" bleibt` : ''}</span>` +
` &ensp;Δx=${t.tx}&thinsp;mm&ensp;Δy=${t.ty}&thinsp;mm&ensp;Δz=${t.tz}&thinsp;mm` +
`&ensp;θ=${t.thetaDeg}°`;
loadBoardTable();

View File

@@ -14,9 +14,15 @@
<span class="info-label">Letzter Run</span>
<span class="info-value" id="board-last-run"></span>
</div>
<div class="controls" style="margin-top: 16px;">
<div class="controls" style="margin-top: 16px; display:flex; align-items:center; gap:10px; flex-wrap:wrap;">
<button id="btn-board-run">Board erkennen</button>
<button disabled title="Folgt später">Ergebnis anzeigen</button>
<label style="display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted)">
Referenz:
<select id="board-ref-set"
style="background:#1e293b;border:1px solid #334155;color:#c8cdd8;border-radius:3px;padding:3px 8px;font:inherit;font-size:12px;cursor:pointer">
<option value="">alle</option>
</select>
</label>
</div>
</div>
@@ -78,14 +84,21 @@
Sets justieren (zu 3b-Messung)
</p>
<div style="display:flex;flex-wrap:wrap;align-items:center;gap:8px;font-size:12px;color:var(--text)">
Set verschieben
<input id="act-align-set" type="text" placeholder="rail"
style="width:90px;background:#1e293b;border:1px solid #334155;color:#c8cdd8;border-radius:3px;padding:3px 7px;font:inherit;font-size:12px">
<select id="act-align-fixed"
style="background:#1e293b;border:1px solid #334155;color:#c8cdd8;border-radius:3px;padding:3px 8px;font:inherit;font-size:12px;cursor:pointer">
<option value=""> bleibt </option>
</select>
bleibt&ensp;/&ensp;
<select id="act-align-move"
style="background:#1e293b;border:1px solid #334155;color:#c8cdd8;border-radius:3px;padding:3px 8px;font:inherit;font-size:12px;cursor:pointer">
<option value=""> verschoben </option>
</select>
wird verschoben
<button id="btn-act-align"
style="background:#1e293b;color:#c8cdd8;border:1px solid #4a9eff;border-radius:3px;padding:4px 14px;cursor:pointer;font:inherit;font-size:12px">
Justieren
</button>
<span style="color:var(--muted);font-size:10px">Rotation (Z-Achse) + Translation → passt Set zu 3b-Messung</span>
<span style="color:var(--muted);font-size:10px">Rotation (Z-Achse) + Translation → passt verschobenes Set zu 3b-Messung</span>
</div>
</div>