kienamtics

This commit is contained in:
PROFERIS - Mi³osz Stocki
2026-07-08 14:53:47 +02:00
parent ed6c6a6658
commit 242df22ba6
6 changed files with 109 additions and 2 deletions
+10
View File
@@ -0,0 +1,10 @@
const fs = require('fs');
const { execSync } = require('child_process');
try {
const output = execSync('git log -p -3 src/main.cpp', { cwd: 'm:/Nextcloud/IoT/esp32s3-wiji' });
fs.writeFileSync('m:/Nextcloud/IoT/esp32s3-wiji/git_history.txt', output);
console.log('Success');
} catch (e) {
console.log('Error', e.message);
}
+7
View File
@@ -0,0 +1,7 @@
const { execSync } = require('child_process');
const fs = require('fs');
try {
const log = execSync('git log -p -n 10 src/main.cpp', { encoding: 'utf8' });
fs.writeFileSync('git_log.txt', log);
} catch(e) {}
+1
View File
@@ -289,6 +289,7 @@ void loop() {
stepper2.setMaxSpeed(currentMaxSpeed); stepper2.setMaxSpeed(currentMaxSpeed);
stepper1.setAcceleration(currentAccel); stepper1.setAcceleration(currentAccel);
stepper2.setAcceleration(currentAccel); stepper2.setAcceleration(currentAccel);
sendPosition();
homingState = HOME_IDLE; homingState = HOME_IDLE;
Serial.println("[SYS] Homing all complete."); Serial.println("[SYS] Homing all complete.");
} }
+41
View File
@@ -0,0 +1,41 @@
import math
d2 = 12.9
l1 = 85.0
l2 = 110.0
t1_deg = 474 / 2048.0 * 360.0
t2_deg = 530 / 2048.0 * 360.0
th1 = math.radians(t1_deg)
th2 = math.radians(t2_deg)
e1x = -d2 + l1 * math.cos(th1)
e1y = l1 * math.sin(th1)
e2x = d2 + l1 * math.cos(th2)
e2y = l1 * math.sin(th2)
dx = e2x - e1x
dy = e2y - e1y
dist = math.sqrt(dx*dx + dy*dy)
a = dist / 2
h = math.sqrt(l2*l2 - a*a)
mx = (e1x + e2x) / 2
my = (e1y + e2y) / 2
px1 = mx + h * (dy / dist)
py1 = my + h * (-dx / dist)
px2 = mx - h * (dy / dist)
py2 = my - h * (-dx / dist)
ex = px1 if py1 >= py2 else px2
ey = py1 if py1 >= py2 else py2
with open("output.txt", "w") as f:
f.write(f"End Effector: {ex:.1f}, {ey:.1f}\n")
f.write(f"Elbow 1: {e1x:.1f}, {e1y:.1f}\n")
f.write(f"Elbow 2: {e2x:.1f}, {e2y:.1f}\n")
+47
View File
@@ -0,0 +1,47 @@
const fs = require('fs');
const d2 = 12.9;
const l1 = 85;
const l2 = 110;
function stepsToRad(steps) {
return (steps / 2048) * 2 * Math.PI;
}
function render(steps1, steps2) {
const t1 = stepsToRad(steps1);
const t2 = stepsToRad(steps2);
const e1x = -d2 + l1 * Math.cos(t1);
const e1y = l1 * Math.sin(t1);
const e2x = d2 + l1 * Math.cos(t2);
const e2y = l1 * Math.sin(t2);
const dx = e2x - e1x;
const dy = e2y - e1y;
const dist = Math.sqrt(dx*dx + dy*dy);
let endX = 0, endY = 0;
if (dist <= 2*l2 && dist >= 1e-6) {
const a = dist / 2;
const h = Math.sqrt(l2*l2 - a*a);
const mx = (e1x + e2x) / 2;
const my = (e1y + e2y) / 2;
const px1 = mx + h * (dy / dist);
const py1 = my + h * (-dx / dist);
const px2 = mx - h * (dy / dist);
const py2 = my - h * (-dx / dist);
if (py1 >= py2) { endX = px1; endY = py1; }
else { endX = px2; endY = py2; }
}
console.log(`steps1=${steps1}, steps2=${steps2}`);
console.log(`t1=${(t1*180/Math.PI).toFixed(1)}°, t2=${(t2*180/Math.PI).toFixed(1)}°`);
console.log(`e1=(${e1x.toFixed(1)}, ${e1y.toFixed(1)})`);
console.log(`e2=(${e2x.toFixed(1)}, ${e2y.toFixed(1)})`);
console.log(`end=(${endX.toFixed(1)}, ${endY.toFixed(1)})`);
}
render(854, 41);
render(-41, 967);
+3 -2
View File
@@ -294,8 +294,9 @@ function armsCrossed(theta1, theta2) {
return false; return false;
} }
const cross1 = lineIntersectsBox(m1x, m1y, e1x, e1y, -BOX_HALF_W, BOX_HALF_W, BOX_Y_MIN, BOX_Y_MAX); // Motors are at Y=0, so they are inside BOX_Y_MIN=-10. Start the collision box above the motors.
const cross2 = lineIntersectsBox(m2x, m2y, e2x, e2y, -BOX_HALF_W, BOX_HALF_W, BOX_Y_MIN, BOX_Y_MAX); const cross1 = lineIntersectsBox(m1x, m1y, e1x, e1y, -BOX_HALF_W, BOX_HALF_W, 15, BOX_Y_MAX);
const cross2 = lineIntersectsBox(m2x, m2y, e2x, e2y, -BOX_HALF_W, BOX_HALF_W, 15, BOX_Y_MAX);
// Also check if elbows went rogue (e.g. wrapped entirely around the wrong side) // Also check if elbows went rogue (e.g. wrapped entirely around the wrong side)
const e1_rogue = e1x > BOX_HALF_W && e1y < BOX_Y_MAX; const e1_rogue = e1x > BOX_HALF_W && e1y < BOX_Y_MAX;