Files
appRobotDriver/test/GCode.speed.test.js

132 lines
4.6 KiB
JavaScript

const GCode = require('../robot/GCode.js');
const Robot = require('../robot/kinematics/Arm3SegmentLinearX');
const TelnetSender = require('../robot/TelnetSenderGRBL.js');
describe('GCode Speed Tests', () => {
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => {});
});
afterAll(() => {
jest.restoreAllMocks();
});
test('G1 with Feedrate F300 - TelnetSender1 should include f300', () => {
const L1 = 300;
const L2 = 300;
const L3 = 20;
const robot = new Robot(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 2300, "x", "y", "z");
const telnetSender2 = new TelnetSender("test.test", 5000, "a", null, null);
const telnetSender3 = new TelnetSender("test.test", 5000, "c", "e", "b");
robot.cmdReceivers.push(telnetSender1);
robot.cmdReceivers.push(telnetSender2);
robot.cmdReceivers.push(telnetSender3);
// G1 with F300
GCode.receiveGCode(robot, "G1 x120 y100 z50 f300");
// Check telnetSender1 (x,y,z axes)
expect(telnetSender1.tSocket.written).toContain('G1');
expect(telnetSender1.tSocket.written).toContain('f300');
expect(telnetSender1.tSocket.written).toMatch(/f300\.00/); // Exact format
// telnetSender2 and telnetSender3 might not have output if no changes
// But since x,y,z changed, telnetSender1 should have the command
});
test('G1 with Feedrate F300 - mit env', () => {
const previousValue = process.env.ROBOT_USE_SPEED_CALC;
process.env.ROBOT_USE_SPEED_CALC = 'true';
const L1 = 300;
const L2 = 300;
const L3 = 20;
const Robot2 = require('../robot/kinematics/Arm3SegmentLinearX'); // neu geladen
const robot = new Robot2(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 5000, "x", "y", "z");
robot.cmdReceivers.push(telnetSender1);
// G1 with F300
robot.useSpeedCalc = true; // Aktiviere die neue Logik
GCode.receiveGCode(robot, "G90 G1 x0 f700"); // Absolut!!
GCode.receiveGCode(robot, "G91 G1 x120 f700"); // relativ!!
// Check telnetSender1 (x,y,z axes)
expect(telnetSender1.tSocket.written).toContain('G1');
expect(telnetSender1.tSocket.written).toContain('f700');
expect(telnetSender1.tSocket.written).toMatch(/f700\.00/); // Exact format
// telnetSender2 and telnetSender3 might not have output if no changes
// But since x,y,z changed, telnetSender1 should have the command
if (previousValue === undefined) {
delete process.env.ROBOT_USE_SPEED_CALC;
} else {
process.env.ROBOT_USE_SPEED_CALC = previousValue;
}
});
test('G1 without Feedrate - should use default f1000', () => {
const L1 = 300;
const L2 = 300;
const L3 = 20;
const robot = new Robot(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 2300, "x", "y", "z");
robot.cmdReceivers.push(telnetSender1);
// G1 without F
GCode.receiveGCode(robot, "G1 x120 y100 z50");
// Check default feedrate
expect(telnetSender1.tSocket.written).toContain('G1');
expect(telnetSender1.tSocket.written).toContain('f1000');
expect(telnetSender1.tSocket.written).toMatch(/f1000\.00/);
});
test('G1 with different Feedrate F500 - multiple senders', () => {
const L1 = 300;
const L2 = 300;
const L3 = 20;
const robot = new Robot(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 2300, "x", "y", "z");
const telnetSender2 = new TelnetSender("test.test", 5000, "a", null, null);
const telnetSender3 = new TelnetSender("test.test", 5000, "c", "e", "b");
robot.cmdReceivers.push(telnetSender1);
robot.cmdReceivers.push(telnetSender2);
robot.cmdReceivers.push(telnetSender3);
// G1 with F500
GCode.receiveGCode(robot, "G1 x120 y100 z50 a10 b20 c30 f500");
// telnetSender1 should have f500
expect(telnetSender1.tSocket.written).toContain('f500');
expect(telnetSender1.tSocket.written).toMatch(/f500\.00/);
// telnetSender2 (a axis) should have f500 if a changed
if (telnetSender2.tSocket.written.length > 0) {
expect(telnetSender2.tSocket.written).toContain('f500');
}
// telnetSender3 (c,e,b axes) should have f500 if changed
if (telnetSender3.tSocket.written.length > 0) {
expect(telnetSender3.tSocket.written).toContain('f500');
}
});
});