This commit is contained in:
chk
2026-06-14 06:35:18 +02:00
parent b19489d836
commit 87cbd51bd2
6 changed files with 112 additions and 2 deletions

View File

@@ -51,6 +51,34 @@ describe('RobotController (ToDo_6)', () => {
expect(robot.sendCommand).toHaveBeenCalled();
});
test('applyCommand: M92 setzt Motorwerte absolut und sendet G92', () => {
const robot = createDummyRobot();
robot.createMotorPosition = jest.fn();
RobotController.applyCommand(robot, { command: 'M92', params: { X: 5, Y: 0.5, A: 0.3 } });
expect(robot.createMotorPosition).toHaveBeenCalledTimes(1);
expect(robot.xMotor).toBe(5);
expect(robot.alpha).toBe(0.5);
expect(robot.a).toBe(0.3);
expect(robot.calculatePositionFromMotorAngles).toHaveBeenCalled();
expect(robot.sendCommand).toHaveBeenCalledWith('G92');
});
test('applyCommand: G92 verhält sich identisch zu M92 (Bug 3)', () => {
const robot = createDummyRobot();
robot.createMotorPosition = jest.fn();
RobotController.applyCommand(robot, { command: 'G92', params: { X: 5, Y: 0.5, A: 0.3 } });
expect(robot.createMotorPosition).toHaveBeenCalledTimes(1);
expect(robot.xMotor).toBe(5);
expect(robot.alpha).toBe(0.5);
expect(robot.a).toBe(0.3);
expect(robot.calculatePositionFromMotorAngles).toHaveBeenCalled();
expect(robot.sendCommand).toHaveBeenCalledWith('G92');
});
test('applyCommand: ungültiger Befehl wird ignoriert', () => {
const robot = createDummyRobot();
RobotController.applyCommand(robot, null);

View File

@@ -84,4 +84,23 @@ describe("TelnetSenderGRBL.execCommand", () => {
expect(sender.tSocket.written).toBe("G92 x12.34 y57.30 z57.30\r\n");
});
test("aAxisGrbl guard prüft mNew.x, nicht mNew.y (Bug 5)", () => {
// Sender mit aAxisGrbl = "x": GRBL-a-Achse bekommt xMotor
const sender = new TenetSender("test.test", 2300, null, null, null, "x");
sender.tSocket = {
written: "",
write: function(txt) { this.written = txt; }
};
const mOld = { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0 };
// mNew.x ist NaN (ungültig), mNew.y ist finite — alter Bug würde Guard passieren lassen
const mNew = { x: NaN, y: 1.0, z: 0, a: 0, b: 0, c: 0, e: 0 };
mNew.xMotorChanged = true;
sender.execCommand("G1", mOld, mNew);
// Guard muss auf mNew.x prüfen — da NaN, darf kein "a"-Wert gesendet werden
expect(sender.tSocket.written).not.toContain(" a");
});
});