From cf3d17e1f57430c8704678b12b2062e8d55f9ce6 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Thu, 14 Jun 2018 17:23:55 +0100 Subject: [PATCH] Better distance calculations --- boosthub.js | 2 +- test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/boosthub.js b/boosthub.js index 89116de..d021c8a 100644 --- a/boosthub.js +++ b/boosthub.js @@ -284,7 +284,7 @@ class BoostHub extends Hub { distance += 1 / partial; } - this.emit("distance", port.id, Math.floor(distance * 25.4)); + this.emit("distance", port.id, Math.floor(distance * 25.4) - 20); break; } case Consts.Devices.WEDO2_TILT: diff --git a/test.js b/test.js index 8c693d8..1efbfa9 100644 --- a/test.js +++ b/test.js @@ -18,7 +18,7 @@ lpf2.on("discover", (hub) => { moveHub.on("distance", (port, distance) => { console.log(`Distance ${distance} received on port ${port}`); - if (distance < 80) { + if (distance < 100) { moveHub.setMotorSpeed("D", 40); } else { moveHub.setMotorSpeed("D", 0); @@ -31,7 +31,7 @@ lpf2.on("discover", (hub) => { wedoHub.on("distance", (port, distance) => { console.log(`Distance ${distance} received on port ${port}`); - if (distance < 80) { + if (distance < 100) { wedoHub.setMotorSpeed("B", 40); } else { wedoHub.setMotorSpeed("B", 0);