G92-Grad + E-Korrektur
This commit is contained in:
@@ -65,20 +65,38 @@ describe('RobotController (ToDo_6)', () => {
|
||||
expect(robot.sendCommand).toHaveBeenCalledWith('G92');
|
||||
});
|
||||
|
||||
test('applyCommand: G92 verhält sich identisch zu M92 (Bug 3)', () => {
|
||||
test('applyCommand: G92 interpretiert Winkel als Grad (→ rad), X bleibt mm', () => {
|
||||
const robot = createDummyRobot();
|
||||
robot.createMotorPosition = jest.fn();
|
||||
|
||||
// G92 nutzt die G-Code-Konvention (Grad). Intern landen die Winkel in Radiant,
|
||||
// X (lineare Schiene) bleibt unverändert in mm. Vgl. M92 oben (Roh-Radiant).
|
||||
RobotController.applyCommand(robot, { command: 'G92', params: { X: 5, Y: 0.5, A: 0.3 } });
|
||||
|
||||
const DEG2RAD = Math.PI / 180;
|
||||
expect(robot.createMotorPosition).toHaveBeenCalledTimes(1);
|
||||
expect(robot.xMotor).toBe(5);
|
||||
expect(robot.alpha).toBe(0.5);
|
||||
expect(robot.a).toBe(0.3);
|
||||
expect(robot.alpha).toBeCloseTo(0.5 * DEG2RAD, 10);
|
||||
expect(robot.a).toBeCloseTo(0.3 * DEG2RAD, 10);
|
||||
expect(robot.calculatePositionFromMotorAngles).toHaveBeenCalled();
|
||||
expect(robot.sendCommand).toHaveBeenCalledWith('G92');
|
||||
});
|
||||
|
||||
test('applyCommand: G92 E setzt Greifer-Öffnung (mm) und leitet eMotor ab', () => {
|
||||
const robot = createDummyRobot();
|
||||
robot.createMotorPosition = jest.fn();
|
||||
robot.b = 0.2; // Handgelenk-Knick
|
||||
robot.c = -0.5; // Hand-Dreher
|
||||
|
||||
// E ist mm (keine Grad/rad-Umrechnung). eMotor wird über die Greifer-Kopplung
|
||||
// aus e, b, c abgeleitet — sonst bliebe der an FluidNC gesendete Wert stale.
|
||||
RobotController.applyCommand(robot, { command: 'G92', params: { E: 10, B: 0.2 * (180 / Math.PI), C: -0.5 * (180 / Math.PI) } });
|
||||
|
||||
expect(robot.e).toBe(10);
|
||||
expect(robot.eMotor).toBeCloseTo(10 - robot.b - robot.c, 10); // = 10 - 0.2 - (-0.5) = 10.3
|
||||
expect(robot.sendCommand).toHaveBeenCalledWith('G92');
|
||||
});
|
||||
|
||||
test('applyCommand: ungültiger Befehl wird ignoriert', () => {
|
||||
const robot = createDummyRobot();
|
||||
RobotController.applyCommand(robot, null);
|
||||
|
||||
Reference in New Issue
Block a user