kine
This commit is contained in:
+13
-3
@@ -319,10 +319,20 @@ function lookup(char) {
|
|||||||
|
|
||||||
// ── Unit converters ───────────────────────────────────────────────
|
// ── Unit converters ───────────────────────────────────────────────
|
||||||
function stepsToRad(steps) {
|
function stepsToRad(steps) {
|
||||||
return (steps / ARM.STEPS_PER_REV) * 2 * Math.PI;
|
// Physical motors are wired such that + steps is CW.
|
||||||
|
// We negate here so UI math maps correctly to hardware.
|
||||||
|
return -(steps / ARM.STEPS_PER_REV) * 2 * Math.PI;
|
||||||
}
|
}
|
||||||
function radToSteps(rad) {
|
function radToSteps(rad) {
|
||||||
return Math.round((rad / (2 * Math.PI)) * ARM.STEPS_PER_REV);
|
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 stepsToDeg(steps) {
|
function stepsToDeg(steps) {
|
||||||
return steps * ARM.STEP_ANGLE_DEG;
|
return steps * ARM.STEP_ANGLE_DEG;
|
||||||
@@ -334,5 +344,5 @@ function radToDeg(rad) {
|
|||||||
export default {
|
export default {
|
||||||
ARM, LIMITS, LOOKUP_TABLE,
|
ARM, LIMITS, LOOKUP_TABLE,
|
||||||
solve, forward, armsCrossed, checkWorkspace, lookup,
|
solve, forward, armsCrossed, checkWorkspace, lookup,
|
||||||
stepsToRad, radToSteps, stepsToDeg, radToDeg,
|
stepsToRad, radToSteps, radToStepsClosest, stepsToDeg, radToDeg,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ async function moveToXY(targetX, targetY) {
|
|||||||
|
|
||||||
const { theta1, theta2 } = IK.solve(targetX, targetY);
|
const { theta1, theta2 } = IK.solve(targetX, targetY);
|
||||||
|
|
||||||
const newSteps1 = IK.radToSteps(theta1);
|
const newSteps1 = IK.radToStepsClosest(theta1, steps1);
|
||||||
const newSteps2 = IK.radToSteps(theta2);
|
const newSteps2 = IK.radToStepsClosest(theta2, steps2);
|
||||||
|
|
||||||
const cmd = `X:${newSteps1},${newSteps2}`;
|
const cmd = `X:${newSteps1},${newSteps2}`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user