From bfcbc6c0b406139e8e8af2eee5315074e4b68d2f Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Fri, 8 Jun 2018 11:32:12 -0600 Subject: [PATCH] instrument model Properties, #38 Signed-off-by: Chris Malley --- js/common/model/RoboticArm.js | 1 + js/common/model/Spring.js | 73 +++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/js/common/model/RoboticArm.js b/js/common/model/RoboticArm.js index f85866fa..0e5a1679 100644 --- a/js/common/model/RoboticArm.js +++ b/js/common/model/RoboticArm.js @@ -33,6 +33,7 @@ define( function( require ) { // @public left (movable) end of the arm, constrained to extend from right to left this.leftProperty = new NumberProperty( options.left, { isValidValue: function( value ) { return value < self.right; }, + units: 'meters', tandem: options.tandem.createTandem( 'leftProperty' ) } ); } diff --git a/js/common/model/Spring.js b/js/common/model/Spring.js index 4543dc9e..07a8cc5a 100644 --- a/js/common/model/Spring.js +++ b/js/common/model/Spring.js @@ -35,6 +35,10 @@ define( function( require ) { var inherit = require( 'PHET_CORE/inherit' ); var NumberProperty = require( 'AXON/NumberProperty' ); var RangeWithValue = require( 'DOT/RangeWithValue' ); + + // phet-io modules + var DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); + var NumberIO = require( 'ifphetio!PHET_IO/types/NumberIO' ); var Tandem = require( 'TANDEM/Tandem' ); /** @@ -107,70 +111,107 @@ define( function( require ) { //------------------------------------------------ // Properties - // @public F, applied force, units = N - this.appliedForceProperty = new NumberProperty( this.appliedForceRange.defaultValue ); + // @public applied force (F) + this.appliedForceProperty = new NumberProperty( this.appliedForceRange.defaultValue, { + units: 'newtons', + tandem: options.tandem.createTandem( 'appliedForceProperty' ) + } ); - // @public k, spring constant, N/m - this.springConstantProperty = new NumberProperty( this.springConstantRange.defaultValue ); + // @public spring constant (k) + this.springConstantProperty = new NumberProperty( this.springConstantRange.defaultValue, { + units: 'newtons/meters', + tandem: options.tandem.createTandem( 'springConstantProperty' ) + } ); - // @public x, displacement from equilibrium position, units = m - this.displacementProperty = new NumberProperty( this.displacementRange.defaultValue ); + // @public displacement from equilibrium position (x) + this.displacementProperty = new NumberProperty( this.displacementRange.defaultValue, { + units: 'meters', + tandem: options.tandem.createTandem( 'displacementProperty' ) + } ); - // @public location of the left end of the spring, units = m - this.leftProperty = new NumberProperty( options.left ); + // @public location of the left end of the spring + this.leftProperty = new NumberProperty( options.left, { + units: 'meters', + tandem: options.tandem.createTandem( 'leftProperty' ) + } ); //------------------------------------------------ // Derived properties - // @public -F, spring force opposes the applied force, units = N + // @public spring force opposes the applied force (-F) this.springForceProperty = new DerivedProperty( [ this.appliedForceProperty ], function( appliedForce ) { return -appliedForce; + }, { + units: 'newtons', + phetioType: DerivedPropertyIO( NumberIO ), + tandem: options.tandem.createTandem( 'springForceProperty' ) } ); - // @public equilibrium x location, units = m + // @public equilibrium x location this.equilibriumXProperty = new DerivedProperty( [ this.leftProperty ], function( left ) { return left + self.equilibriumLength; + }, { + units: 'meters', + phetioType: DerivedPropertyIO( NumberIO ), + tandem: options.tandem.createTandem( 'equilibriumXProperty' ) } ); - // @public x location of the right end of the spring, units = m + // @public x location of the right end of the spring this.rightProperty = new DerivedProperty( [ this.equilibriumXProperty, this.displacementProperty ], function( equilibriumX, displacement ) { var left = self.leftProperty.get(); var right = equilibriumX + displacement; assert && assert( right - left > 0, 'right must be > left, right=' + right + ', left=' + left ); return right; + }, { + units: 'meters', + phetioType: DerivedPropertyIO( NumberIO ), + tandem: options.tandem.createTandem( 'rightProperty' ) } ); - // @public Range of the right end of the spring, units = m + // @public Range of the right end of the spring // Derivation differs depending on whether changing spring constant modifies applied force or displacement. this.rightRangeProperty = null; + var rightRangePropertyOptions = { + units: 'meters', + phetioType: DerivedPropertyIO( NumberIO ), + tandem: options.tandem.createTandem( 'rightRangeProperty' ) + }; if ( options.appliedForceRange ) { this.rightRangeProperty = new DerivedProperty( [ this.springConstantProperty, this.equilibriumXProperty ], function( springConstant, equilibriumX ) { var minDisplacement = self.appliedForceRange.min / springConstant; var maxDisplacement = self.appliedForceRange.max / springConstant; return new RangeWithValue( equilibriumX + minDisplacement, equilibriumX + maxDisplacement ); - } ); + }, rightRangePropertyOptions ); } else { this.rightRangeProperty = new DerivedProperty( [ this.equilibriumXProperty ], function( equilibriumX ) { return new RangeWithValue( equilibriumX + self.displacementRange.min, equilibriumX + self.displacementRange.max ); - } ); + }, rightRangePropertyOptions ); } - // @public length of the spring, units = m + // @public length of the spring this.lengthProperty = new DerivedProperty( [ this.leftProperty, this.rightProperty ], function( left, right ) { return Math.abs( right - left ); + }, { + units: 'meters', + phetioType: DerivedPropertyIO( NumberIO ), + tandem: options.tandem.createTandem( 'lengthProperty' ) } ); - // @public potential energy, E = ( k1 * x1 * x1 ) / 2, units = J + // @public potential energy, E = ( k1 * x1 * x1 ) / 2 this.energyProperty = new DerivedProperty( [ this.springConstantProperty, this.displacementProperty ], function( springConstant, displacement ) { return ( springConstant * displacement * displacement ) / 2; + }, { + units: 'joules', + phetioType: DerivedPropertyIO( NumberIO ), + tandem: options.tandem.createTandem( 'energyProperty' ) } ); //------------------------------------------------