Y-Axis checks

This commit is contained in:
chk
2026-06-13 06:13:31 +02:00
parent 1762a771cf
commit 7f17427e0a
7 changed files with 765 additions and 110 deletions

View File

@@ -556,15 +556,145 @@ function initArm(tab) {
});
}
// Achsen-Messung vom Viewer empfangen
// ── Kalibrierungs-Aktionen (werden nach Rotation-Messung aktiv) ──────────
// Tab-Name → Link-Name in robot.json
const TAB_TO_LINK = { arm1: 'Arm1', arm2: 'Arm2', elbow: 'Ellbow', hand: 'Hand' };
const robotLink = TAB_TO_LINK[tab] ?? tab;
const calibActionsEl = document.getElementById(`${tab}-calib-actions`);
const assignFixedBtn = document.getElementById(`btn-${tab}-assign-fixed`);
const assignFixedInfo = document.getElementById(`${tab}-assign-fixed-info`);
const setOriginBtn = document.getElementById(`btn-${tab}-set-origin`);
const setOriginInfo = document.getElementById(`${tab}-set-origin-info`);
let _lastYAxisMsg = null; // letztes gültiges yaxis-measurement
function enableCalibActions(msg) {
if (!calibActionsEl) return;
calibActionsEl.style.display = 'block';
// ── Button 1: Fixe Marker → Base ────────────────────────────────────────
if (assignFixedBtn) {
const skipped = msg.skipped ?? [];
if (skipped.length > 0) {
const ids = skipped.map(s => s.id).join(', ');
assignFixedBtn.disabled = false;
assignFixedBtn.style.opacity = '1';
assignFixedBtn.style.cursor = 'pointer';
assignFixedBtn.title =
`Marker ${ids} in robot.json dem Link 'Base' zuordnen`;
if (assignFixedInfo) {
assignFixedInfo.textContent =
`Kaum-bewegende Marker: ${ids} ` +
`(Bewegung < ${msg.skipped.map(s => s.maxMoveMm + ' mm').join(', ')}) ` +
`→ Link 'Base' in robot.json eintragen.`;
}
} else {
assignFixedBtn.disabled = true;
if (assignFixedInfo) assignFixedInfo.textContent = 'Alle erkannten Marker rotieren kein fixer Marker gefunden.';
}
}
// ── Button 2: Joint-Origin Y/Z ───────────────────────────────────────────
if (setOriginBtn) {
const [, ay, az] = msg.axisPoint;
setOriginBtn.disabled = false;
setOriginBtn.style.opacity = '1';
setOriginBtn.style.cursor = 'pointer';
setOriginBtn.title = `Joint '${robotLink}': origin[Y]=${ay.toFixed(1)} mm, origin[Z]=${az.toFixed(1)} mm`;
if (setOriginInfo) {
setOriginInfo.textContent =
`Berechnete Achse: Y = ${ay.toFixed(1)} mm · Z = ${az.toFixed(1)} mm ` +
`→ in robot.json links.${robotLink}.jointToParent.origin setzen.`;
}
}
}
function disableCalibActions() {
if (assignFixedBtn) {
assignFixedBtn.disabled = true;
assignFixedBtn.style.opacity = '.45';
assignFixedBtn.style.cursor = 'not-allowed';
}
if (setOriginBtn) {
setOriginBtn.disabled = true;
setOriginBtn.style.opacity = '.45';
setOriginBtn.style.cursor = 'not-allowed';
}
}
if (assignFixedBtn) {
assignFixedBtn.addEventListener('click', async () => {
if (!_lastYAxisMsg) return;
const skipped = _lastYAxisMsg.skipped ?? [];
const markerIds = skipped.map(s => s.id);
const measuredPositions = skipped
.filter(s => Array.isArray(s.posA))
.map(s => ({ id: s.id, position_mm: s.posA }));
log(`🔄 Ordne Marker [${markerIds.join(', ')}] dem Link 'Base' zu …`);
assignFixedBtn.disabled = true;
try {
const r = await fetch('/api/robot/assign-fixed-markers', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ markerIds, targetLink: 'Base', measuredPositions }),
});
const data = await r.json();
if (!r.ok) { log(`❌ Fehler: ${data.error ?? r.status}`); return; }
log(`✅ Zugeordnet: ${data.numAdded} neu, ${data.numAlreadyPresent} bereits vorhanden`);
data.changes.forEach(c => {
if (c.action === 'added') log(` + Marker ${c.markerId}${c.targetLink}`);
else if (c.action === 'already-present') log(` ○ Marker ${c.markerId} bereits in '${c.existingLink}'`);
else if (c.action === 'skipped-no-position') log(` ⚠ Marker ${c.markerId}: keine Positions-Daten`);
});
} catch (err) {
log(`❌ Netzwerkfehler: ${err}`);
} finally {
assignFixedBtn.disabled = false;
}
});
}
if (setOriginBtn) {
setOriginBtn.addEventListener('click', async () => {
if (!_lastYAxisMsg) return;
const [, ay, az] = _lastYAxisMsg.axisPoint;
log(`🔄 Setze ${robotLink}.jointToParent.origin: Y=${ay.toFixed(1)} Z=${az.toFixed(1)}`);
setOriginBtn.disabled = true;
try {
const r = await fetch('/api/robot/set-joint-origin', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ linkName: robotLink, y: ay, z: az }),
});
const data = await r.json();
if (!r.ok) { log(`❌ Fehler: ${data.error ?? r.status}`); return; }
log(`✅ Joint-Origin gesetzt: [${data.oldOrigin.join(', ')}] → [${data.newOrigin.join(', ')}]`);
} catch (err) {
log(`❌ Netzwerkfehler: ${err}`);
} finally {
setOriginBtn.disabled = false;
}
});
}
// ── Achsen-Messung vom Viewer empfangen ───────────────────────────────────
window.addEventListener('message', (e) => {
if (!frameEl || e.source !== frameEl.contentWindow) return;
const msg = e.data;
if (msg?.type === 'yaxis-measurement' && Array.isArray(msg.axisDir)) {
if (msg?.type !== 'yaxis-measurement') return;
if (Array.isArray(msg.axisDir)) {
_lastYAxisMsg = msg;
const fmt = v => (v >= 0 ? '+' : '') + v.toFixed(3) + '°';
log(`📐 Achse (${msg.numMarkers} Marker): dir=[${msg.axisDir.map(v => v.toFixed(4)).join(', ')}]` +
log(`📐 Achse (${msg.numMarkers}/${msg.numMarkersCommon} Marker): dir=[${msg.axisDir.map(v => v.toFixed(4)).join(', ')}]` +
` XY=${fmt(msg.tiltXY)} YZ=${fmt(msg.tiltYZ)}`);
log(` Referenzpunkt: [${msg.axisPoint.map(v => v.toFixed(1)).join(', ')}] mm`);
if ((msg.skipped ?? []).length) {
log(` Gefiltert (zu geringe Bewegung): ${msg.skipped.map(s => `${s.id} (${s.maxMoveMm} mm)`).join(', ')}`);
}
enableCalibActions(msg);
// In rotation_detection.json speichern (anhängen)
fetch('/api/xaxis/save-rotation-detection', {
@@ -579,6 +709,11 @@ function initArm(tab) {
}).then(r => r.json())
.then(d => log(`💾 Gespeichert: ${d.file} (${d.total} Messungen)`))
.catch(e => log(`⚠ Speichern fehlgeschlagen: ${e.message}`));
} else {
// Kein gültiges Ergebnis → Buttons deaktivieren
_lastYAxisMsg = null;
disableCalibActions();
}
});
}