kinematic motion controller

This commit is contained in:
osiu97
2026-07-08 18:14:17 +02:00
parent e1416f6979
commit 57ea3f7b4a
6 changed files with 220 additions and 138 deletions
+5 -48
View File
@@ -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';
import { buildQuickSequencesHTML, initQuickSequences } from '../quick-sequences.js';
let eventCleanup = [];
@@ -16,6 +17,7 @@ function syncStateFromStorage() {
isHomed = localStorage.getItem('wiji_homed') === 'true';
steps1 = isHomed ? parseInt(localStorage.getItem('wiji_steps1') || IK.ARM.HOME_STEPS.m1) : IK.ARM.HOME_STEPS.m1;
steps2 = isHomed ? parseInt(localStorage.getItem('wiji_steps2') || IK.ARM.HOME_STEPS.m2) : IK.ARM.HOME_STEPS.m2;
Motion.setSteps(steps1, steps2);
}
function saveSteps() {
@@ -255,54 +257,8 @@ async function executeMove(spot) {
}
const mode = document.getElementById('mode-select').value;
if (mode !== 'direct') {
UI.log(`Mode '${mode}' not fully implemented yet! Using direct move.`, 'warn');
}
// Calculate IK
const wsCheck = IK.checkWorkspace(spot.x, spot.y);
if (!wsCheck.ok) {
UI.log(`${wsCheck.reason}`, 'error');
return;
}
const res = IK.solve(spot.x, spot.y);
if (!res.reachable) {
UI.log(`Target ${spot.label} is unreachable geometrically.`, 'error');
return;
}
if (IK.armsCrossed(res.theta1, res.theta2)) {
UI.log(`Target ${spot.label} rejected: elbows crossed!`, 'error');
return;
}
const newSteps1 = IK.radToStepsAbsolute(res.theta1, 1);
const newSteps2 = IK.radToStepsAbsolute(res.theta2, 2);
const delta1 = newSteps1 - steps1;
const delta2 = newSteps2 - steps2;
const cmd1 = `S1${delta1 >= 0 ? '+' : ''}${delta1}`;
const cmd2 = `S2${delta2 >= 0 ? '+' : ''}${delta2}`;
UI.log(`Moving to ${spot.label} (${spot.x}, ${spot.y})`, 'success');
if (BLE.isConnected()) {
try {
await BLE.write(cmd1);
await BLE.write(cmd2);
} catch (e) {
UI.log(`BLE error: ${e.message}`, 'error');
}
} else {
steps1 = newSteps1;
steps2 = newSteps2;
saveSteps();
updatePositionReadout();
const simMsg = `[sim] ${cmd1} ${cmd2}`;
console.log(simMsg);
UI.log(simMsg, 'info');
}
UI.log(`Moving to ${spot.label} (${spot.x}, ${spot.y}) [${mode}]`, 'success');
await Motion.goto(spot.x, spot.y, mode);
}
export default {
@@ -369,6 +325,7 @@ export default {
} else {
steps1 = IK.ARM.HOME_STEPS.m1;
steps2 = IK.ARM.HOME_STEPS.m2;
Motion.setSteps(steps1, steps2);
saveSteps();
updatePositionReadout();
UI.log('[sim] HOMEALL', 'info');