82 lines
3.3 KiB
JavaScript
Executable File
82 lines
3.3 KiB
JavaScript
Executable File
/***
|
|
* 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){
|
|
// position = Workspace (x/y/z in mm, a/b/c als Euler-Winkel phi/theta/psi in rad,
|
|
// e = Greifer-Öffnung in mm).
|
|
// motorCounts = die 7 Motor-Slots, inkl. e = eMotor (abgeleiteter Greifer-Motorwert,
|
|
// NICHT die mm-Öffnung — die steht in position.e).
|
|
let text = '{"position":{ "x":'+robot.x+
|
|
', "y":'+robot.y+
|
|
', "z":'+robot.z+
|
|
', "a":' +robot.phi +
|
|
', "b":' +robot.theta +
|
|
', "c":' +robot.psi +
|
|
', "e":' +(robot.e ?? 0) + '},' +
|
|
'"motorCounts":{ "x":'+ robot.xMotor +
|
|
', "y":'+ robot.alpha +
|
|
', "z":'+ robot.beta +
|
|
', "a":'+ robot.a +
|
|
', "b":'+ robot.b +
|
|
', "c":'+ robot.c +
|
|
', "e":'+ (robot.eMotor ?? 0) +
|
|
'}}';
|
|
return text;
|
|
}
|
|
|
|
|
|
/**
|
|
* 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
|
|
|