fixing Changed-Flag

This commit is contained in:
ChK
2026-04-20 16:07:06 +02:00
parent 5482588566
commit 657f460cf2
7 changed files with 664 additions and 91 deletions

View File

@@ -116,13 +116,14 @@ class Robot{
createMotorPosition(){
this.motorPosition = new MotorPosition(this.xMotor, this.alpha, this.beta, this.a, this.b, this.c, this.eMotor);
this.motorPosition.xMotorChanged = this.xMotorChanged;
this.motorPosition.yMotorChanged = this.yMotorChanged;
this.motorPosition.zMotorChanged = this.zMotorChanged;
this.motorPosition.aMotorChanged = this.aMotorChanged;
this.motorPosition.bMotorChanged = this.bMotorChanged;
this.motorPosition.cMotorChanged = this.cMotorChanged;
this.motorPosition.eMotorChanged = this.eMotorChanged;
// Setze Changed-Flags basierend auf Änderungen seit der letzten Position
this.motorPosition.xMotorChanged = this.motorPositionOld ? this.xMotor !== this.motorPositionOld.x : true;
this.motorPosition.yMotorChanged = this.motorPositionOld ? this.alpha !== this.motorPositionOld.y : true;
this.motorPosition.zMotorChanged = this.motorPositionOld ? this.beta !== this.motorPositionOld.z : true;
this.motorPosition.aMotorChanged = this.motorPositionOld ? this.a !== this.motorPositionOld.a : true;
this.motorPosition.bMotorChanged = this.motorPositionOld ? this.b !== this.motorPositionOld.b : true;
this.motorPosition.cMotorChanged = this.motorPositionOld ? this.c !== this.motorPositionOld.c : true;
this.motorPosition.eMotorChanged = this.motorPositionOld ? this.eMotor !== this.motorPositionOld.e : true;
// Setze Handgelenk-Koordinaten (für Speed-Berechnung)
this.motorPosition.pX = this.pX;
@@ -313,10 +314,27 @@ class Robot{
}
sendCommand(cmd="G1"){
if(this.motorPosition == null){this.createMotorPosition() }
this.motorPositionOld = this.motorPosition;
const isFirstCall = !this.motorPosition;
if (isFirstCall) {
this.motorPositionOld = new MotorPosition(this.xMotor, this.alpha, this.beta, this.a, this.b, this.c, this.eMotor);
} else {
this.motorPositionOld = this.motorPosition;
}
this.createMotorPosition()
// Für den ersten Aufruf setze alle Changed-Flags auf true
if (isFirstCall) {
this.motorPosition.xMotorChanged = true;
this.motorPosition.yMotorChanged = true;
this.motorPosition.zMotorChanged = true;
this.motorPosition.aMotorChanged = true;
this.motorPosition.bMotorChanged = true;
this.motorPosition.cMotorChanged = true;
this.motorPosition.eMotorChanged = true;
}
// Berechne Geschwindigkeiten
this.calculateSpeeds(this.motorPositionOld, this.motorPosition);
this.motorPosition.speeds = {...this.motorSpeeds};

View File

@@ -60,133 +60,273 @@ module.exports = class TelnetSenderGRBL{
if(this.xAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " x" + (mNew.x).toFixed(2).toString();
if(this.xAxisGrbl == "x"){
if(Number.isFinite(mNew.x)){
data += " x" + (mNew.x).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.x in execCommand");
}
}
if(this.xAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " x" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
if(this.xAxisGrbl == "y"){
if(Number.isFinite(mNew.y)){
data += " x" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.y in execCommand");
}
}
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 == "z"){
if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " x" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.z or mNew.y in execCommand");
}
}
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 == "a"){
if(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();
} else {
console.log("Non-finite value for mNew.a in execCommand");
}
}
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 == "b"){
if(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();
} else {
console.log("Non-finite value for mNew.b, mNew.z or mNew.y in execCommand");
}
}
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 == "c"){
if(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();
} else {
console.log("Non-finite value for mNew.b or mNew.c in execCommand");
}
}
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 ;
data += " x" + ((-1.0*(-1.0*(handUpDown) + handTurn) + mNew.e*handOpenInMM)).toFixed(2).toString();
if(this.xAxisGrbl == "e"){
if(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 ;
data += " x" + ((-1.0*(-1.0*(handUpDown) + handTurn) + mNew.e*handOpenInMM)).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.b, mNew.c or mNew.e in execCommand");
}
}
if(this.yAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " y" + (mNew.x ).toFixed(2).toString();
if(this.yAxisGrbl == "x"){
if(Number.isFinite(mNew.x)){
data += " y" + (mNew.x ).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.x in execCommand");
}
}
if(this.yAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " y" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
if(this.yAxisGrbl == "y"){
if(Number.isFinite(mNew.y)){
data += " y" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.y in execCommand");
}
}
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 == "z"){
if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " y" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.z or mNew.y in execCommand");
}
}
if(this.yAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " y" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
if(this.yAxisGrbl == "a"){
if(Number.isFinite(mNew.a)){
data += " y" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.a in execCommand");
}
}
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 == "b"){
if(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();
} else {
console.log("Non-finite value for mNew.b, mNew.z or mNew.y in execCommand");
}
}
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 == "c"){
if(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();
} else {
console.log("Non-finite value for mNew.b or mNew.c in execCommand");
}
}
if(this.yAxisGrbl == "e" && Number.isFinite(mNew.e)){
data += " y" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
if(this.yAxisGrbl == "e"){
if(Number.isFinite(mNew.e)){
data += " y" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.e in execCommand");
}
}
if(this.zAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " z" + (mNew.x).toFixed(2).toString();
if(this.zAxisGrbl == "x"){
if(Number.isFinite(mNew.x)){
data += " z" + (mNew.x).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.x in execCommand");
}
}
if(this.zAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " z" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
if(this.zAxisGrbl == "y"){
if(Number.isFinite(mNew.y)){
data += " z" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.y in execCommand");
}
}
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 == "z"){
if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " z" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.z or mNew.y in execCommand");
}
}
if(this.zAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " z" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
if(this.zAxisGrbl == "a"){
if(Number.isFinite(mNew.a)){
data += " z" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.a in execCommand");
}
}
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 == "b"){
if(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();
} else {
console.log("Non-finite value for mNew.b in execCommand");
}
}
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 == "c"){
if(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();
} else {
console.log("Non-finite value for mNew.c, mNew.b, mNew.z or mNew.y in execCommand");
}
}
if(this.zAxisGrbl == "e" && Number.isFinite(mNew.e)){
data += " z" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
if(this.zAxisGrbl == "e"){
if(Number.isFinite(mNew.e)){
data += " z" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.e in execCommand");
}
}
if(this.aAxisGrbl == "x" && Number.isFinite(mNew.y)){
data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
if(this.aAxisGrbl == "x"){
if(Number.isFinite(mNew.y)){
data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.y in execCommand");
}
}
if(this.aAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
if(this.aAxisGrbl == "y"){
if(Number.isFinite(mNew.y)){
data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.y in execCommand");
}
}
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 == "z"){
if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " a" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.z or mNew.y in execCommand");
}
}
if(this.aAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " a" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
if(this.aAxisGrbl == "a"){
if(Number.isFinite(mNew.a)){
data += " a" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.a in execCommand");
}
}
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 == "b"){
if(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();
} else {
console.log("Non-finite value for mNew.b, mNew.z or mNew.y in execCommand");
}
}
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 == "c"){
if(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();
} else {
console.log("Non-finite value for mNew.c, mNew.b, mNew.z or mNew.y in execCommand");
}
}
if(this.aAxisGrbl == "e" && Number.isFinite(mNew.e)){
// ToDo Mai 2024
data += " a" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
if(this.aAxisGrbl == "e"){
if(Number.isFinite(mNew.e)){
// ToDo Mai 2024
data += " a" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.e in execCommand");
}
}
if(this.bAxisGrbl == "x" && Number.isFinite(mNew.x)){
data += " b" + (mNew.x).toFixed(2).toString();
if(this.bAxisGrbl == "x"){
if(Number.isFinite(mNew.x)){
data += " b" + (mNew.x).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.x in execCommand");
}
}
if(this.bAxisGrbl == "y" && Number.isFinite(mNew.y)){
data += " b" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
if(this.bAxisGrbl == "y"){
if(Number.isFinite(mNew.y)){
data += " b" + (mNew.y * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.y in execCommand");
}
}
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 == "z"){
if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){
data += " b" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.z or mNew.y in execCommand");
}
}
if(this.bAxisGrbl == "a" && Number.isFinite(mNew.a)){
data += " b" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
if(this.bAxisGrbl == "a"){
if(Number.isFinite(mNew.a)){
data += " b" + (mNew.a * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.a in execCommand");
}
}
if(this.bAxisGrbl == "b" && Number.isFinite(mNew.b)){
data += " b" + (mNew.b * 180 / Math.PI).toFixed(2).toString();
if(this.bAxisGrbl == "b"){
if(Number.isFinite(mNew.b)){
data += " b" + (mNew.b * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.b in execCommand");
}
}
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 == "c"){
if(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();
} else {
console.log("Non-finite value for mNew.c, mNew.b, mNew.z or mNew.y in execCommand");
}
}
if(this.bAxisGrbl == "e" && Number.isFinite(mNew.e)){
data += " b" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
if(this.bAxisGrbl == "e"){
if(Number.isFinite(mNew.e)){
data += " b" + (mNew.e * 180 / Math.PI).toFixed(2).toString();
} else {
console.log("Non-finite value for mNew.e in execCommand");
}
}
data += " f"+(maxSpeedF.toFixed(2).toString())