From 512e704fffe0bff8ab2703a254beef2f36936fa2 Mon Sep 17 00:00:00 2001 From: Owen Trueblood Date: Fri, 3 Nov 2023 15:03:08 -0400 Subject: [PATCH] Avoid accumulation of position error --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 63754fa..4e7a009 100644 --- a/src/index.js +++ b/src/index.js @@ -265,11 +265,12 @@ export class AxiDraw { // https://corexy.com/theory.html const steps = { - x: delta.x * STEPS_PER_MM, - y: delta.y * STEPS_PER_MM, + x: Math.floor(delta.x * STEPS_PER_MM), + y: Math.floor(delta.y * STEPS_PER_MM), }; - this.lastCommandedPos = this.targetPos; + this.lastCommandedPos.x += steps.x / STEPS_PER_MM; + this.lastCommandedPos.y += steps.y / STEPS_PER_MM; await this.#command(async () => { // Wait for the command to be sent and acknowledged