kin
This commit is contained in:
+10
-12
@@ -132,18 +132,16 @@ void parseCommand(const String &cmd) {
|
|||||||
Serial.printf("[S2] Move relative %+ld steps\n", steps);
|
Serial.printf("[S2] Move relative %+ld steps\n", steps);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// X1:<n> (Absolute)
|
// X:<n1>,<n2> (Absolute combined)
|
||||||
if (cmd.startsWith("X1:")) {
|
if (cmd.startsWith("X:")) {
|
||||||
long target = cmd.substring(3).toInt();
|
int commaIdx = cmd.indexOf(',');
|
||||||
stepper1.moveTo(target);
|
if (commaIdx != -1) {
|
||||||
Serial.printf("[S1] Move absolute to %ld\n", target);
|
long target1 = cmd.substring(2, commaIdx).toInt();
|
||||||
return;
|
long target2 = cmd.substring(commaIdx + 1).toInt();
|
||||||
}
|
stepper1.moveTo(target1);
|
||||||
// X2:<n> (Absolute)
|
stepper2.moveTo(target2);
|
||||||
if (cmd.startsWith("X2:")) {
|
Serial.printf("[X] Move absolute to %ld, %ld\n", target1, target2);
|
||||||
long target = cmd.substring(3).toInt();
|
}
|
||||||
stepper2.moveTo(target);
|
|
||||||
Serial.printf("[S2] Move absolute to %ld\n", target);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// SPD:<n>
|
// SPD:<n>
|
||||||
|
|||||||
@@ -198,13 +198,11 @@ async function moveToXY(targetX, targetY) {
|
|||||||
const newSteps1 = IK.radToSteps(theta1);
|
const newSteps1 = IK.radToSteps(theta1);
|
||||||
const newSteps2 = IK.radToSteps(theta2);
|
const newSteps2 = IK.radToSteps(theta2);
|
||||||
|
|
||||||
const cmd1 = `X1:${newSteps1}`;
|
const cmd = `X:${newSteps1},${newSteps2}`;
|
||||||
const cmd2 = `X2:${newSteps2}`;
|
|
||||||
|
|
||||||
if (BLE.isConnected()) {
|
if (BLE.isConnected()) {
|
||||||
try {
|
try {
|
||||||
await BLE.write(cmd1);
|
await BLE.write(cmd);
|
||||||
await BLE.write(cmd2);
|
|
||||||
// Do not update steps1/steps2 here; let the P: notify handler update the UI smoothly
|
// Do not update steps1/steps2 here; let the P: notify handler update the UI smoothly
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
UI.log(`BLE error: ${e.message}`, 'error');
|
UI.log(`BLE error: ${e.message}`, 'error');
|
||||||
@@ -213,7 +211,7 @@ async function moveToXY(targetX, targetY) {
|
|||||||
steps1 = newSteps1;
|
steps1 = newSteps1;
|
||||||
steps2 = newSteps2;
|
steps2 = newSteps2;
|
||||||
renderArm(theta1, theta2);
|
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);
|
console.log(simMsg);
|
||||||
UI.log(simMsg, 'info');
|
UI.log(simMsg, 'info');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,15 +67,13 @@ export default {
|
|||||||
const newSteps1 = IK.radToSteps(res.theta1);
|
const newSteps1 = IK.radToSteps(res.theta1);
|
||||||
const newSteps2 = IK.radToSteps(res.theta2);
|
const newSteps2 = IK.radToSteps(res.theta2);
|
||||||
|
|
||||||
const cmd1 = `X1:${newSteps1}`;
|
const cmd = `X:${newSteps1},${newSteps2}`;
|
||||||
const cmd2 = `X2:${newSteps2}`;
|
|
||||||
|
|
||||||
UI.log(`Seq step: ${label}`, 'info');
|
UI.log(`Seq step: ${label}`, 'info');
|
||||||
|
|
||||||
if (BLE.isConnected()) {
|
if (BLE.isConnected()) {
|
||||||
try {
|
try {
|
||||||
await BLE.write(cmd1);
|
await BLE.write(cmd);
|
||||||
await BLE.write(cmd2);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
UI.log(`BLE error: ${e.message}`, 'error');
|
UI.log(`BLE error: ${e.message}`, 'error');
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
@@ -88,7 +86,7 @@ export default {
|
|||||||
if (onStepComplete) {
|
if (onStepComplete) {
|
||||||
onStepComplete(steps1, steps2);
|
onStepComplete(steps1, steps2);
|
||||||
}
|
}
|
||||||
console.log(`[sim] ${cmd1} ${cmd2}`);
|
console.log(`[sim] ${cmd}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for delay
|
// Wait for delay
|
||||||
|
|||||||
Reference in New Issue
Block a user