mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Merge pull request #1381 from paulkaplan/fix-ev3-coast
Do not send coast if another motor command has been sent
This commit is contained in:
commit
f3451cea91
1 changed files with 22 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
const ArgumentType = require('../../extension-support/argument-type');
|
const ArgumentType = require('../../extension-support/argument-type');
|
||||||
const BlockType = require('../../extension-support/block-type');
|
const BlockType = require('../../extension-support/block-type');
|
||||||
const Cast = require('../../util/cast');
|
const Cast = require('../../util/cast');
|
||||||
|
const uid = require('../../util/uid');
|
||||||
// const log = require('../../util/log');
|
// const log = require('../../util/log');
|
||||||
const Base64Util = require('../../util/base64-util');
|
const Base64Util = require('../../util/base64-util');
|
||||||
const BTSession = require('../../io/btSession');
|
const BTSession = require('../../io/btSession');
|
||||||
|
@ -135,7 +136,8 @@ class EV3 {
|
||||||
this._motors = {
|
this._motors = {
|
||||||
speeds: [50, 50, 50, 50],
|
speeds: [50, 50, 50, 50],
|
||||||
positions: [0, 0, 0, 0],
|
positions: [0, 0, 0, 0],
|
||||||
busy: [0, 0, 0, 0]
|
busy: [0, 0, 0, 0],
|
||||||
|
commandId: [null, null, null, null]
|
||||||
};
|
};
|
||||||
this._pollingIntervalID = null;
|
this._pollingIntervalID = null;
|
||||||
this._pollingCounter = 0;
|
this._pollingCounter = 0;
|
||||||
|
@ -186,7 +188,8 @@ class EV3 {
|
||||||
this._motors = {
|
this._motors = {
|
||||||
speeds: [50, 50, 50, 50],
|
speeds: [50, 50, 50, 50],
|
||||||
positions: [0, 0, 0, 0],
|
positions: [0, 0, 0, 0],
|
||||||
busy: [0, 0, 0, 0]
|
busy: [0, 0, 0, 0],
|
||||||
|
commandId: [null, null, null, null]
|
||||||
};
|
};
|
||||||
this._pollingIntervalID = null;
|
this._pollingIntervalID = null;
|
||||||
}
|
}
|
||||||
|
@ -296,10 +299,7 @@ class EV3 {
|
||||||
// Set motor to busy
|
// Set motor to busy
|
||||||
// this._motors.busy[port] = 1;
|
// this._motors.busy[port] = 1;
|
||||||
|
|
||||||
// Send coast message
|
this.coastAfter(port, time);
|
||||||
setTimeout(() => {
|
|
||||||
this.motorCoast(port);
|
|
||||||
}, time);
|
|
||||||
|
|
||||||
// Yield for turn time + brake time
|
// Yield for turn time + brake time
|
||||||
const coastTime = 100; // TODO: calculate coasting or set flag
|
const coastTime = 100; // TODO: calculate coasting or set flag
|
||||||
|
@ -331,10 +331,7 @@ class EV3 {
|
||||||
// Set motor to busy
|
// Set motor to busy
|
||||||
// this._motors.busy[port] = 1;
|
// this._motors.busy[port] = 1;
|
||||||
|
|
||||||
// Send coast message
|
this.coastAfter(port, time);
|
||||||
setTimeout(() => {
|
|
||||||
this.motorCoast(port);
|
|
||||||
}, time);
|
|
||||||
|
|
||||||
// Yield for time
|
// Yield for time
|
||||||
const coastTime = 100; // TODO: calculate coasting or set flag
|
const coastTime = 100; // TODO: calculate coasting or set flag
|
||||||
|
@ -345,6 +342,21 @@ class EV3 {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coastAfter (port, time) {
|
||||||
|
// Set the motor command id to check before starting coast
|
||||||
|
const commandId = uid();
|
||||||
|
this._motors.commandId[port] = commandId;
|
||||||
|
|
||||||
|
// Send coast message
|
||||||
|
setTimeout(() => {
|
||||||
|
// Do not send coast if another motor command changed the command id.
|
||||||
|
if (this._motors.commandId[port] === commandId) {
|
||||||
|
this.motorCoast(port);
|
||||||
|
this._motors.commandId[port] = null;
|
||||||
|
}
|
||||||
|
}, time);
|
||||||
|
}
|
||||||
|
|
||||||
motorCoast (port) {
|
motorCoast (port) {
|
||||||
|
|
||||||
const cmd = [];
|
const cmd = [];
|
||||||
|
|
Loading…
Reference in a new issue