Upgrade pathing
This commit is contained in:
+11
-7
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user