G92 senden

This commit is contained in:
chk
2026-06-25 17:16:30 +02:00
parent 1db62e08df
commit 7818604c02
10 changed files with 934 additions and 121 deletions

View File

@@ -346,11 +346,21 @@ function setHomingProgress(step, total, text) {
if (txt) txt.textContent = text || `Schritt ${step} / ${total}`;
}
function writePartialGCode(state) {
// Schreibt das G92-Kommando ins Eingabefeld.
// - progressiv (full=false): nur die bereits bestimmten Achsen, je Gelenk-Update
// - final (full=true): alle 7 Achsen; fehlende c (Palm) / e (Greifer)
// werden als 0 ergänzt — identisch zu dem, was
// "An Roboter senden" via server/buildG92.cjs sendet.
function writePartialGCode(state, { full = false } = {}) {
const axisMap = { x: 'X', y: 'Y', z: 'Z', a: 'A', b: 'B', c: 'C', e: 'E' };
const parts = [];
for (const [key, axis] of Object.entries(axisMap)) {
if (state[key] != null) parts.push(`${axis}${Number(state[key]).toFixed(2)}`);
const num = Number(state[key]);
if (state[key] != null && Number.isFinite(num)) {
parts.push(`${axis}${num.toFixed(2)}`);
} else if (full) {
parts.push(`${axis}0.00`);
}
}
if (!parts.length) return;
const el = document.getElementById('gcodePayload');
@@ -549,6 +559,9 @@ async function runHoming() {
if (evt.state) {
_homingState = evt.state;
showHomingResult(evt.state);
// Vollständiges G92 (inkl. C0/E0) ins Feld — exakt das, was
// "An Roboter senden" schickt.
writePartialGCode(evt.state, { full: true });
if (btnSend) {
btnSend.disabled = false;
btnSend.style.opacity = '';
@@ -593,7 +606,8 @@ async function sendHomingToRobot() {
});
const data = await res.json();
if (res.ok) {
appendLog('✅ State erfolgreich an Roboter gesendet');
appendLog(`✅ An Roboter gesendet: ${data.gcode ?? ''}`);
if (data.note) appendLog(` ${data.note}`);
setHomingStatus('✓ Gesendet', 'done');
} else {
appendLog(`❌ Fehler beim Senden: ${data.error ?? JSON.stringify(data)}`);
@@ -605,6 +619,23 @@ async function sendHomingToRobot() {
}
}
// Transport für die G-Code-/Befehl-Buttons (data-cmd). Schickt eine rohe
// Zeile über das Backend an den Driver-WebSocket (POST /api/robot/gcode).
// Liegt ein Payload-Feld vor (z.B. das G92 aus #gcodePayload), wird dessen
// Inhalt gesendet, sonst der cmd-Name selbst. Ersetzt den toten WSS-Altpfad.
window.sendCommand = async function (cmd, payload) {
const line = (payload && payload.trim()) ? payload.trim() : String(cmd ?? '').trim();
if (!line) throw new Error('Leere Befehlszeile');
const res = await fetch('/api/robot/gcode', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ line }),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error ?? `HTTP ${res.status}`);
return data;
};
async function onCommandClick(btn) {
const cmd = btn.dataset.cmd;
const payloadSelector = btn.dataset.payload;