NaN vermeiden

This commit is contained in:
ChK
2026-04-20 15:23:15 +02:00
parent a28c759746
commit 5482588566
3 changed files with 856 additions and 36 deletions

View File

@@ -60,27 +60,27 @@ module.exports = class TelnetSenderGRBL{
if(this.xAxisGrbl == "x"){
if(this.xAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " x" + (mNew.x).toFixed(2).toString();
}
if(this.xAxisGrbl == "y"){
if(this.xAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " x" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
}
if(this.xAxisGrbl == "z"){
if(this.xAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " x" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
}
if(this.xAxisGrbl == "a"){
if(this.xAxisGrbl == "a" && Number.isFinite(mNew.a)){
// This is the case for the Ellbow, when the Motor is connected to the X-Port of the FluidNC
data += " x" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
}
if(this.xAxisGrbl == "b"){
if(this.xAxisGrbl == "b" && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " x" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString();
}
if(this.xAxisGrbl == "c"){
if(this.xAxisGrbl == "c" && Number.isFinite(mNew.b) && Number.isFinite(mNew.c)){
// Runs correctly, substracts the "b" axis, uses the "c" axis to send to the x-Motor wich is in this case the hand-twist
data += " x" + ((-1)*mNew.b * 180 / Math.PI + (mNew.c * 180 / Math.PI) ).toFixed(2).toString();
}
if(this.xAxisGrbl == "e"){
if(this.xAxisGrbl == "e" && Number.isFinite(mNew.b) && Number.isFinite(mNew.c) && Number.isFinite(mNew.e)){
//This is the case for the Hand, when the Open-Close Motor is connected to the X-Port of FluidNC
var handUpDown = mNew.b * 180 * factorTurnLift / Math.PI ;
var handTurn = mNew.c*180/Math.PI ;
@@ -89,77 +89,77 @@ module.exports = class TelnetSenderGRBL{
if(this.yAxisGrbl == "x"){
if(this.yAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " y" + (mNew.x ).toFixed(2).toString();
}
if(this.yAxisGrbl == "y"){
if(this.yAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " y" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
}
if(this.yAxisGrbl == "z"){
if(this.yAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " y" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
}
if(this.yAxisGrbl == "a"){
if(this.yAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " y" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
}
if(this.yAxisGrbl == "b"){
if(this.yAxisGrbl == "b" && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " y" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString();
}
if(this.yAxisGrbl == "c"){
if(this.yAxisGrbl == "c" && Number.isFinite(mNew.b) && Number.isFinite(mNew.c)){
// This is the case if the hand-rotation-turner is connected to the FluidNC-Y
var handUpDown = (mNew.b * 180 / Math.PI ) * factorTurnLift;
var handTurn = ( mNew.c*180/Math.PI ) ;
data += " y" + (-1.0*(handUpDown) + handTurn).toFixed(2).toString();
}
if(this.yAxisGrbl == "e"){
if(this.yAxisGrbl == "e" && Number.isFinite(mNew.e)){
data += " y" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
}
if(this.zAxisGrbl == "x"){
if(this.zAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " z" + (mNew.x).toFixed(2).toString();
}
if(this.zAxisGrbl == "y"){
if(this.zAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " z" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
}
if(this.zAxisGrbl == "z"){
if(this.zAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " z" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
}
if(this.zAxisGrbl == "a"){
if(this.zAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " z" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
}
if(this.zAxisGrbl == "b"){
if(this.zAxisGrbl == "b" && Number.isFinite(mNew.b)){
// This is the case of the Hand, when the Up-Down-Motor is connected to the FluidNC-Z
data += " z" + ( mNew.b * 180 / Math.PI ).toFixed(2).toString();
}
if(this.zAxisGrbl == "c"){
if(this.zAxisGrbl == "c" && Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " z" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString();
}
if(this.zAxisGrbl == "e"){
if(this.zAxisGrbl == "e" && Number.isFinite(mNew.e)){
data += " z" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
}
if(this.aAxisGrbl == "x"){
if(this.aAxisGrbl == "x" && Number.isFinite(mNew.y)){
data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
}
if(this.aAxisGrbl == "y"){
if(this.aAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
}
if(this.aAxisGrbl == "z"){
if(this.aAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " a" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
}
if(this.aAxisGrbl == "a"){
if(this.aAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " a" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
}
if(this.aAxisGrbl == "b"){
if(this.aAxisGrbl == "b" && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " a" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString();
}
if(this.aAxisGrbl == "c"){
if(this.aAxisGrbl == "c" && Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " a" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString();
}
if(this.aAxisGrbl == "e"){
if(this.aAxisGrbl == "e" && Number.isFinite(mNew.e)){
// ToDo Mai 2024
data += " a" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
}
@@ -167,25 +167,25 @@ module.exports = class TelnetSenderGRBL{
if(this.bAxisGrbl == "x"){
if(this.bAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " b" + (mNew.x).toFixed(2).toString();
}
if(this.bAxisGrbl == "y"){
if(this.bAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " b" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
}
if(this.bAxisGrbl == "z"){
if(this.bAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " b" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
}
if(this.bAxisGrbl == "a"){
if(this.bAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " b" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
}
if(this.bAxisGrbl == "b"){
if(this.bAxisGrbl == "b" && Number.isFinite(mNew.b)){
data += " b" + (mNew.b * 180 / Math.PI).toFixed(2).toString();
}
if(this.bAxisGrbl == "c"){
if(this.bAxisGrbl == "c" && Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " b" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString();
}
if(this.bAxisGrbl == "e"){
if(this.bAxisGrbl == "e" && Number.isFinite(mNew.e)){
data += " b" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
}
@@ -193,7 +193,9 @@ module.exports = class TelnetSenderGRBL{
if(this.tSocket && data.toString("utf-8").length > 3){
if(!this.isTestMode){ console.log("" + this.urlGRBLstr + " gets the message: " + data.toString("utf-8"))}
//if(!this.isTestMode){
console.log("" + this.urlGRBLstr + " gets the message: " + data.toString("utf-8"))
//}
this.tSocket.write( data.toString("utf-8") + "\r\n");
}
}