store synched motor info always (#187)

This commit is contained in:
Peli de Halleux 2018-01-05 08:40:49 -08:00 committed by GitHub
parent dc6ce0efc7
commit aa06fd344a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -15,7 +15,7 @@ namespace pxsim {
private speedCmdValues: number[]; private speedCmdValues: number[];
private speedCmdTacho: number; private speedCmdTacho: number;
private speedCmdTime: number; private speedCmdTime: number;
private _synchedMotor: MotorNode; // non-null if master motor private _synchedMotor: MotorNode; // non-null if synchronized
constructor(port: number, large: boolean) { constructor(port: number, large: boolean) {
super(port); super(port);
@ -50,6 +50,7 @@ namespace pxsim {
clearSpeedCmd() { clearSpeedCmd() {
delete this.speedCmd; delete this.speedCmd;
delete this.speedCmdValues;
delete this._synchedMotor; delete this._synchedMotor;
} }
@ -135,10 +136,10 @@ namespace pxsim {
} }
case DAL.opOutputStepSync: case DAL.opOutputStepSync:
case DAL.opOutputTimeSync: { case DAL.opOutputTimeSync: {
if (!this._synchedMotor) // handled in other motor code const otherMotor = this._synchedMotor;
if (otherMotor.port < this.port) // handled in other motor code
break; break;
const otherMotor = this._synchedMotor;
const speed = this.speedCmdValues[0]; const speed = this.speedCmdValues[0];
const turnRatio = this.speedCmdValues[1]; const turnRatio = this.speedCmdValues[1];
const stepsOrTime = this.speedCmdValues[2]; const stepsOrTime = this.speedCmdValues[2];

View File

@ -70,7 +70,7 @@ namespace pxsim {
for (const motor of motors) { for (const motor of motors) {
const otherMotor = motors.filter(m => m.port != motor.port)[0]; const otherMotor = motors.filter(m => m.port != motor.port)[0];
motor.setSyncCmd( motor.setSyncCmd(
motor.port < otherMotor.port ? otherMotor : undefined, otherMotor,
cmd, [speed, turnRatio, stepsOrTime, brake]); cmd, [speed, turnRatio, stepsOrTime, brake]);
} }
return 2; return 2;