This commit is contained in:
PROFERIS - Mi³osz Stocki
2026-07-08 13:30:30 +02:00
parent cf71803fc4
commit eeb2cb191b
3 changed files with 16 additions and 22 deletions
+9 -11
View File
@@ -132,18 +132,16 @@ void parseCommand(const String &cmd) {
Serial.printf("[S2] Move relative %+ld steps\n", steps);
return;
}
// X1:<n> (Absolute)
if (cmd.startsWith("X1:")) {
long target = cmd.substring(3).toInt();
stepper1.moveTo(target);
Serial.printf("[S1] Move absolute to %ld\n", target);
return;
// X:<n1>,<n2> (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);
}
// X2:<n> (Absolute)
if (cmd.startsWith("X2:")) {
long target = cmd.substring(3).toInt();
stepper2.moveTo(target);
Serial.printf("[S2] Move absolute to %ld\n", target);
return;
}
// SPD:<n>
+3 -5
View File
@@ -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');
}
+3 -5
View File
@@ -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