Upgrade pathing

This commit is contained in:
osiu97
2026-07-08 17:52:38 +02:00
parent a912d23b7c
commit e1416f6979
6 changed files with 52 additions and 16 deletions
+11 -7
View File
@@ -327,12 +327,16 @@ function radToSteps(rad) {
return Math.round(-(rad / (2 * Math.PI)) * ARM.STEPS_PER_REV);
}
function radToStepsClosest(rad, currentSteps) {
let target = radToSteps(rad);
// Ensure we take the shortest path instead of winding up the motors
while (target - currentSteps > 1024) target -= 2048;
while (target - currentSteps < -1024) target += 2048;
return target;
function radToStepsAbsolute(rad, motor) {
let steps = radToSteps(rad);
// Motor 1 (Left) is constrained near 1536 steps (90 deg, UP)
// Motor 2 (Right) is constrained near -512 steps (90 deg, UP)
const center = motor === 1 ? 1536 : -512;
// Snap the step position to the closest equivalent angle around the center.
// This guarantees we always take the "top" physical path and never wrap through the bottom.
while (steps - center > 1024) steps -= 2048;
while (steps - center < -1024) steps += 2048;
return steps;
}
function stepsToDeg(steps) {
return steps * ARM.STEP_ANGLE_DEG;
@@ -344,5 +348,5 @@ function radToDeg(rad) {
export default {
ARM, LIMITS, LOOKUP_TABLE,
solve, forward, armsCrossed, checkWorkspace, lookup,
stepsToRad, radToSteps, radToStepsClosest, stepsToDeg, radToDeg,
stepsToRad, radToSteps, radToStepsAbsolute, stepsToDeg, radToDeg,
};