G92 ohne Senden

This commit is contained in:
ChK
2026-03-29 21:20:37 +02:00
parent a361d96802
commit ff96dfd8f1
8 changed files with 212 additions and 14 deletions

View File

@@ -39,6 +39,7 @@ class GCode{
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;
@@ -89,7 +90,7 @@ class GCode{
if(g == undefined) return;
console.log("GCode: Empfange GCode: " + g);
//console.log("GCode: Empfange GCode: " + g);
var multipleCommands = g.split(" G");
var doProcessRest = false;
@@ -202,7 +203,32 @@ class GCode{
if(s.includes("e")){ robot.e = Number(s.substring(1, s.length));}
});
}
if(g[0] == "G92"){ // G92 - Set Position
g.forEach((s) => {
if(s.includes("X")){ robot.xMotor = Number(s.substring(1, s.length));}
if(s.includes("x")){ robot.xMotor = Number(s.substring(1, s.length));}
if(s.includes("Y")){ robot.alpha = Number(s.substring(1, s.length));}
if(s.includes("y")){ robot.alpha = Number(s.substring(1, s.length));}
if(s.includes("Z")){ robot.beta = Number(s.substring(1, s.length));}
if(s.includes("z")){ robot.beta = Number(s.substring(1, s.length));}
if(s.includes("A")){ robot.a = Number(s.substring(1, s.length));}
if(s.includes("a")){ robot.a = Number(s.substring(1, s.length));}
if(s.includes("B")){ robot.b = Number(s.substring(1, s.length));}
if(s.includes("b")){ robot.b = Number(s.substring(1, s.length));}
if(s.includes("C")){ robot.c = Number(s.substring(1, s.length));}
if(s.includes("c")){ robot.c = Number(s.substring(1, s.length));}
if(s.includes("E")){ robot.e = Number(s.substring(1, s.length));}
if(s.includes("e")){ robot.e = Number(s.substring(1, s.length));}
});
robot.calculatePositionFromMotorAngles();
calculateNew = false;
// ToDo: Send Command to update Position of Robot, because G92 should
// set the current Position to the given Coordinates without moving the Robot.
}
if(calculateNew && !calculateFromMotorCoordinates){
robot.calculateAngles3D();

View File

@@ -12,7 +12,6 @@ module.exports = class TelnetSenderGRBL{
* zAxisGrbl: ...
*/
constructor(urlGRBL = "grblesp.local", maxSpeedF = 5000, xAxisGrbl = "x", yAxisGrbl = "y", zAxisGrbl = "z", aAxisGrbl = null, bAxisGrbl = null, cAxisGrbl = null, eAxisGrbl = null){
var socket = null;
this.tSocket = null;
this.receiver = null;
@@ -26,6 +25,12 @@ module.exports = class TelnetSenderGRBL{
this.cAxisGrbl = cAxisGrbl;
this.eAxisGrbl = eAxisGrbl;
if (urlGRBL === "test.test") {
this.tSocket = { written: "", write(txt){ this.written = txt; } };
this.isTestMode = true;
return;
}
new Promise((resolve, reject) => {
@@ -53,10 +58,10 @@ module.exports = class TelnetSenderGRBL{
}
moveTo(mOld, mNew){
this.translateAxisNames(mOld, mNew, "G1")
this.execCommand("G1", mOld, mNew)
}
translateAxisNames(mOld, mNew, strCommand = "G1"){
execCommand(strCommand = "G1", mOld, mNew ){
// The Hand-Turn is not 1:1 to the Hand-Lift °
var factorTurnLift = 1.2;
@@ -67,7 +72,7 @@ module.exports = class TelnetSenderGRBL{
// Hand-Open in mm
var handOpenInMM = 1.0
var data = strCommand;
var data = strCommand.toString("utf-8");
if(this.xAxisGrbl == "x"){
data += " x" + (mNew.x).toFixed(2).toString();
@@ -200,10 +205,9 @@ module.exports = class TelnetSenderGRBL{
data += " f"+(maxSpeedF.toFixed(2).toString())
console.log("" + this.urlGRBLstr + " receives: " + data.toString("utf-8"))
if(this.tSocket && data.toString("utf-8").length > 3){
if(!this.isTestMode){ console.log("" + this.urlGRBLstr + " gets the message: " + data.toString("utf-8"))}
this.tSocket.write( data.toString("utf-8") + "\r\n");
}
}

View File

@@ -26,6 +26,12 @@ module.exports = class TelnetSenderGRBL{
this.bAxisGrbl = bAxisGrbl;
this.cAxisGrbl = cAxisGrbl;
this.eAxisGrbl = eAxisGrbl;
if (urlGRBL === "test.test") {
this.tSocket = { written: "", write(txt){ this.written = txt; } };
this.isTestMode = true;
return;
}
var fluidConfig = { host: urlGRBL, port: 80, reconnectDelay: 30000}
@@ -36,6 +42,12 @@ module.exports = class TelnetSenderGRBL{
moveTo(mOld, mNew){
this.execCommand("G1", mOld, mNew)
}
execCommand(strCommand = "G1", mOld, mNew){
var data = strCommand.toString("utf-8");
// The Hand-Turn is not 1:1 to the Hand-Lift °
var factorTurnLift = 1.2;
@@ -46,7 +58,7 @@ module.exports = class TelnetSenderGRBL{
// Hand-Open in mm
var handOpenInMM = 1.0
var data = "G1"
if(this.xAxisGrbl == "x"){
data += " x" + (mNew.x).toFixed(2).toString();
@@ -179,10 +191,9 @@ module.exports = class TelnetSenderGRBL{
data += " f"+(maxSpeedF.toFixed(2).toString())
console.log("" + this.urlGRBLstr + " receives: " + data.toString("utf-8"))
if(this.tSocket && data.toString("utf-8").length > 3){
if(!this.isTestMode){ console.log("" + this.urlGRBLstr + " gets the message: " + data.toString("utf-8"))}
this.tSocket.write( data.toString("utf-8") + "\r\n");
}
}