Compare commits

...

2 Commits

Author SHA1 Message Date
5c61677ab9 0.3.4 2018-06-20 22:08:04 -07:00
21025b5f83 better handling end of integration step 2018-06-20 22:03:48 -07:00
3 changed files with 14 additions and 3 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.3.3",
"version": "0.3.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.3.3",
"version": "0.3.4",
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
"private": true,
"keywords": [

View File

@ -150,7 +150,8 @@ namespace pxsim {
const step2 = this.speedCmdValues[2];
const step3 = this.speedCmdValues[3];
const brake = this.speedCmdValues[4];
const dstep = (this.speedCmd == DAL.opOutputTimePower || this.speedCmd == DAL.opOutputTimeSpeed)
const isTimeCommand = this.speedCmd == DAL.opOutputTimePower || this.speedCmd == DAL.opOutputTimeSpeed;
const dstep = isTimeCommand
? pxsim.U.now() - this.speedCmdTime
: this.tacho - this.speedCmdTacho;
if (dstep < step1) // rampup
@ -161,6 +162,16 @@ namespace pxsim {
this.speed = speed * (step1 + step2 + step3 - dstep) / (step1 + step2 + step3);
else {
if (brake) this.speed = 0;
if (!isTimeCommand) {
// we need to patch the actual position of the motor when
// finishing the move as our integration step introduce errors
const deltaAngle = -Math.sign(speed) * (dstep - (step1 + step2 + step3));
if (deltaAngle) {
this.angle += deltaAngle;
this.tacho -= Math.abs(deltaAngle);
this.setChangedState();
}
}
this.clearSpeedCmd();
}
break;