From d7440f882dd6caea78b153bcb3b53e460ae1d830 Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Mon, 1 Oct 2018 19:25:37 -0400 Subject: [PATCH] Fixing #1505: WeDo2 motor power between 0-30ish doesn't power the motor. --- src/extensions/scratch3_wedo2/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/extensions/scratch3_wedo2/index.js b/src/extensions/scratch3_wedo2/index.js index d0a118cb5..850141c24 100644 --- a/src/extensions/scratch3_wedo2/index.js +++ b/src/extensions/scratch3_wedo2/index.js @@ -226,7 +226,15 @@ class WeDo2Motor { * @param {int} value - this motor's new power level, in the range [0,100]. */ set power (value) { - this._power = Math.max(0, Math.min(value, 100)); + const p = Math.max(0, Math.min(value, 100)); + // Lego Wedo 2.0 hub only turns motors at power range [30 - 100], so + // map value from [0 - 100] to [30 - 100]. + if (p === 0) { + this._power = 0; + } else { + const delta = 100 / p; + this._power = 30 + (70 / delta); + } } /** @@ -305,7 +313,7 @@ class WeDo2Motor { */ turnOff (useLimiter = true) { if (this._power === 0) return; - + const cmd = this._parent.generateOutputCommand( this._index + 1, WeDo2Command.MOTOR_POWER,