Skip to content

Commit

Permalink
Cleanup in Voltmeter, see #86
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 6, 2017
1 parent d79e212 commit c6c9959
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions js/faradays-law/model/Voltmeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define( function( require ) {
this.needleAngularAcceleration = 0;

// @public {NumberProperty} Needle angle in radians. This drives both the needle location and the light bulb brightness.
this.thetaProperty = new NumberProperty( 0 );
this.needleAngleProperty = new NumberProperty( 0 );

// @private - input voltage to meter
this.signalProperty = new NumberProperty( 0, {
Expand All @@ -59,18 +59,18 @@ define( function( require ) {
// empirically determined to make the needle move the correct amount and direction.
this.signalProperty.set( -0.2 * (this.model.bottomCoil.emfProperty.get() + this.model.topCoil.emfProperty.get()) );

this.needleAngularAcceleration = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.thetaProperty.get()) - NEEDLE_FRICTION * this.needleAngularVelocity; //angular acceleration of needle
this.thetaProperty.set( this.thetaProperty.get() + this.needleAngularVelocity * dt + 0.5 * this.needleAngularAcceleration * dt * dt ); //angle of needle
this.needleAngularAcceleration = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.needleAngleProperty.get()) - NEEDLE_FRICTION * this.needleAngularVelocity; //angular acceleration of needle
this.needleAngleProperty.set( this.needleAngleProperty.get() + this.needleAngularVelocity * dt + 0.5 * this.needleAngularAcceleration * dt * dt ); //angle of needle
var omega = this.needleAngularVelocity + this.needleAngularAcceleration * dt;
var alpha = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.thetaProperty.get()) - NEEDLE_FRICTION * omega;
var alpha = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.needleAngleProperty.get()) - NEEDLE_FRICTION * omega;
this.needleAngularVelocity = this.needleAngularVelocity + 0.5 * dt * (this.needleAngularAcceleration + alpha);

// Clamp the needle angle when its position, velocity, and acceleration go below a threshold so that it doesn't
// oscillate forever.
if ( Math.abs( this.needleAngularAcceleration ) !== 0 && Math.abs( this.needleAngularAcceleration ) < ACTIVITY_THRESHOLD &&
Math.abs( this.needleAngularVelocity ) !== 0 && Math.abs( this.needleAngularVelocity ) < ACTIVITY_THRESHOLD &&
Math.abs( this.thetaProperty.get() ) !== 0 && Math.abs( this.thetaProperty.get() ) < ACTIVITY_THRESHOLD ) {
this.thetaProperty.set( 0 );
if ( this.needleAngularAcceleration !== 0 && Math.abs( this.needleAngularAcceleration ) < ACTIVITY_THRESHOLD &&
this.needleAngularVelocity !== 0 && Math.abs( this.needleAngularVelocity ) < ACTIVITY_THRESHOLD &&
this.needleAngleProperty.get() !== 0 && Math.abs( this.needleAngleProperty.get() ) < ACTIVITY_THRESHOLD ) {
this.needleAngleProperty.set( 0 );
this.needleAngularVelocity = 0;
this.needleAngularAcceleration = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions js/faradays-law/view/FaradaysLawScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ define( function( require ) {
this.aligner = new Aligner( model, bottomCoilNode.endRelativePositions, topCoilNode.endRelativePositions );

// voltmeter and bulb created
var voltmeterNode = new VoltmeterNode( model.voltmeter.thetaProperty, tandem.createTandem( 'voltmeterNode' ) );
var bulbNode = new BulbNode( model.voltmeter.thetaProperty, {
var voltmeterNode = new VoltmeterNode( model.voltmeter.needleAngleProperty, tandem.createTandem( 'voltmeterNode' ) );
var bulbNode = new BulbNode( model.voltmeter.needleAngleProperty, {
centerX: this.aligner.bulbPosition.x,
centerY: this.aligner.bulbPosition.y
} );
Expand Down

0 comments on commit c6c9959

Please sign in to comment.