/*** * Receives GCode, processes it and moves the Data to the Roboter-Class */ const RobotController = require('./RobotController'); class GCode{ static containsMCode(s){ return s === 'M1' || s.startsWith('M1 '); } static receiveMCode(robot, m){ m = m.split(" "); if(m[0] == "M1"){ m.forEach((s) => { if(s.toUpperCase().includes("X")){ robot.xMotor += Number(s.substring(1, s.length));} if(s.toUpperCase().includes("Y")){ robot.alpha += Number(s.substring(1, s.length));} if(s.toUpperCase().includes("Z")){ robot.beta += Number(s.substring(1, s.length));} }) } console.log("Empfangene Motor-Position (" + robot.xMotor.toPrecision(3)+ ", "+ robot.alpha.toPrecision(3)+ ", "+ robot.beta.toPrecision(3)+ ", "+ robot.a.toPrecision(5) + ", "+ robot.b.toPrecision(5)+ ", "+ robot.c.toPrecision(5)+ ") "); robot.sendCommand(); } static containsCommand(s){ if(s.indexOf('M1 ') !== -1){return true;} // M1-Commands = G1-Command only for Motor-Coordinates if(s.indexOf('M114') === 0){return true;} // M114 R - Hardware-Sync (MPos lesen, ToDo_9 Paket 4) if(s.indexOf('G') !== 0){return false;} if(s.indexOf('G90') == 0){return true;} if(s.indexOf('G91') == 0){return true;} if(s.indexOf('G92') == 0){return true;} // G92 - Set Position if(s.indexOf('G28') !== -1){return true;} if(s.indexOf('G1 ') !== -1){return true;} return false; } static getM114(robot){ let text = '{"position":{ "x":'+robot.x+ ', "y":'+robot.y+ ', "z":'+robot.z+ ', "a":' +robot.phi + ', "b":' +robot.theta + ', "c":' +robot.psi + '},' + '"motorCounts":{ "x":'+ robot.xMotor + ', "y":'+ robot.alpha + ', "z":'+ robot.beta + ', "a":'+ robot.a + ', "b":'+ robot.b + ', "c":'+ robot.c + ', "e":'+ (robot.e ?? 0) + '}}'; return text; } static toPiMultiple(gCode){ if(gCode == undefined){return gCode;} var multipleParameters = gCode.split(" "); var newGString = ""; multipleParameters.forEach((paramet) => { if(paramet == undefined || !paramet || paramet.length === 0 || paramet == " " || paramet ==""){ } else if(['A', 'a', 'B', 'b', 'C', 'c','E','e'].includes(paramet.charAt(0)) ) { var numberParameter = Number(paramet.substring(1, paramet.length)) newGString += " " + paramet[0] + String(numberParameter*Math.PI/180) } else{ newGString += " " + paramet; } }); return newGString.trim(); }; /** * Verarbeitet eine rohe G-Code-Nachricht. Parsing + Steuerlogik liegen jetzt im * GCodeParser bzw. RobotController (ToDo_6); diese Methode bleibt als Fassade * erhalten, damit bestehende Aufrufer (InputWS, Datei-Befehle) unverändert * funktionieren. */ static receiveGCode(robot, g){ // Rückgabe durchreichen: synchron `undefined` wie bisher, oder ein Promise, // falls ein asynchroner Befehl (Hardware-Sync, ToDo_9 Paket 4) enthalten war. return RobotController.receive(robot, g); } } module.exports = GCode