Merge pull request #121 from Microsoft/motorphysics

Motor work
This commit is contained in:
Sam El-Husseini
2017-12-19 17:07:15 -08:00
committed by GitHub
7 changed files with 39 additions and 71 deletions

View File

@ -374,17 +374,18 @@ namespace pxsim.visuals {
now = Date.now();
delta = now - then;
if (delta > interval) {
then = now - (delta % interval);
that.updateStateStep();
then = now;
that.updateStateStep(delta);
}
}
loop();
}
private updateStateStep() {
private updateStateStep(elapsed: number) {
const selected = this.layoutView.getSelected();
const inputNodes = ev3board().getInputNodes();
inputNodes.forEach((node, index) => {
node.updateState(elapsed);
if (!node.didChange()) return;
const view = this.getDisplayViewForNode(node.id, index);
if (view) {
@ -400,6 +401,7 @@ namespace pxsim.visuals {
const outputNodes = ev3board().getMotors();
outputNodes.forEach((node, index) => {
node.updateState(elapsed);
if (!node.didChange()) return;
const view = this.getDisplayViewForNode(node.id, index);
if (view) {

View File

@ -5,8 +5,6 @@ namespace pxsim.visuals {
private static ROTATING_ECLIPSE_ID = "1eb2ae58-2419-47d4-86bf-4f26a7f0cf61";
private lastMotorAnimationId: any;
constructor(port: number) {
super(LARGE_MOTOR_SVG, "large-motor", NodeType.LargeMotor, port);
}
@ -15,7 +13,6 @@ namespace pxsim.visuals {
const motorState = ev3board().getMotors()[this.port];
if (!motorState) return;
const speed = motorState.getSpeed();
if (this.lastMotorAnimationId) cancelAnimationFrame(this.lastMotorAnimationId);
if (!speed) return;
this.setMotorAngle(motorState.getAngle());

View File

@ -11,8 +11,6 @@ namespace pxsim.visuals {
private hasPreviousAngle: boolean;
private previousAngle: number;
private lastMotorAnimationId: any;
constructor(port: number) {
super(MEDIUM_MOTOR_SVG, "medium-motor", NodeType.MediumMotor, port);
}
@ -25,7 +23,6 @@ namespace pxsim.visuals {
const motorState = ev3board().getMotors()[this.port];
if (!motorState) return;
const speed = motorState.getSpeed();
if (this.lastMotorAnimationId) cancelAnimationFrame(this.lastMotorAnimationId);
if (!speed) return;
this.setMotorAngle(motorState.getAngle());