com.yobotics.simulationconstructionset
Class YoVariable

java.lang.Object
  extended by com.yobotics.simulationconstructionset.YoVariable
All Implemented Interfaces:
Observable, java.io.Serializable
Direct Known Subclasses:
AlphaFilteredYoVariable, AlphaFusedYoVariable, BetaFilteredYoVariable, ButterworthFilteredYoVariable, ButterworthFusedYoVariable, FilteredVelocityYoVariable, GlitchFilteredBooleanYoVariable, HysteresisFilteredYoVariable, InfiniteImpulseResponseFilteredYoVariable, RateChangeLimitedYoVariable, RateLimitedYoVariable, TwoVariableTransitionFilter

public class YoVariable
extends java.lang.Object
implements java.io.Serializable, Observable

Title: Yobotics! Simulation Construction Set

Description: Package for Simulating Dynamic Robots and Mechanisms

YoVariables provide a simple, convienent mechanism for storing and manipulating robot data. While each essentially contains a double value YoVariables are designed for integration into the SCS GUI. Once registered, a variable will automatically become available to the GUI for graphing, modification and other data manipulation. Historical values of all registered YoVariables are stored in the DataBuffer which may be exported for later use.

Copyright: Copyright (c) Jerry Pratt

Company: Yobotics, Inc.

Author:
Jerry Pratt
See Also:
Serialized Form

Field Summary
static int MAX_LENGTH_SHORT_NAME
           
 double val
           
 
Constructor Summary
YoVariable(java.lang.String name, java.lang.Enum[] enumeratorValues, YoVariableRegistry registry)
          Creates a new variable of type ENUM based on the provided array of values and registered with the given YoVariableRegistry.
YoVariable(java.lang.String name, java.lang.String description, java.lang.Enum[] enumeratorValues, YoVariableRegistry registry)
          Creates a new YoVariable with the given name and type and adds it to the specified registry.
YoVariable(java.lang.String name, java.lang.String description, YoVariableRegistry registry)
          Creates a new YoVariable with the given name and adds it to the specified registry.
YoVariable(java.lang.String name, java.lang.String description, YoVariableRegistry registry, double minScaling, double maxScaling)
          Creates a new YoVariable with the given name and adds it to the specified registry.
YoVariable(java.lang.String name, java.lang.String description, YoVariableType type, YoVariableRegistry registry)
          Creates a new YoVariable with the given name and adds it to the specified registry.
YoVariable(java.lang.String name, java.lang.String description, YoVariableType type, YoVariableRegistry registry, double minScaling, double maxScaling)
          Creates a new YoVariable with the given name and type and adds it to the specified registry.
YoVariable(java.lang.String name, YoVariableRegistry registry)
          Creates a new YoVariable with the given name and adds it to the specified registry.
YoVariable(java.lang.String name, YoVariableType type, YoVariableRegistry registry)
          Creates a new YoVariable of the given type with the given name and adds it to the specified registry.
 
Method Summary
 void addObserver(Observer observer)
          Adds a new observer
 boolean fullNameEndsWith(java.lang.String name)
          fullNameEndsWith
 boolean getBooleanValue()
          Retrieve the boolean value of this YoVariable, if not of boolean type a warning will be printed.
 java.lang.String getDescription()
          Retrieve the description of this variable, "" if not specified.
 double getDoubleValue()
          Retrieve the double value of this variable, if not of double type a warning will be printed.
 java.lang.Enum getEnumValue()
          Retrieve the enum value of this YoVariable.
 java.lang.String getFullNameWithNameSpace()
           
 int getIntegerValue()
          Retrieve the integer representation of this variable.
 double getManualScalingMax()
          Retrieve the current maximum value for manual scaling.
 double getManualScalingMin()
          Retrieve the current minimum value for manual scaling.
 java.lang.String getName()
          Retrieves the name of this YoVariable.
 void getName(java.lang.StringBuffer buffer)
          Adds the name of this variable to the provided string buffer.
 void getNameAndValue(java.lang.StringBuffer stringBuffer)
          Adds the variables name & value to the beginning of the given string buffer
 java.lang.String getShortName()
          Retrieves a shortened version of this variables name.
 void getValue(java.lang.StringBuffer stringBuffer)
          Appends the value of this variable to the end of the given StringBuffer.
 YoVariableRegistry getYoVariableRegistry()
           
 YoVariableType getYoVariableType()
          Retrieve the type of this YoVariable.
 boolean hasSameFullName(YoVariable variable)
          hasSameFullName
 void notifyObservers(Event event)
          Notifies observers of an event (most likely a change to the val field).
 void removeAllObservers()
          Removes all observers
 void removeObserver(Observer observer)
          Removes an observer
 void set(boolean value)
          Sets the boolean value of this YoVariable.
 void set(double value)
          Set the value of this YoVariable.
 void set(java.lang.Enum value)
          Set the enum value of this variable.
 void set(int value)
          Set the value of this YoVariable.
 void setManualScalingMinMax(double minScaling, double maxScaling)
          Set the min and max scaling values for graphing purposes.
 java.lang.String toString()
          Retrieves a string representation of this variable.
 boolean valueEquals(boolean value)
          Check if the value contained by this variable is equal to the given double.
 boolean valueEquals(double value)
          Check if the value contained by this variable is equal to the given double.
 boolean valueEquals(java.lang.Enum value)
          Check if the value contained by this variable is equal to the given enum.
 boolean valueEquals(int value)
          Check if the value contained by this variable is equal to the given integer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

val

public double val

MAX_LENGTH_SHORT_NAME

public static final int MAX_LENGTH_SHORT_NAME
See Also:
Constant Field Values
Constructor Detail

YoVariable

public YoVariable(java.lang.String name,
                  YoVariableRegistry registry)
Creates a new YoVariable with the given name and adds it to the specified registry.

Parameters:
name - name to be used for all references of this variable by SCS
registry - YoVariableRegistry with which this variable is to be registerd
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  java.lang.String description,
                  YoVariableRegistry registry)
Creates a new YoVariable with the given name and adds it to the specified registry. This constructor allows the user to provide a simple description of the variable, which can come in handy when faced with thousands. The description is displayed in the VarPanel component of the GUI.

Parameters:
name - name to be used for all references of this variable by SCS
description - A short discription of this variable
registry - YoVariableRegistry with which this variable is to be registerd
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  java.lang.String description,
                  YoVariableRegistry registry,
                  double minScaling,
                  double maxScaling)
Creates a new YoVariable with the given name and adds it to the specified registry. This constructor allows the user to provide a simple description of the variable, which can come in handy when faced with thousands. The description is displayed in the VarPanel component of the GUI. This variant also allows the user to specify min and max values for manual scaling of graphs.

Parameters:
name - name to be used for all references of this variable by SCS
description - A short discription of this variable
registry - YoVariableRegistry with which this variable is to be registerd
minScaling - minimum value for scaling purposes
maxScaling - maximum value for scaling purpouses
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  YoVariableType type,
                  YoVariableRegistry registry)
Creates a new YoVariable of the given type with the given name and adds it to the specified registry.

Parameters:
name - name to be used for all references of this variable by SCS
type - YoVariableType of this variable, can be an int, double, boolean or enum see YoVariableType for more information
registry - YoVariableRegistry with which this variable is to be registerd
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  java.lang.String description,
                  YoVariableType type,
                  YoVariableRegistry registry)
Creates a new YoVariable with the given name and adds it to the specified registry. This constructor allows the user to provide a simple description of the variable, which can come in handy when faced with thousands. The description is displayed in the VarPanel component of the GUI.

Parameters:
name - name to be used for all references of this variable by SCS
description - A short discription of this variable
type - YoVariableType of this variable, can be an int, double, boolean or enum see YoVariableType for more information
registry - YoVariableRegistry with which this variable is to be registered
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  java.lang.String description,
                  YoVariableType type,
                  YoVariableRegistry registry,
                  double minScaling,
                  double maxScaling)
Creates a new YoVariable with the given name and type and adds it to the specified registry. This constructor allows the user to provide a simple description of the variable, which can come in handy when faced with thousands. The description is displayed in the VarPanel component of the GUI. This variant also allows the user to specify min and max values for manual scaling of graphs.

Parameters:
name - name to be used for all references of this variable by SCS
description - A short discription of this variable
type - YoVariableType of this variable, can be an int, double, boolean or enum see YoVariableType for more information
registry - YoVariableRegistry with which this variable is to be registered
minScaling - minimum value for scaling purposes
maxScaling - maximum value for scaling purpouses
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  java.lang.Enum[] enumeratorValues,
                  YoVariableRegistry registry)
Creates a new variable of type ENUM based on the provided array of values and registered with the given YoVariableRegistry.

Parameters:
name - name to be used for all references of this variable by SCS
enumeratorValues - Enum[] array of enumerator values to be stored by this YoVariable
registry - YoVariableRegistry with which this variable is to be registered.
See Also:
YoVariableRegistry

YoVariable

public YoVariable(java.lang.String name,
                  java.lang.String description,
                  java.lang.Enum[] enumeratorValues,
                  YoVariableRegistry registry)
Creates a new YoVariable with the given name and type and adds it to the specified registry. This constructor allows the user to provide a simple description of the variable, which can come in handy when faced with thousands. The description is displayed in the VarPanel component of the GUI. This variant also allows the user to specify min and max values for manual scaling of graphs.

Parameters:
name - name to be used for all references of this variable by SCS
description - a short description
enumeratorValues - Array of enumerator values to be contained by this YoVariable
registry - YoVariableRegistry
Method Detail

getYoVariableRegistry

public YoVariableRegistry getYoVariableRegistry()

getName

public java.lang.String getName()
Retrieves the name of this YoVariable.

Returns:
the full name

getShortName

public java.lang.String getShortName()
Retrieves a shortened version of this variables name. The shortened name is created from the full name using the following method:
  1. Take the first 8 characters
  2. Insert "..."
  3. Add the last 9 characters

Returns:
the name of this variable reduced to 20 characters

getDescription

public java.lang.String getDescription()
Retrieve the description of this variable, "" if not specified.

Returns:
the description of this variable

getName

public void getName(java.lang.StringBuffer buffer)
Adds the name of this variable to the provided string buffer. This is done to avoid object creation.

Parameters:
buffer - StringBuffer to which the name will be added at the beginning

getYoVariableType

public YoVariableType getYoVariableType()
Retrieve the type of this YoVariable. There are 4 possible types: int, double, enum, and boolean. By default the type is set to double.

Returns:
YoVariableType representing the type of this variable

setManualScalingMinMax

public void setManualScalingMinMax(double minScaling,
                                   double maxScaling)
Set the min and max scaling values for graphing purposes. By default graphs are created using manual scaling based on these values where min = 0.0 and max = 1.0.

Parameters:
minScaling - double representing the min scale value
maxScaling - double representing the max scale value

getManualScalingMin

public double getManualScalingMin()
Retrieve the current minimum value for manual scaling.

Returns:
double min value

getManualScalingMax

public double getManualScalingMax()
Retrieve the current maximum value for manual scaling.

Returns:
double max value

toString

public java.lang.String toString()
Retrieves a string representation of this variable. Currently this is only the variable name.

Overrides:
toString in class java.lang.Object
Returns:
String representation

valueEquals

public boolean valueEquals(int value)
Check if the value contained by this variable is equal to the given integer. If not of integer type a warning will be printed to the console.

Parameters:
value - int to be compared
Returns:
boolean are they equal?

valueEquals

public boolean valueEquals(double value)
Check if the value contained by this variable is equal to the given double. If not of double type a warning will be printed to the console.

Parameters:
value - double to be compared
Returns:
boolean are they equal?

valueEquals

public boolean valueEquals(boolean value)
Check if the value contained by this variable is equal to the given double. If not of double type a warning will be printed to the console.

Parameters:
value - boolean to be compared to
Returns:
are they equal?

valueEquals

public boolean valueEquals(java.lang.Enum value)
Check if the value contained by this variable is equal to the given enum. If this YoVariable is not of enum type a warning will be printed to the console.

Parameters:
value - Enum to be compared
Returns:
boolean

getEnumValue

public java.lang.Enum getEnumValue()
Retrieve the enum value of this YoVariable. If this variable is not of enum type a warning will be printed.

Returns:
Enum value of this

getDoubleValue

public double getDoubleValue()
Retrieve the double value of this variable, if not of double type a warning will be printed.

Returns:
double value of this

getBooleanValue

public boolean getBooleanValue()
Retrieve the boolean value of this YoVariable, if not of boolean type a warning will be printed.

Returns:
boolean value of this

getIntegerValue

public int getIntegerValue()
Retrieve the integer representation of this variable. If not of integer type a warning will be printed.

Returns:
int value of this

getNameAndValue

public void getNameAndValue(java.lang.StringBuffer stringBuffer)
Adds the variables name & value to the beginning of the given string buffer

Parameters:
stringBuffer - StringBuffer to which the data will be added

set

public void set(int value)
Set the value of this YoVariable. All four types are represented via the same interal double. If of integer type this value is cast as an int whenever accessed. It represents the ordinal if of enum type. Boolean values are triggered around the 0.5 threshold with < 0.5 being false and greater or equal being true.

Parameters:
value - double value to store

set

public void set(double value)
Set the value of this YoVariable. All four types are represented via the same interal double. If of integer type this value is cast as an int whenever accessed. It represents the ordinal if of enum type. Boolean values are triggered around the 0.5 threshold with < 0.5 being false and greater or equal being true.

Parameters:
value - double value to store

set

public void set(java.lang.Enum value)
Set the enum value of this variable. If not of enum type a warning will be printed.

Parameters:
value - Enum to store in this YoVariable

set

public void set(boolean value)
Sets the boolean value of this YoVariable. If not of boolean type a warning will be printed.

Parameters:
value - boolean

getValue

public void getValue(java.lang.StringBuffer stringBuffer)
Appends the value of this variable to the end of the given StringBuffer. This representation is based on variable type.

Parameters:
stringBuffer - StringBuffer to which the value will be appended

fullNameEndsWith

public boolean fullNameEndsWith(java.lang.String name)
fullNameEndsWith

Parameters:
name - String
Returns:
boolean

hasSameFullName

public boolean hasSameFullName(YoVariable variable)
hasSameFullName

Parameters:
variable - YoVariable
Returns:
boolean

getFullNameWithNameSpace

public java.lang.String getFullNameWithNameSpace()

addObserver

public void addObserver(Observer observer)
Description copied from interface: Observable
Adds a new observer

Specified by:
addObserver in interface Observable
Parameters:
observer - the new observer to be addedd

removeAllObservers

public void removeAllObservers()
Description copied from interface: Observable
Removes all observers

Specified by:
removeAllObservers in interface Observable

removeObserver

public void removeObserver(Observer observer)
Description copied from interface: Observable
Removes an observer

Specified by:
removeObserver in interface Observable
Parameters:
observer - the new observer to be removed

notifyObservers

public void notifyObservers(Event event)
Notifies observers of an event (most likely a change to the val field). FIXME: This should really be a private method, called from within this class at appropriate places. However, since the val field is currently public, there's no way to guarantee that this method is called when appropriate. Therefore, the resposibility to notify observers currently lies with the object that changes the YoVariable.

Parameters:
event - the event to communicate to the observers