Test vom GCode
This commit is contained in:
@@ -120,6 +120,7 @@ class GCode{
|
||||
if(s.toUpperCase().includes("B")){ robot.theta += Number(s.substring(1, s.length)); robot.bMotorChanged = true;}
|
||||
if(s.toUpperCase().includes("C")){ robot.psi += Number(s.substring(1, s.length)); robot.cMotorChanged = true;}
|
||||
if(s.toUpperCase().includes("E")){ robot.e += Number(s.substring(1, s.length)); robot.eMotorChanged = true;}
|
||||
if(s.toUpperCase().includes("F")){ robot.feedrate = Number(s.substring(1, s.length)); }
|
||||
});
|
||||
}
|
||||
else if(g[0] == "M1" && robot.moveRelative){
|
||||
@@ -146,6 +147,7 @@ class GCode{
|
||||
if(s.toUpperCase().includes("B")){ robot.theta = Number(s.substring(1, s.length)); robot.bMotorChanged = true;}
|
||||
if(s.toUpperCase().includes("C")){ robot.psi = Number(s.substring(1, s.length)); robot.cMotorChanged = true;}
|
||||
if(s.toUpperCase().includes("E")){ robot.e = Number(s.substring(1, s.length)); robot.eMotorChanged = true;}
|
||||
if(s.toUpperCase().includes("F")){ robot.feedrate = Number(s.substring(1, s.length)); }
|
||||
});
|
||||
}
|
||||
else if(g[0] == "M1" && !robot.moveRelative){
|
||||
|
||||
@@ -44,6 +44,12 @@ class Robot{
|
||||
/** @type {number} Finger-Abstands-Einstellung (Öffnungsweite) */
|
||||
this.e = 0.0;
|
||||
|
||||
/** @type {number} Feedrate für Bewegungen in mm/min */
|
||||
this.feedrate = 200; // Standardwert
|
||||
|
||||
/** @type {Object} Motor-Geschwindigkeiten in Einheiten pro Minute */
|
||||
this.motorSpeeds = {x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0};
|
||||
|
||||
// Zwischen-Ergebnisse: Handgelenk-Punkt (Koordinaten des Handgelenks, nur für Tests public)
|
||||
/** @type {number} Handgelenk-Position X in mm (berechneter Zwischenwert) */
|
||||
this.pX = 0.0;
|
||||
@@ -111,6 +117,10 @@ class Robot{
|
||||
this.motorPosition.bMotorChanged = this.bMotorChanged;
|
||||
this.motorPosition.cMotorChanged = this.cMotorChanged;
|
||||
this.motorPosition.eMotorChanged = this.eMotorChanged;
|
||||
|
||||
// Setze Geschwindigkeiten
|
||||
this.motorPosition.speeds = {...this.motorSpeeds};
|
||||
this.motorPosition.feedrate = this.feedrate || 200;
|
||||
}
|
||||
|
||||
// Berechnet aus XYZ die Motor-Winkel für den GCode
|
||||
@@ -178,6 +188,31 @@ class Robot{
|
||||
this.eMotor = this.e - this.b - this.c;
|
||||
}
|
||||
|
||||
// Berechnet die Motor-Geschwindigkeiten basierend auf Feedrate und Positionsänderung
|
||||
calculateSpeeds(oldPos, newPos) {
|
||||
if (!oldPos || !newPos || this.feedrate <= 0) return;
|
||||
|
||||
// Berechne Distanz im Raum (nur linear, Orientierung ignoriert für Einfachheit)
|
||||
const dx = newPos.x - oldPos.x;
|
||||
const dy = newPos.y - oldPos.y;
|
||||
const dz = newPos.z - oldPos.z;
|
||||
const dist = Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||
|
||||
if (dist === 0) return; // Keine Bewegung
|
||||
|
||||
const time = dist / this.feedrate; // Zeit in Minuten
|
||||
|
||||
// Geschwindigkeiten in Motor-Einheiten pro Minute
|
||||
// Annahme: xMotor in mm/min, alpha/beta/a/b/c in rad/min, e in mm/min
|
||||
this.motorSpeeds.x = (this.xMotor - oldPos.xMotor) / time;
|
||||
this.motorSpeeds.y = (this.alpha - oldPos.alpha) / time;
|
||||
this.motorSpeeds.z = (this.beta - oldPos.beta) / time;
|
||||
this.motorSpeeds.a = (this.a - oldPos.a) / time;
|
||||
this.motorSpeeds.b = (this.b - oldPos.b) / time;
|
||||
this.motorSpeeds.c = (this.c - oldPos.c) / time;
|
||||
this.motorSpeeds.e = (this.eMotor - oldPos.e) / time;
|
||||
}
|
||||
|
||||
rotateAroundAxis(v, n, angle) {
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
@@ -233,6 +268,10 @@ class Robot{
|
||||
this.motorPositionOld = this.motorPosition;
|
||||
this.createMotorPosition()
|
||||
|
||||
// Berechne Geschwindigkeiten
|
||||
this.calculateSpeeds(this.motorPositionOld, this.motorPosition);
|
||||
this.motorPosition.speeds = {...this.motorSpeeds};
|
||||
|
||||
console.log("Robot.sendCommand: Motor-Pos: x=", this.motorPosition.x.toFixed(3), "yMotor=",this.motorPosition.y.toFixed(3), "zMotor=",this.motorPosition.z.toFixed(3), "aM=", this.motorPosition.a.toFixed(3), "bM=", this.motorPosition.b.toFixed(3), "cM=", this.motorPosition.c.toFixed(3), " e=", this.motorPosition.e.toFixed(3));
|
||||
|
||||
this.cmdReceivers.forEach(receiver => {
|
||||
|
||||
@@ -21,6 +21,12 @@ module.exports = class RobotMotorPosition{
|
||||
this.bMotorChanged = false;
|
||||
this.cMotorChanged = false;
|
||||
this.eMotorChanged = false;
|
||||
|
||||
// Geschwindigkeiten in Einheiten pro Minute
|
||||
this.speeds = {x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0};
|
||||
|
||||
// Feedrate in mm/min
|
||||
this.feedrate = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -203,8 +203,9 @@ module.exports = class TelnetSenderGRBL{
|
||||
|
||||
if(this.tSocket && data.toString("utf-8").length > 3){
|
||||
|
||||
if(strCommand == "G1"){
|
||||
data += " f"+(maxSpeedF.toFixed(2).toString())
|
||||
if(strCommand == "G1" && mNew){
|
||||
const feedrate = mNew.feedrate !== undefined ? mNew.feedrate : 2300;
|
||||
data += " f"+(feedrate.toFixed(2).toString())
|
||||
}
|
||||
|
||||
if(!this.isTestMode){ console.log("" + this.urlGRBLstr + " gets the message: " + data.toString("utf-8"))}
|
||||
|
||||
Reference in New Issue
Block a user