From 367b1b0d1a47c136595fd7df2b77dbb5b403f973 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Sun, 17 Dec 2017 23:00:07 -0800 Subject: [PATCH 1/2] properly setting multiple-motor options --- libs/core/output.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/core/output.ts b/libs/core/output.ts index 2781c74a..96f679cb 100644 --- a/libs/core/output.ts +++ b/libs/core/output.ts @@ -242,7 +242,7 @@ namespace motors { if (!this._initialized) { this._initialized = true; // specify motor size on this port - const b = mkCmd(this._port, DAL.opOutputSetType, 1) + const b = mkCmd(outOffset(this._port), DAL.opOutputSetType, 1) b.setNumber(NumberFormat.Int8LE, 2, this._large ? 0x07 : 0x08) writePWM(b) } @@ -352,9 +352,13 @@ namespace motors { protected __init() { if (!this._initialized) { this._initialized = true; - const b = mkCmd(this._port, DAL.opOutputSetType, 1) - b.setNumber(NumberFormat.Int8LE, 2, 0x07) // large motor - writePWM(b) + for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { + if (this._port & (1 << i)) { + const b = mkCmd(outOffset(1 << i), DAL.opOutputSetType, 1) + b.setNumber(NumberFormat.Int8LE, 2, 0x07) // large motor + writePWM(b) + } + } } } @@ -389,6 +393,7 @@ namespace motors { //% inlineInputMode=inline //% group="Chassis" steer(steering: number, speed: number, value: number, unit: MoveUnit) { + this.__init(); speed = Math.clamp(-100, 100, speed >> 0); if (!speed) { stop(this._port, this._brake); From 217958aec367cd029fef5ac6698847e7f4d7de21 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Sun, 17 Dec 2017 23:19:38 -0800 Subject: [PATCH 2/2] fix polarity --- libs/core/output.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/core/output.ts b/libs/core/output.ts index 96f679cb..01f90e53 100644 --- a/libs/core/output.ts +++ b/libs/core/output.ts @@ -144,9 +144,9 @@ namespace motors { setReversed(reversed: boolean) { this.__init(); const b = mkCmd(this._port, DAL.opOutputPolarity, 1) - b.setNumber(NumberFormat.Int8LE, 2, reversed ? -1 : 1); + b.setNumber(NumberFormat.Int8LE, 2, reversed ? 0 : 1); writePWM(b) - } + } /** * Stops the motor(s).