kinematics
This commit is contained in:
+19
-6
@@ -118,19 +118,32 @@ class CmdCallbacks : public BLECharacteristicCallbacks {
|
|||||||
|
|
||||||
// ─── Command parser ───────────────────────────────────────────────
|
// ─── Command parser ───────────────────────────────────────────────
|
||||||
void parseCommand(const String &cmd) {
|
void parseCommand(const String &cmd) {
|
||||||
// S1+<n> or S1-<n>
|
// S1+<n> or S1-<n> (Relative)
|
||||||
if (cmd.startsWith("S1") && cmd.length() > 2) {
|
if (cmd.startsWith("S1") && cmd.length() > 2) {
|
||||||
long steps =
|
long steps = cmd.substring(2).toInt();
|
||||||
cmd.substring(2).toInt(); // '+' or '-' prefix handled by toInt()
|
|
||||||
stepper1.move(steps);
|
stepper1.move(steps);
|
||||||
Serial.printf("[S1] Move %+ld steps\n", steps);
|
Serial.printf("[S1] Move relative %+ld steps\n", steps);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// S2+<n> or S2-<n>
|
// S2+<n> or S2-<n> (Relative)
|
||||||
if (cmd.startsWith("S2") && cmd.length() > 2) {
|
if (cmd.startsWith("S2") && cmd.length() > 2) {
|
||||||
long steps = cmd.substring(2).toInt();
|
long steps = cmd.substring(2).toInt();
|
||||||
stepper2.move(steps);
|
stepper2.move(steps);
|
||||||
Serial.printf("[S2] Move %+ld steps\n", steps);
|
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;
|
||||||
|
}
|
||||||
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
// SPD:<n>
|
// SPD:<n>
|
||||||
|
|||||||
@@ -197,11 +197,9 @@ 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 delta1 = newSteps1 - steps1;
|
|
||||||
const delta2 = newSteps2 - steps2;
|
|
||||||
|
|
||||||
const cmd1 = `S1${delta1 >= 0 ? '+' : ''}${delta1}`;
|
const cmd1 = `X1:${newSteps1}`;
|
||||||
const cmd2 = `S2${delta2 >= 0 ? '+' : ''}${delta2}`;
|
const cmd2 = `X2:${newSteps2}`;
|
||||||
|
|
||||||
if (BLE.isConnected()) {
|
if (BLE.isConnected()) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -66,11 +66,9 @@ 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 delta1 = newSteps1 - steps1;
|
|
||||||
const delta2 = newSteps2 - steps2;
|
|
||||||
|
|
||||||
const cmd1 = `S1${delta1 >= 0 ? '+' : ''}${delta1}`;
|
const cmd1 = `X1:${newSteps1}`;
|
||||||
const cmd2 = `S2${delta2 >= 0 ? '+' : ''}${delta2}`;
|
const cmd2 = `X2:${newSteps2}`;
|
||||||
|
|
||||||
UI.log(`Seq step: ${label}`, 'info');
|
UI.log(`Seq step: ${label}`, 'info');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user