From adb4c0482cf6cc23ca095287a803e83d5fe2d7f5 Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Tue, 23 Apr 2019 19:05:12 -0400 Subject: [PATCH 1/4] Reversing the sign on Motor A reported position. --- src/extensions/scratch3_boost/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index f36744740..8c7d71830 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1888,7 +1888,11 @@ class Scratch3BoostBlocks { return false; } if (portID && this._peripheral.motor(portID)) { - return MathUtil.wrapClamp(this._peripheral.motor(portID).position, 0, 360); + let val = MathUtil.wrapClamp(this._peripheral.motor(portID).position, 0, 360); + if (portID === BoostPort.A) { + val *= -1; + } + return val; } return 0; } From e3ec61417347d184676210a5aadfba228484feb8 Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Wed, 24 Apr 2019 11:24:56 -0400 Subject: [PATCH 2/4] Move reversing of sign to _onMessage, before clamping. --- src/extensions/scratch3_boost/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 8c7d71830..ae7411792 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1016,7 +1016,10 @@ class Boost { break; case BoostIO.MOTOREXT: case BoostIO.MOTORINT: - this.motor(portID).position = int32ArrayToNumber(data.slice(4, 8)); + // The motor position in port A is reversed by design, so we need + // to reverse it here so that all motors match + this.motor(portID).position = ((portID === BoostPort.A) ? -1 : 1) * + int32ArrayToNumber(data.slice(4, 8)); break; case BoostIO.CURRENT: case BoostIO.VOLTAGE: @@ -1888,13 +1891,8 @@ class Scratch3BoostBlocks { return false; } if (portID && this._peripheral.motor(portID)) { - let val = MathUtil.wrapClamp(this._peripheral.motor(portID).position, 0, 360); - if (portID === BoostPort.A) { - val *= -1; - } - return val; + return MathUtil.wrapClamp(this._peripheral.motor(portID).position, 0, 360); } - return 0; } /** From a61b01628e02d034fb4b43aeb31c8ae9d135d40b Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Wed, 24 Apr 2019 11:28:29 -0400 Subject: [PATCH 3/4] Putting back a line deleted by accident. --- src/extensions/scratch3_boost/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index ae7411792..61af3e418 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1893,6 +1893,7 @@ class Scratch3BoostBlocks { if (portID && this._peripheral.motor(portID)) { return MathUtil.wrapClamp(this._peripheral.motor(portID).position, 0, 360); } + return 0; } /** From a0f0a4092ca752c4fe94577574d7121e57b2fa33 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Apr 2019 22:42:54 -0400 Subject: [PATCH 4/4] Moving position reversal back to reporter to avoid conflicts. --- src/extensions/scratch3_boost/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 61af3e418..c10f7a7c3 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1016,10 +1016,7 @@ class Boost { break; case BoostIO.MOTOREXT: case BoostIO.MOTORINT: - // The motor position in port A is reversed by design, so we need - // to reverse it here so that all motors match - this.motor(portID).position = ((portID === BoostPort.A) ? -1 : 1) * - int32ArrayToNumber(data.slice(4, 8)); + this.motor(portID).position = int32ArrayToNumber(data.slice(4, 8)); break; case BoostIO.CURRENT: case BoostIO.VOLTAGE: @@ -1891,7 +1888,13 @@ class Scratch3BoostBlocks { return false; } if (portID && this._peripheral.motor(portID)) { - return MathUtil.wrapClamp(this._peripheral.motor(portID).position, 0, 360); + let val = this._peripheral.motor(portID).position; + // Boost motor A position direction is reversed by design + // so we have to reverse the position here + if (portID === BoostPort.A) { + val *= -1; + } + return MathUtil.wrapClamp(val, 0, 360); } return 0; }