ChangeAngles zweites Gelenk

Arbeiten am zweiten Gelenk
This commit is contained in:
chk
2026-05-14 20:30:09 +02:00
parent 3fa1f76413
commit 58837c646a
4 changed files with 46 additions and 10 deletions

View File

@@ -133,6 +133,10 @@ function calculateRotationAngle(listIdAndX, jsonRobot, jointName, method = "tan"
a = 2;
b = 1;
}
if(JSON.stringify(jointInfo.axis) === JSON.stringify([0, 1, 0])){
a = 2;
b = 0;
}
else{
// Default: Rotationum X Achse
a = 2;
@@ -163,22 +167,31 @@ const markerFound = markerUsed
const db = pos[1][b] - jointB;
const angleOne = Math.atan2(db, da) * (180 / Math.PI);
const deltaAngleTan = angleOne - angleZero;
angles.push({ deltaAngleTan });
angles.push(deltaAngleTan);
}
else{
const hypotenuse = Math.sqrt(mRobot.relPos[a]**2 + mRobot.relPos[b]**2);
// Arbetein mit sin und hypotenuse
if(method === "sin"){
const angleOneSin = Math.asin(db / hypotenuse) * (180 / Math.PI);
const db = pos[1][b] - jointB;
var angleOneSin;
if(Math.abs(db) > hypotenuse && db < 1.3 * hypotenuse){angleOneSin = 180}
else if(Math.abs(db) < hypotenuse && -1*Math.abs(db) > -hypotenuse){
angleOneSin = Math.asin(db / hypotenuse) * (180 / Math.PI);
}
else if(Math.abs(db) < -1*hypotenuse && Math.abs(db) > 1.3*Math.abs(db)){angleOneSin = -180}
else angleOneSin = NaN;
const deltaAngleSin = angleOneSin - angleZero;
angles.push({ deltaAngleSin });
angles.push(deltaAngleSin);
}
// Arbeiten mit cos und hypotenuse
else{
const db = pos[1][b] - jointB;
const angleOneCos = Math.acos(db / hypotenuse) * (180 / Math.PI);
const deltaAngleCos = -(angleOneCos - angleZero);
angles.push({ deltaAngleCos });
angles.push(deltaAngleCos);
}
}
}
@@ -191,7 +204,7 @@ const markerFound = markerUsed
const deviation = Math.sqrt(angles.reduce((sum, x) => sum + Math.pow(x - average, 2), 0) / n);
return average, deviation;
return {average, deviation};
}
async function calculate(foundMarkers, jsonRobot) {
@@ -199,7 +212,17 @@ async function calculate(foundMarkers, jsonRobot) {
const foundById = new Map(foundMarkers.markers.map(f => [f.id, f.position_mm ]));
const { meanPx: x, stdDevPx: varx } = calculateXPos(foundById, jsonRobot);
const { meanY: y, stdDevY: vary } = calculateRotationAngle(foundById, jsonRobot, "jointB", "tan");
jsonRobot.recognized.x = x;
const { average: y, deviation: vary } = calculateRotationAngle(foundById, jsonRobot, "jointB", "tan");
jsonRobot.recognized.y = y;
jsonRobot.Joints["jointD"].origin[0] = x;
jsonRobot.Joints["jointD"].origin[1] = -jsonRobot.ElementLength["Arm1"]*Math.cos(y*Math.PI/180)
jsonRobot.Joints["jointD"].origin[2] = jsonRobot.ElementLength["Arm1"]*Math.sin(y*Math.PI/180)
const { average: a, deviation: vara } = calculateRotationAngle(foundById, jsonRobot, "jointD", "sin");
return {
meta: {