Initiales Projekt-Skelett appRobotFileservice

Ausgelagertes Programm-/File-Handling (vormals GCode.receiveFC im appRobotDriver,
ToDo_4 / ToDo_6b). Express-Service mit .gcode + .json-Storage, aktivem Programm +
Cursor, Teaching (FPoint) und Playback. Speicherung in Grad, driver-nativ (Radian)
zum Driver. Konzept/API unter doc/draft_filehandeling*.md. Tests: jest (13 gruen).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
chk
2026-06-14 10:12:41 +02:00
commit b68bdfa9b4
20 changed files with 6085 additions and 0 deletions

51
test/units.test.js Normal file
View File

@@ -0,0 +1,51 @@
const units = require('../src/gcode/units');
test('degToRad / radToDeg', () => {
expect(units.degToRad(180)).toBeCloseTo(Math.PI, 10);
expect(units.radToDeg(Math.PI)).toBeCloseTo(180, 10);
});
test('toExecutable: a/b/c/e Grad→Radian, Kommentar entfernt, mm/Feedrate unverändert', () => {
const stored = 'G90 G1 x10 y20 z0 a90.00 b-90.00 c0.00 e0.00 f1000 ;1759566014';
const exec = units.toExecutable(stored);
expect(exec).not.toMatch(/;/); // kein Kommentar mehr
expect(exec).toContain('x10'); // mm unverändert
expect(exec).toContain('f1000'); // Feedrate unverändert
expect(exec.startsWith('G90 G1')).toBe(true);
const val = (axis) => Number(exec.split(/\s+/).find((t) => t.startsWith(axis)).slice(1));
expect(val('a')).toBeCloseTo(Math.PI / 2, 4);
expect(val('b')).toBeCloseTo(-Math.PI / 2, 4);
expect(val('c')).toBeCloseTo(0, 6);
});
test('formatPointLine: Grad-Zeile mit Zeitstempel-Kommentar', () => {
const pose = { x: 0, y: 300, z: 0, a: Math.PI / 2, b: -Math.PI / 2, c: 0, e: 0 };
const line = units.formatPointLine(pose, 1000, 1759566014000);
expect(line.startsWith('G90 G1 ')).toBe(true);
expect(line).toContain('a90.00');
expect(line).toContain('b-90.00');
expect(line).toContain('f1000');
expect(line).toContain(';1759566014000');
});
test('Round-trip Pose → gespeichert (Grad) → ausführbar (Radian)', () => {
const pose = { x: 5, y: 100, z: -3, a: 1, b: -0.5, c: 0.25, e: 0.1 };
const exec = units.toExecutable(units.formatPointLine(pose, 800));
const val = (axis) => Number(exec.split(/\s+/).find((t) => t.startsWith(axis)).slice(1));
expect(val('a')).toBeCloseTo(1, 3);
expect(val('b')).toBeCloseTo(-0.5, 3);
expect(val('e')).toBeCloseTo(0.1, 3);
});
test('Cursor-Marker hinzufügen/entfernen/erkennen', () => {
const base = 'G90 G1 x0 y0 z0 a0 b0 c0 e0 f1000 ;123';
const withCursor = units.addCursorMarker(base);
expect(withCursor.endsWith('!')).toBe(true);
expect(units.hasCursorMarker(withCursor)).toBe(true);
const without = units.removeCursorMarker(withCursor);
expect(units.hasCursorMarker(without)).toBe(false);
expect(without).toBe(base);
});