kinematic motion controller
This commit is contained in:
+10
-29
@@ -2,6 +2,7 @@ import BLE from './ble.js';
|
||||
import UI from './ui.js';
|
||||
import IK from './kinematics.js';
|
||||
import Settings from './settings.js';
|
||||
import Motion from './motion.js';
|
||||
|
||||
let isRunning = false;
|
||||
|
||||
@@ -52,41 +53,21 @@ export default {
|
||||
continue;
|
||||
}
|
||||
|
||||
const wsCheck = IK.checkWorkspace(targetX, targetY);
|
||||
if (!wsCheck.ok) {
|
||||
UI.log(`⛔ ${wsCheck.reason} [${label}]`, 'error');
|
||||
continue; // or break? let's continue
|
||||
}
|
||||
|
||||
const res = IK.solve(targetX, targetY);
|
||||
if (!res.reachable || IK.armsCrossed(res.theta1, res.theta2)) {
|
||||
UI.log(`Target ${label} is unreachable or crosses arms.`, 'error');
|
||||
continue;
|
||||
}
|
||||
|
||||
const newSteps1 = IK.radToStepsAbsolute(res.theta1, 1);
|
||||
const newSteps2 = IK.radToStepsAbsolute(res.theta2, 2);
|
||||
|
||||
const cmd = `X:${newSteps1},${newSteps2}`;
|
||||
|
||||
UI.log(`Seq step: ${label}`, 'info');
|
||||
|
||||
if (BLE.isConnected()) {
|
||||
try {
|
||||
await BLE.write(cmd);
|
||||
} catch (e) {
|
||||
UI.log(`BLE error: ${e.message}`, 'error');
|
||||
isRunning = false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
steps1 = newSteps1;
|
||||
steps2 = newSteps2;
|
||||
const success = await Motion.goto(targetX, targetY, step.mode || 'direct');
|
||||
if (!success) {
|
||||
isRunning = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BLE.isConnected()) {
|
||||
const st = Motion.getSteps();
|
||||
steps1 = st.steps1;
|
||||
steps2 = st.steps2;
|
||||
if (onStepComplete) {
|
||||
onStepComplete(steps1, steps2);
|
||||
}
|
||||
console.log(`[sim] ${cmd}`);
|
||||
}
|
||||
|
||||
// Wait for delay
|
||||
|
||||
Reference in New Issue
Block a user