more kiniematics

This commit is contained in:
PROFERIS - Mi³osz Stocki
2026-07-08 13:02:04 +02:00
parent c457910bfa
commit 92820e8a15
2 changed files with 62 additions and 17 deletions
+23 -17
View File
@@ -53,6 +53,12 @@ function syncStateFromStorage() {
const 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;
// Auto-migrate the old buggy negative home position to the new positive one
if (steps1 === -1024) {
steps1 = 1024;
localStorage.setItem('wiji_steps1', 1024);
}
}
function saveSteps() {
@@ -194,10 +200,6 @@ async function moveToXY(targetX, targetY) {
const delta1 = newSteps1 - steps1;
const delta2 = newSteps2 - steps2;
steps1 = newSteps1;
steps2 = newSteps2;
renderArm(theta1, theta2);
const cmd1 = `S1${delta1 >= 0 ? '+' : ''}${delta1}`;
const cmd2 = `S2${delta2 >= 0 ? '+' : ''}${delta2}`;
@@ -205,10 +207,14 @@ async function moveToXY(targetX, targetY) {
try {
await BLE.write(cmd1);
await BLE.write(cmd2);
// Do not update steps1/steps2 here; let the P: notify handler update the UI smoothly
} catch (e) {
UI.log(`BLE error: ${e.message}`, 'error');
}
} else {
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}`;
console.log(simMsg);
UI.log(simMsg, 'info');
@@ -221,33 +227,33 @@ async function moveToXY(targetX, targetY) {
// ─────────────────────────────────────────────────────────────────
async function jogMotor(motor, delta) {
if (motor === 1) steps1 += delta;
else steps2 += delta;
renderArmFromSteps();
const cmd = `S${motor}${delta >= 0 ? '+' : ''}${delta}`;
if (BLE.isConnected()) {
await BLE.write(cmd).catch(e => UI.log(e.message, 'error'));
} else {
if (motor === 1) steps1 += delta;
else steps2 += delta;
renderArmFromSteps();
console.log(`[sim] ${cmd}`);
UI.log(`[sim] ${cmd}`, 'info');
}
}
async function zeroMotor(motor) {
if (motor === 'ALL') {
steps1 = IK.ARM.HOME_STEPS.m1;
steps2 = IK.ARM.HOME_STEPS.m2;
localStorage.setItem('wiji_homed', 'true');
} else if (motor === 1) {
steps1 = IK.ARM.HOME_STEPS.m1;
} else {
steps2 = IK.ARM.HOME_STEPS.m2;
}
renderArmFromSteps();
const cmd = motor === 'ALL' ? 'HOMEALL' : `HOME${motor}`;
if (BLE.isConnected()) {
await BLE.write(cmd).catch(e => UI.log(e.message, 'error'));
} else {
if (motor === 'ALL') {
steps1 = IK.ARM.HOME_STEPS.m1;
steps2 = IK.ARM.HOME_STEPS.m2;
localStorage.setItem('wiji_homed', 'true');
} else if (motor === 1) {
steps1 = IK.ARM.HOME_STEPS.m1;
} else {
steps2 = IK.ARM.HOME_STEPS.m2;
}
renderArmFromSteps();
console.log(`[sim] ${cmd}`);
UI.log(`[sim] ${cmd}`, 'info');
}