better handling end of integration step
This commit is contained in:
parent
f9a0729b63
commit
21025b5f83
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user