Support for smooth acceleration/deceleration in run (#900)

* removed logging

* removing more logging

* always use step for single/multiple motors

* refactored schedule

* account for accel ramp up and down

* added default acc/decel

* rounding speed/angle

* remove hack

* use acceleration time in run too

* handle missing case

* adding notes on motors

* adding sample

* fixed ramp simulation

* clear defaults

* some docs, more later

* adding basic examples

* remove debug msg

* clean json

* added move schedule

* docs

* basic docs
This commit is contained in:
Peli de Halleux
2019-09-02 20:57:23 -07:00
committed by GitHub
parent 7e9cc791ec
commit 56bbcde299
7 changed files with 281 additions and 109 deletions

View File

@ -1,4 +1,5 @@
namespace pxsim {
const MIN_RAMP_SPEED = 3;
export class MotorNode extends BaseNode {
isOutput = true;
@ -30,11 +31,11 @@ namespace pxsim {
}
getSpeed() {
return this.speed * (!this._synchedMotor && this.polarity == 0 ? -1 : 1);
return Math.round(this.speed * (!this._synchedMotor && this.polarity == 0 ? -1 : 1));
}
getAngle() {
return this.angle;
return Math.round(this.angle);
}
// returns the slave motor if any
@ -64,7 +65,7 @@ namespace pxsim {
delete this.speedCmdValues;
delete this._synchedMotor;
this.setChangedState();
}
}
clearSyncCmd() {
if (this._synchedMotor)
@ -160,13 +161,19 @@ namespace pxsim {
const dstep = isTimeCommand
? pxsim.U.now() - this.speedCmdTime
: this.tacho - this.speedCmdTacho;
if (dstep < step1) // rampup
if (step1 && dstep < step1) { // rampup
this.speed = speed * dstep / step1;
// ensure non-zero speed
this.speed = Math.max(MIN_RAMP_SPEED, Math.ceil(Math.abs(this.speed))) * Math.sign(speed);
}
else if (dstep < step1 + step2) // run
this.speed = speed;
else if (dstep < step1 + step2 + step3)
this.speed = speed * (step1 + step2 + step3 - dstep) / (step1 + step2 + step3);
else {
else if (step2 && dstep < step1 + step2 + step3) {
this.speed = speed * (step1 + step2 + step3 - dstep)
/ (step1 + step2 + step3) + 5;
// ensure non-zero speed
this.speed = Math.max(MIN_RAMP_SPEED, Math.ceil(Math.abs(this.speed))) * Math.sign(speed);
} else {
if (brake) this.speed = 0;
if (!isTimeCommand) {
// we need to patch the actual position of the motor when
@ -227,11 +234,10 @@ namespace pxsim {
this.angle = this.manualReferenceAngle + this.manualAngle;
this.setChangedState();
}
this.speed = Math.round(this.speed); // integer only
// don't round speed
// compute delta angle
const rotations = this.getSpeed() / 100 * this.rotationsPerMilliSecond * elapsed;
const deltaAngle = Math.round(rotations * 360);
const rotations = this.speed / 100 * this.rotationsPerMilliSecond * elapsed;
const deltaAngle = rotations * 360;
if (deltaAngle) {
this.angle += deltaAngle;
this.tacho += Math.abs(deltaAngle);