From eeb2cb191bb45f5256d9dcae79a4a56b3860c8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?PROFERIS=20-=20Mi=C2=B3osz=20Stocki?= Date: Wed, 8 Jul 2026 13:30:30 +0200 Subject: [PATCH] kin --- src/main.cpp | 22 ++++++++++------------ web/js/sections/stepper-test.js | 8 +++----- web/js/sequence-runner.js | 8 +++----- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8b61195..47c741d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,18 +132,16 @@ void parseCommand(const String &cmd) { Serial.printf("[S2] Move relative %+ld steps\n", steps); return; } - // X1: (Absolute) - if (cmd.startsWith("X1:")) { - long target = cmd.substring(3).toInt(); - stepper1.moveTo(target); - Serial.printf("[S1] Move absolute to %ld\n", target); - return; - } - // X2: (Absolute) - if (cmd.startsWith("X2:")) { - long target = cmd.substring(3).toInt(); - stepper2.moveTo(target); - Serial.printf("[S2] Move absolute to %ld\n", target); + // X:, (Absolute combined) + if (cmd.startsWith("X:")) { + int commaIdx = cmd.indexOf(','); + if (commaIdx != -1) { + long target1 = cmd.substring(2, commaIdx).toInt(); + long target2 = cmd.substring(commaIdx + 1).toInt(); + stepper1.moveTo(target1); + stepper2.moveTo(target2); + Serial.printf("[X] Move absolute to %ld, %ld\n", target1, target2); + } return; } // SPD: diff --git a/web/js/sections/stepper-test.js b/web/js/sections/stepper-test.js index df34b12..4c46fe7 100644 --- a/web/js/sections/stepper-test.js +++ b/web/js/sections/stepper-test.js @@ -198,13 +198,11 @@ async function moveToXY(targetX, targetY) { const newSteps1 = IK.radToSteps(theta1); const newSteps2 = IK.radToSteps(theta2); - const cmd1 = `X1:${newSteps1}`; - const cmd2 = `X2:${newSteps2}`; + const cmd = `X:${newSteps1},${newSteps2}`; if (BLE.isConnected()) { try { - await BLE.write(cmd1); - await BLE.write(cmd2); + await BLE.write(cmd); // Do not update steps1/steps2 here; let the P: notify handler update the UI smoothly } catch (e) { UI.log(`BLE error: ${e.message}`, 'error'); @@ -213,7 +211,7 @@ async function moveToXY(targetX, targetY) { steps1 = newSteps1; steps2 = newSteps2; renderArm(theta1, theta2); - const simMsg = `[sim] IK→ θ1=${IK.radToDeg(theta1).toFixed(1)}° θ2=${IK.radToDeg(theta2).toFixed(1)}° | ${cmd1} ${cmd2}`; + const simMsg = `[sim] IK→ θ1=${IK.radToDeg(theta1).toFixed(1)}° θ2=${IK.radToDeg(theta2).toFixed(1)}° | ${cmd}`; console.log(simMsg); UI.log(simMsg, 'info'); } diff --git a/web/js/sequence-runner.js b/web/js/sequence-runner.js index 107ceaf..361cefa 100644 --- a/web/js/sequence-runner.js +++ b/web/js/sequence-runner.js @@ -67,15 +67,13 @@ export default { const newSteps1 = IK.radToSteps(res.theta1); const newSteps2 = IK.radToSteps(res.theta2); - const cmd1 = `X1:${newSteps1}`; - const cmd2 = `X2:${newSteps2}`; + const cmd = `X:${newSteps1},${newSteps2}`; UI.log(`Seq step: ${label}`, 'info'); if (BLE.isConnected()) { try { - await BLE.write(cmd1); - await BLE.write(cmd2); + await BLE.write(cmd); } catch (e) { UI.log(`BLE error: ${e.message}`, 'error'); isRunning = false; @@ -88,7 +86,7 @@ export default { if (onStepComplete) { onStepComplete(steps1, steps2); } - console.log(`[sim] ${cmd1} ${cmd2}`); + console.log(`[sim] ${cmd}`); } // Wait for delay