mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
- Motor-power functionality changed!
-- Using a max-power setting of 100 rather than following the speed in the motor-commands will allow motors to run at really slow speeds. -- As a result, motor-commands now use max-power of 100 regardless of speed and setMotorPower no longer scales according to a minimum speed of 20. - BLE-rate enums consolidated into BoostBLE enum
This commit is contained in:
parent
a4e005cf2b
commit
873b56c985
2 changed files with 2511 additions and 2492 deletions
4960
package-lock.json
generated
4960
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -28,20 +28,17 @@ const iconURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5z
|
||||||
|
|
||||||
const BoostBLE = {
|
const BoostBLE = {
|
||||||
service: '00001623-1212-efde-1623-785feabcd123',
|
service: '00001623-1212-efde-1623-785feabcd123',
|
||||||
characteristic: '00001624-1212-efde-1623-785feabcd123'
|
characteristic: '00001624-1212-efde-1623-785feabcd123',
|
||||||
|
sendInterval: 100,
|
||||||
|
sendRateMax: 20
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A time interval to wait (in milliseconds) while a block that sends a BLE message is running.
|
* Boost Motor Max Power.
|
||||||
* @type {number}
|
* @constant {number}
|
||||||
*/
|
*/
|
||||||
const BLESendInterval = 100;
|
|
||||||
|
|
||||||
/**
|
const BoostMotorMaxPower = 100;
|
||||||
* A maximum number of BLE message sends per second, to be enforced by the rate limiter.
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
const BLESendRateMax = 20;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for Boost sensor and actuator types.
|
* Enum for Boost sensor and actuator types.
|
||||||
|
@ -80,7 +77,6 @@ const BoostOutputCommandFeedback = {
|
||||||
BUSY_OR_FULL: 0x10
|
BUSY_OR_FULL: 0x10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for physical Boost Ports
|
* Enum for physical Boost Ports
|
||||||
* @readonly
|
* @readonly
|
||||||
|
@ -364,14 +360,11 @@ class BoostMotor {
|
||||||
*/
|
*/
|
||||||
set power (value) {
|
set power (value) {
|
||||||
const p = Math.max(0, Math.min(value, 100));
|
const p = Math.max(0, Math.min(value, 100));
|
||||||
|
// The Boost motors barely move at speed 1 - solution is to step up to 2.
|
||||||
// Lego Boost hub only turns motors at power range [20 - 100], so
|
if (p === 1) {
|
||||||
// map value from [0 - 100] to [20 - 100].
|
this._power = 2;
|
||||||
if (p === 0) {
|
|
||||||
this._power = 0;
|
|
||||||
} else {
|
} else {
|
||||||
const delta = 100 / p;
|
this._power = p;
|
||||||
this._power = 20 + (80 / delta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +421,7 @@ class BoostMotor {
|
||||||
BoostOutputSubCommand.START_SPEED,
|
BoostOutputSubCommand.START_SPEED,
|
||||||
[
|
[
|
||||||
this._power * this._direction,
|
this._power * this._direction,
|
||||||
this._power,
|
BoostMotorMaxPower,
|
||||||
BoostMotorProfile.DO_NOT_USE
|
BoostMotorProfile.DO_NOT_USE
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -466,7 +459,7 @@ class BoostMotor {
|
||||||
[
|
[
|
||||||
...numberToInt32Array(degrees),
|
...numberToInt32Array(degrees),
|
||||||
this._power * this._direction * direction, // power in range 0-100
|
this._power * this._direction * direction, // power in range 0-100
|
||||||
this._power, // max speed
|
BoostMotorMaxPower, // max speed
|
||||||
BoostMotorEndState.BRAKE,
|
BoostMotorEndState.BRAKE,
|
||||||
BoostMotorProfile.DO_NOT_USE
|
BoostMotorProfile.DO_NOT_USE
|
||||||
] // byte for using acceleration/braking profile
|
] // byte for using acceleration/braking profile
|
||||||
|
@ -599,7 +592,7 @@ class Boost {
|
||||||
* @type {RateLimiter}
|
* @type {RateLimiter}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._rateLimiter = new RateLimiter(BLESendRateMax);
|
this._rateLimiter = new RateLimiter(BoostBLE.sendRateMax);
|
||||||
|
|
||||||
this.disconnect = this.disconnect.bind(this);
|
this.disconnect = this.disconnect.bind(this);
|
||||||
this._onConnect = this._onConnect.bind(this);
|
this._onConnect = this._onConnect.bind(this);
|
||||||
|
@ -1636,7 +1629,7 @@ class Scratch3BoostBlocks {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}, BLESendInterval);
|
}, BoostBLE.sendInterval);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1658,7 +1651,7 @@ class Scratch3BoostBlocks {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}, BLESendInterval);
|
}, BoostBLE.sendInterval);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1681,7 +1674,7 @@ class Scratch3BoostBlocks {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}, BLESendInterval);
|
}, BoostBLE.sendInterval);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1724,7 +1717,7 @@ class Scratch3BoostBlocks {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}, BLESendInterval);
|
}, BoostBLE.sendInterval);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1750,7 +1743,7 @@ class Scratch3BoostBlocks {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}, BLESendInterval);
|
}, BoostBLE.sendInterval);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue