properly setting multiple-motor options
This commit is contained in:
parent
6836852122
commit
367b1b0d1a
@ -242,7 +242,7 @@ namespace motors {
|
|||||||
if (!this._initialized) {
|
if (!this._initialized) {
|
||||||
this._initialized = true;
|
this._initialized = true;
|
||||||
// specify motor size on this port
|
// 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)
|
b.setNumber(NumberFormat.Int8LE, 2, this._large ? 0x07 : 0x08)
|
||||||
writePWM(b)
|
writePWM(b)
|
||||||
}
|
}
|
||||||
@ -352,11 +352,15 @@ namespace motors {
|
|||||||
protected __init() {
|
protected __init() {
|
||||||
if (!this._initialized) {
|
if (!this._initialized) {
|
||||||
this._initialized = true;
|
this._initialized = true;
|
||||||
const b = mkCmd(this._port, DAL.opOutputSetType, 1)
|
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
|
b.setNumber(NumberFormat.Int8LE, 2, 0x07) // large motor
|
||||||
writePWM(b)
|
writePWM(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected __setSpeed(speed: number) {
|
protected __setSpeed(speed: number) {
|
||||||
syncMotors(this._port, {
|
syncMotors(this._port, {
|
||||||
@ -389,6 +393,7 @@ namespace motors {
|
|||||||
//% inlineInputMode=inline
|
//% inlineInputMode=inline
|
||||||
//% group="Chassis"
|
//% group="Chassis"
|
||||||
steer(steering: number, speed: number, value: number, unit: MoveUnit) {
|
steer(steering: number, speed: number, value: number, unit: MoveUnit) {
|
||||||
|
this.__init();
|
||||||
speed = Math.clamp(-100, 100, speed >> 0);
|
speed = Math.clamp(-100, 100, speed >> 0);
|
||||||
if (!speed) {
|
if (!speed) {
|
||||||
stop(this._port, this._brake);
|
stop(this._port, this._brake);
|
||||||
|
Loading…
Reference in New Issue
Block a user