diff --git a/sim/state/motor.ts b/sim/state/motor.ts index ded9a837..e2a5c9f0 100644 --- a/sim/state/motor.ts +++ b/sim/state/motor.ts @@ -19,9 +19,15 @@ namespace pxsim { console.log("motor before read"); for (let port = 0; port < DAL.NUM_OUTPUTS; ++port) { const output = outputs[port]; + const speed = output ? Math.round(outputs[port].getSpeed()) : 0; + const angle = output ? Math.round(outputs[port].getAngle()) : 0; + const tsi = MotorDataOff.TachoSensor + port * MotorDataOff.Size; data[MotorDataOff.TachoCounts + port * MotorDataOff.Size] = 0; // Tacho count - data[MotorDataOff.Speed + port * MotorDataOff.Size] = output ? outputs[port].getSpeed() : 0; // Speed - data[MotorDataOff.TachoSensor + port * MotorDataOff.Size] = output ? outputs[port].getAngle() : 0; // Count + data[MotorDataOff.Speed + port * MotorDataOff.Size] = speed; // Speed + data[tsi] = angle & 0xff; // Count + data[tsi + 1] = (angle >> 8) & 0xff; // Count + data[tsi + 2] = (angle >> 16) & 0xff; // Count + data[tsi + 3] = (angle >> 24) & 0xff; // Count } }, read: buf => { diff --git a/sim/state/output.ts b/sim/state/output.ts index e85ca5a4..a3b93f8e 100644 --- a/sim/state/output.ts +++ b/sim/state/output.ts @@ -37,7 +37,7 @@ namespace pxsim { case DAL.opOutputStepSpeed: { // step speed const port = buf.data[1]; - const speed = buf.data[2]; + const speed = buf.data[2] << 24 >> 24; // signed byte // note that b[3] is padding const step1 = buf.data[4]; const step2 = buf.data[5]; // angle @@ -59,7 +59,7 @@ namespace pxsim { case DAL.opOutputSpeed: { // setSpeed const port = buf.data[1]; - const speed = buf.data[2]; + const speed = buf.data[2] << 24 >> 24; // signed byte const motors = ev3board().getMotor(port); motors.forEach(motor => motor.setSpeed(speed)); return 2; diff --git a/sim/visuals/board.ts b/sim/visuals/board.ts index 152bf5ef..a5a1d040 100644 --- a/sim/visuals/board.ts +++ b/sim/visuals/board.ts @@ -374,7 +374,7 @@ namespace pxsim.visuals { now = Date.now(); delta = now - then; if (delta > interval) { - then = now - (delta % interval); + then = now; that.updateStateStep(delta); } }