nslj.src.lang
Class NslModule

java.lang.Object
  |
  +--EDU.gatech.cc.is.abstractrobot.ControlSystemS
        |
        +--EDU.gatech.cc.is.abstractrobot.ControlSystemMFN150
              |
              +--nslj.src.lang.NslBase
                    |
                    +--nslj.src.lang.NslHierarchy
                          |
                          +--nslj.src.lang.NslModule
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
NslInModule, NslModel, NslMotorModule, NslOutModule

public class NslModule
extends NslHierarchy
implements java.lang.Runnable


Field Summary
protected  double _approximationDelta
           
protected  boolean _bufferingChanged
           
protected  NslDiff _diff_method
           
protected  boolean _doubleBuffering
           
protected  java.util.Vector _inports
           
protected  java.util.Vector _moduleChildren
           
protected  java.util.Vector _outports
           
protected  java.util.Vector _protocols
           
protected  double _runDelta
           
protected  boolean _runDeltaChanged
           
protected  double _timeConstantTM
           
protected  double _trainDelta
           
protected  boolean _trainDeltaChanged
           
 int child_c
           
 int ID
           
 java.lang.String ID_str
           
 java.lang.String order_str
           
 boolean postorder
           
 
Fields inherited from class nslj.src.lang.NslHierarchy
nslClassInstances, nslDataVars, system
 
Fields inherited from class nslj.src.lang.NslBase
_accessChar, _name, _parent
 
Fields inherited from class EDU.gatech.cc.is.abstractrobot.ControlSystemMFN150
abstract_robot
 
Fields inherited from class EDU.gatech.cc.is.abstractrobot.ControlSystemS
CSSTAT_DONE, CSSTAT_ERROR, CSSTAT_OK, seed
 
Constructor Summary
NslModule()
          Bare Constructor.
NslModule(java.lang.String label)
          Default constructor.
NslModule(java.lang.String label, NslModule parent)
          Default constructor.
NslModule(java.lang.String label, NslModule parent, java.lang.String options)
           
 
Method Summary
 boolean connect(NslModule child1, java.lang.String name1, NslModule child2, java.lang.String name2)
          Connect two child modules and add the nslConnection to the scheduler
The nslConnection is done in two phases.
 void endModule()
           
 void endrun()
           
 void endRun()
           
 void endRunEpoch()
           
 void endsys()
           
 void endSys()
           
 void endTrain()
           
 void endTrainEpoch()
           
protected  void finalize()
           
 void initModule()
           
 void initrun()
          Initialization step of this module.
 void initRun()
           
 void initRunEpoch()
           
 void initsys()
           
 void initSys()
           
 void initTrain()
           
 void initTrainEpoch()
           
 void makeConn()
          Make the nslConnection between child modules.
 void makeinst(java.lang.String name, NslModule p)
          Instantiation the internal variable of this object.
 void makeInst(java.lang.String name, NslModule p)
           
 void nslAddExistingInport(NslInport inport)
          Add an inport to the current inport list
 void nslAddExistingOutport(NslOutport outport)
          Add an Outport to the current outport list
 NslNumeric nslAddInport(NslNumeric n)
          Create an inport which makes reference to a Numeric object
 NslNumeric nslAddInport(java.lang.String name, NslNumeric n)
          Create an inport which makes reference to an Object
 void nslAddModelPlots(NslFrame df)
           
 void nslAddModelPlots(NslFrame df, java.lang.String s)
           
 NslNumeric nslAddOutport(NslNumeric n)
          Create an outport which makes reference to a NslNumeric
 NslNumeric nslAddOutport(java.lang.String name, NslNumeric n)
          Create an outport which makes reference to an Object
 void nslAddProtocolRecursiveDown(java.lang.String name)
           
 void nslAddProtocolRecursiveUp(java.lang.String name)
           
 void nslAddToModuleChildren(NslModule child)
          Add child module into this module and into the scheduler
 void nslConnChildren()
          Call child modules to nslConnect their own internal modules recursively.
 boolean nslConnect(nslj.src.lang.NslConnection link)
          Connect two modules using defined link
 boolean nslConnect(NslModule child1, java.lang.String name1, NslModule child2, java.lang.String name2)
           
 boolean nslConnect(NslNumeric num1, NslNumeric num2)
           
 void nslConnMissingLinks()
          Call child modules to nslConnect their missing links, if possible It checks the _missing_links vector for the nslConnection required.
 void nslDeclareProtocol(java.lang.String name)
           
 void nslDeclareProtocol(java.lang.String name, java.lang.String label)
           
 NslNumeric nslDummy(NslNumeric n)
           
 double nslGetApproximationDelta()
          get integration time step / numerical method time step tm
 NslDiff nslGetApproximationMethod()
           
 boolean nslGetBuffering()
           
 double nslGetDelta()
          get run or train step size depending on simulation mode, delta t
 boolean nslGetEnableFlag()
           
 java.lang.String nslGetId_str()
           
 int nslGetId()
           
 java.util.Vector nslGetInportsVector()
           
 java.util.Vector nslGetModuleChildrenVector()
          define the scheduler to use
 NslModule nslGetModuleRef(java.lang.String name)
          Get a child module with name
 NslModule nslGetModuleRefByName(java.lang.String tempName)
          Get a child module with name
 java.lang.String nslGetOrderStr()
           
 java.util.Vector nslGetOutportsVector()
           
 NslPort nslGetPort(java.lang.String name)
          Get a port with name name
 java.util.Vector nslGetProtocols()
           
 double nslGetRunDelta()
          get run step size, delta t
 boolean nslGetRunEnableFlag()
          Examine whether the module runs on execution command run or step
 double nslGetTrainDelta()
          get train step size, delta t
 boolean nslGetTrainEnableFlag()
          Examine whether the module runs on execution command run or step
 boolean nslHasChildModule(java.lang.String s)
           
 void nslInitTempModule()
           
 void nslInitTempRun()
           
 void nslInitTempRunEpoch()
           
 void nslInitTempTrain()
           
 void nslInitTempTrainEpoch()
           
 void nslInitWindow()
           
 void nslinitwindow(NslFrame df)
           
 void nslInitWindow(NslFrame df)
           
 void nslinitwindow(NslFrame df, java.lang.String s)
           
 void nslInitWindow(NslFrame df, java.lang.String s)
           
 void nslPrintChildModules()
           
 void nslRemoveFromLocalProtocols(java.lang.String name)
           
 void nslResetBuffering()
           
 void nslResetRunDelta()
           
 void nslResetTrainDelta()
           
 void nslSetAccessRecursive(char new_desiredAccess)
           
 void nslSetApproximationDelta(double t)
          To set the time step size
 void nslSetApproximationMethod(NslDiff dm)
           
 void nslSetBuffering(boolean v)
           
 void nslSetDisplayFrame(NslFrame df)
           
 void nslSetId(NslModule parent, int id)
           
 void nslSetModuleSpecificParams()
           
 void nslSetModuleSpecificParams(java.lang.String label, NslModule parent)
           
 void nslSetModuleSpecificParams2()
           
 void nslSetProtocolFlagRecursiveDown(java.lang.String name)
           
 void nslSetRunDelta(double t)
           
 void nslSetRunDeltaRecursive(double t)
          set run step size, delta t.
 void nslSetRunEnableFlag(boolean b)
          To set if the module runs on execution command run or step.
 void nslSetTrainDelta(double t)
           
 void nslSetTrainDeltaRecursive(double t)
          set train step size, delta t.
 void nslSetTrainEnableFlag(boolean b)
          To set if the module runs on execution command run or step.
 void nslUpdateBuffering()
           
 void nslUpdateBuffers()
          Update the status of all _outports.
 NslData nslValParent(java.lang.String name)
           
 void run()
          Call when multi-threaded.
 void runsim()
          The run block of this module
 void simrun()
           
 void simRun()
           
 void simTrain()
           
 
Methods inherited from class nslj.src.lang.NslHierarchy
initNslHierarchy, nslAddToClassInstances, nslAddToDataVars, nslGetClassInstance, nslGetClassInstancesVector, nslGetDataVar, nslGetDataVar, nslGetDataVarsVector, nslGetNameAndParent, nslGetNameAndParentRecursive, nslGetSystem, nslGetValue, nslHasChildClass, nslPrintChildClasses, nslRemoveAllClassInstances, nslRemoveAllDataVars, nslRemoveFromClassInstances, nslRemoveFromDataVars, nslSetSystem, nslSetValue, nslSetValue, removeFromNslDataVar
 
Methods inherited from class nslj.src.lang.NslBase
nslGetAccess, nslGetName, nslGetParent, nslGetParentClass, nslGetParentModule, nslGetRealName, nslNullifyParent, nslSetAccess, nslSetName, nslSetParent
 
Methods inherited from class EDU.gatech.cc.is.abstractrobot.ControlSystemMFN150
init
 
Methods inherited from class EDU.gatech.cc.is.abstractrobot.ControlSystemS
configure, Configure, getAbstractRobot, Init, quit, takeStep, TakeStep, trialEnd, TrialEnd, trialInit, TrialInit
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_runDelta

protected double _runDelta

_trainDelta

protected double _trainDelta

_trainDeltaChanged

protected boolean _trainDeltaChanged

_runDeltaChanged

protected boolean _runDeltaChanged

_timeConstantTM

protected double _timeConstantTM

_approximationDelta

protected double _approximationDelta

_diff_method

protected NslDiff _diff_method

_doubleBuffering

protected boolean _doubleBuffering

_bufferingChanged

protected boolean _bufferingChanged

_protocols

protected java.util.Vector _protocols

_moduleChildren

protected java.util.Vector _moduleChildren

_inports

protected java.util.Vector _inports

_outports

protected java.util.Vector _outports

ID_str

public java.lang.String ID_str

order_str

public java.lang.String order_str

ID

public int ID

child_c

public int child_c

postorder

public boolean postorder
Constructor Detail

NslModule

public NslModule()
Bare Constructor. Setup internal variables and lists.

NslModule

public NslModule(java.lang.String label)
Default constructor. Call bare constructor to setup internal variables and lists. Attach itself to parent module. It calls makeinst for child modules creation.
Parameters:
label - - the name of the module

NslModule

public NslModule(java.lang.String label,
                 NslModule parent)
Default constructor. Call bare constructor to setup internal variables and lists. Attach itself to parent module. It calls makeinst for child modules creation.
Parameters:
label - - the name of the module
parent - - the reference of the module's parent module

NslModule

public NslModule(java.lang.String label,
                 NslModule parent,
                 java.lang.String options)
Method Detail

nslSetModuleSpecificParams

public void nslSetModuleSpecificParams()

nslSetModuleSpecificParams

public void nslSetModuleSpecificParams(java.lang.String label,
                                       NslModule parent)

nslSetModuleSpecificParams2

public void nslSetModuleSpecificParams2()

nslGetModuleChildrenVector

public java.util.Vector nslGetModuleChildrenVector()
define the scheduler to use
Parameters:
schduler - public static void nslSetScheduler(NslSchduler sch) { scheduler = sch; }

nslGetInportsVector

public java.util.Vector nslGetInportsVector()

nslGetOutportsVector

public java.util.Vector nslGetOutportsVector()

nslSetId

public void nslSetId(NslModule parent,
                     int id)

nslGetId

public int nslGetId()

nslGetId_str

public java.lang.String nslGetId_str()

nslGetOrderStr

public java.lang.String nslGetOrderStr()

nslAddToModuleChildren

public void nslAddToModuleChildren(NslModule child)
Add child module into this module and into the scheduler
Parameters:
child - - child NslModule

nslGetModuleRef

public NslModule nslGetModuleRef(java.lang.String name)
Get a child module with name
Parameters:
name- - name of target child module
Returns:
children module, null if not found

nslGetModuleRefByName

public NslModule nslGetModuleRefByName(java.lang.String tempName)
Get a child module with name
Parameters:
name- - name of target child module
Returns:
children module, null if not found

nslSetAccessRecursive

public void nslSetAccessRecursive(char new_desiredAccess)
Overrides:
nslSetAccessRecursive in class NslHierarchy

nslHasChildModule

public boolean nslHasChildModule(java.lang.String s)

nslPrintChildModules

public void nslPrintChildModules()

nslAddOutport

public NslNumeric nslAddOutport(java.lang.String name,
                                NslNumeric n)
Create an outport which makes reference to an Object
Parameters:
name - name of this outport
n - reference to a single object
Throws:
NullPointerException - if n is not defined

nslAddOutport

public NslNumeric nslAddOutport(NslNumeric n)
Create an outport which makes reference to a NslNumeric
Parameters:
name - name of this outport
n - reference to a NslNumeric, can be NslNumeric0, NslNumeric1 or NslNumeric2
Throws:
NullPointerException - if n is not defined

nslAddExistingOutport

public void nslAddExistingOutport(NslOutport outport)
Add an Outport to the current outport list
Parameters:
outport - the outport to be added
Throws:
NullPointerException - if outport is null

nslAddInport

public NslNumeric nslAddInport(java.lang.String name,
                               NslNumeric n)
Create an inport which makes reference to an Object
Parameters:
name - name of this intport
n - reference to a NslNumeric, can be NslNumeric0, NslNumeric1 or NslNumeric2
Throws:
NullPointerException - if n is null

nslAddInport

public NslNumeric nslAddInport(NslNumeric n)
Create an inport which makes reference to a Numeric object
Parameters:
name - name of this intport
n - reference to a NslNumeric, can be NslNumeric0, NslNumeric1 or NslNumeric2 or NslNumeric3 or NslNumeric4
Throws:
NullPointerException - if n is null

nslAddExistingInport

public void nslAddExistingInport(NslInport inport)
Add an inport to the current inport list
Parameters:
inport - the inport to be added
Throws:
NullPointerException - if inport is null

nslGetPort

public NslPort nslGetPort(java.lang.String name)
Get a port with name name
Parameters:
name - name of target port
Returns:
port, null if not found

nslDummy

public NslNumeric nslDummy(NslNumeric n)

connect

public boolean connect(NslModule child1,
                       java.lang.String name1,
                       NslModule child2,
                       java.lang.String name2)
Connect two child modules and add the nslConnection to the scheduler
The nslConnection is done in two phases. First, it will nslConnect outport of a child module to the inport of another child module, and outport of a child module to the outport of the parent module (ie the wall of module in one level higher in hierarchy). Second, the nslConnection between the inport of the parent module and the intport of the child module is established. Two phases are needed because the content of the inport of the parent module is not available in the first phase. Here is an illustration:
+-NslModule Top-----------------------------------------------+
| +-NslModule A----------+       +-NslModule B-------------+  |
| | +-NslModule a---+    |       |     +-NslModule b-----+ |  |
| | | variable x    | 1  | 2     | 3   | variable y      | |  |
| | |               |o##o|o#####i|i###i|i                | |  |
| | |               |    |       |     |                 | |  |
| | +---------------+    |       |     +-----------------+ |  |
| +----------------------+       +-------------------------+  |
+-------------------------------------------------------------+
o   outport
i   intport
### nslConnection
Assume we are at the top level in the hierarchy: NslModule Top and we are going to nslConnect two modules, NslModule A and NslModule B. All links #1, #2, #3 are not available. In general case, we need to nslConnect all the links internal to the child modules first, ie #1, and #3.
However, in our implementation of ports, the variable, instead of referencing through ports, references the corresponding variable directly. For instance, for a variable y in NslModule b to read a variable x in NslModule a, y makes a direct reference to x.
This implementation is very efficient in the simulation running phase, but not the initialization, as well as the nslConneciton, phase. The nslConnection #1 works fine, since it can reference variable x. But nslConnection #3 does not work, since at the time of nslConnection, NslModule b cannot see variable x in NslModule a. In this implementation, we "remember" this link and delay the construction.
Go back to the highest level. Link #2 can be done since #1 is established. Link #2 can see variable x in NslModule a now. At this time we can construct the Missing Links.
The missing links in the first phase is stored in _missing_links. The system will call another method nslConnMissingLinks to construct the links in the second phase.
Parameters:
child1 - From module child1
name1 - Port of child1
child2 - To module child2
name2 - Port of child2
Returns:
true if nslConnection is successful
See Also:
NslModule#nslConnChildren_callinitsys, Side Effect: change missing_link: all links not established is stored in missing_link

nslConnect

public boolean nslConnect(NslNumeric num1,
                          NslNumeric num2)

nslConnect

public boolean nslConnect(NslModule child1,
                          java.lang.String name1,
                          NslModule child2,
                          java.lang.String name2)

nslConnect

public boolean nslConnect(nslj.src.lang.NslConnection link)
Connect two modules using defined link
Parameters:
link - The nslConnection between two modules
Returns:
true if the nslConnection is successful

nslConnChildren

public void nslConnChildren()
Call child modules to nslConnect their own internal modules recursively. It is the first stage of nslConnection in makeinst. The links not well defined will be put in _missing_links vector for the second stage
See Also:
NslModule#nslConn, nslConnMissingLinks()

nslConnMissingLinks

public void nslConnMissingLinks()
Call child modules to nslConnect their missing links, if possible It checks the _missing_links vector for the nslConnection required.
See Also:
NslModule#nslConn, NslModule#nslConnChildren_callinitsys

nslGetDelta

public double nslGetDelta()
get run or train step size depending on simulation mode, delta t
Returns:
step size

nslGetRunDelta

public double nslGetRunDelta()
get run step size, delta t
Returns:
step size

nslSetRunDeltaRecursive

public void nslSetRunDeltaRecursive(double t)
set run step size, delta t. The setting will propagate to all child modules in the hierarchy if the module is an internal node.
Parameters:
t - step size

nslSetRunDelta

public void nslSetRunDelta(double t)

nslResetRunDelta

public void nslResetRunDelta()

nslGetTrainDelta

public double nslGetTrainDelta()
get train step size, delta t
Returns:
step size

nslSetTrainDeltaRecursive

public void nslSetTrainDeltaRecursive(double t)
set train step size, delta t. The setting will propagate to all child modules in the hierarchy if the module is an internal node.
Parameters:
t - step size

nslSetTrainDelta

public void nslSetTrainDelta(double t)

nslResetTrainDelta

public void nslResetTrainDelta()

nslGetTrainEnableFlag

public boolean nslGetTrainEnableFlag()
Examine whether the module runs on execution command run or step
Returns:
true if it is active, false if idle on execution command

nslSetTrainEnableFlag

public void nslSetTrainEnableFlag(boolean b)
To set if the module runs on execution command run or step. The setting will propagate to all child modules in the hierarchy if the module is an internal node.
Parameters:
b - true if active, false if idle

nslGetRunEnableFlag

public boolean nslGetRunEnableFlag()
Examine whether the module runs on execution command run or step
Returns:
true if it is active, false if idle on execution command

nslGetEnableFlag

public boolean nslGetEnableFlag()

nslSetRunEnableFlag

public void nslSetRunEnableFlag(boolean b)
To set if the module runs on execution command run or step. The setting will propagate to all child modules in the hierarchy if the module is an internal node.
Parameters:
b - true if active, false if idle

nslGetApproximationDelta

public double nslGetApproximationDelta()
get integration time step / numerical method time step tm
Returns:
time step size

nslSetApproximationDelta

public void nslSetApproximationDelta(double t)
To set the time step size
Parameters:
t - time step size

nslGetApproximationMethod

public NslDiff nslGetApproximationMethod()

nslSetApproximationMethod

public void nslSetApproximationMethod(NslDiff dm)

nslUpdateBuffers

public void nslUpdateBuffers()
Update the status of all _outports. It is done after each major numerical calculation

nslSetBuffering

public void nslSetBuffering(boolean v)

nslGetBuffering

public boolean nslGetBuffering()

nslResetBuffering

public void nslResetBuffering()

nslUpdateBuffering

public void nslUpdateBuffering()

run

public void run()
Call when multi-threaded. It simply calls execute() defined by the user This is needed by the Runnable interface to make the applets work
Specified by:
run in interface java.lang.Runnable
See Also:
NslModule#execute

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

makeinst

public void makeinst(java.lang.String name,
                     NslModule p)
Instantiation the internal variable of this object. It is called automatically at the construction phase of this module. It must be defined by user.

makeInst

public void makeInst(java.lang.String name,
                     NslModule p)

initsys

public void initsys()

initSys

public void initSys()

endsys

public void endsys()

endSys

public void endSys()

initModule

public void initModule()

endModule

public void endModule()

initrun

public void initrun()
Initialization step of this module. It is called automatically at the start of the simulation, or by init command in interactive environment.

initRun

public void initRun()

endrun

public void endrun()

endRun

public void endRun()

makeConn

public void makeConn()
Make the nslConnection between child modules. It is automatically called at the construction phase of this module, but after the instantiation of those internal modules

runsim

public void runsim()
The run block of this module

simrun

public void simrun()

initRunEpoch

public void initRunEpoch()

simRun

public void simRun()

endRunEpoch

public void endRunEpoch()

initTrainEpoch

public void initTrainEpoch()

initTrain

public void initTrain()

simTrain

public void simTrain()

endTrain

public void endTrain()

endTrainEpoch

public void endTrainEpoch()

nslGetProtocols

public java.util.Vector nslGetProtocols()

nslRemoveFromLocalProtocols

public void nslRemoveFromLocalProtocols(java.lang.String name)

nslAddProtocolRecursiveDown

public void nslAddProtocolRecursiveDown(java.lang.String name)

nslAddProtocolRecursiveUp

public void nslAddProtocolRecursiveUp(java.lang.String name)

nslDeclareProtocol

public void nslDeclareProtocol(java.lang.String name,
                               java.lang.String label)

nslDeclareProtocol

public void nslDeclareProtocol(java.lang.String name)

nslSetProtocolFlagRecursiveDown

public void nslSetProtocolFlagRecursiveDown(java.lang.String name)

nslValParent

public NslData nslValParent(java.lang.String name)

nslSetDisplayFrame

public void nslSetDisplayFrame(NslFrame df)

nslAddModelPlots

public void nslAddModelPlots(NslFrame df)

nslAddModelPlots

public void nslAddModelPlots(NslFrame df,
                             java.lang.String s)

nslInitTempRun

public void nslInitTempRun()

nslInitTempTrain

public void nslInitTempTrain()

nslInitTempModule

public void nslInitTempModule()

nslInitTempRunEpoch

public void nslInitTempRunEpoch()

nslInitTempTrainEpoch

public void nslInitTempTrainEpoch()

nslinitwindow

public void nslinitwindow(NslFrame df)

nslinitwindow

public void nslinitwindow(NslFrame df,
                          java.lang.String s)

nslInitWindow

public void nslInitWindow(NslFrame df)

nslInitWindow

public void nslInitWindow(NslFrame df,
                          java.lang.String s)

nslInitWindow

public void nslInitWindow()