ptolemy.domains.ct.lib
Class LevelCrossingDetector

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.Transformer
                              extended byptolemy.domains.ct.lib.LevelCrossingDetector
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, CTEventGenerator, CTStepSizeControlActor, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, java.io.Serializable, ptolemy.actor.TypedActor
Direct Known Subclasses:
ZeroCrossingDetector

public class LevelCrossingDetector
extends Transformer
implements CTStepSizeControlActor, CTEventGenerator

An event detector that converts continuous signals to discrete events when the continuous signal crosses a level threshold.

When the trigger equals to the level threshold (within the specified errorTolerance), this actor outputs a discrete event with the value as defaultEventValue if useEventValue is selected. Otherwise, the actor outputs a discrete event with the value as the level threshold. This actor controls the integration step size to accurately resolve the time at which the level crossing occurs. So, this actor is only used in Continuous Time domain.

Since:
Ptolemy II 2.0
Version:
$Id: LevelCrossingDetector.java,v 1.31 2004/04/14 02:52:26 cxh Exp $
Author:
Jie Liu, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (liuj)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
protected  double _level
           
 ptolemy.data.expr.Parameter defaultEventValue
          The parameter that specifies the default output event value if the input port is not connected to any thing.
 ptolemy.data.expr.Parameter errorTolerance
          The parameter of error tolerance of type double.
 ptolemy.data.expr.Parameter level
          The parameter that specifies the level threshold.
 ptolemy.actor.TypedIOPort trigger
          The trigger port.
 ptolemy.data.expr.Parameter useEventValue
          The parameter that indicates whether to use the default event value.
 
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
LevelCrossingDetector(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.Attribute attribute)
          Update the attribute if it has been changed.
 java.lang.Object clone(ptolemy.kernel.util.Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Consume the trigger token.
 boolean hasCurrentEvent()
          Return true if there is an event at the current time.
 void initialize()
          Initialize the execution.
 boolean isThisStepAccurate()
          Return true if this step does not cross the threshold.
 boolean postfire()
          Prepare for the next iteration, by making the current trigger token to be the history trigger token.
 double predictedStepSize()
          Return the maximum Double, since this actor does not predict step size.
 boolean prefire()
          If the level has changed during the last iteration, update the parameter value.
 void preinitialize()
          Make sure the actor runs inside a CT domain.
 double refinedStepSize()
          Return the refined step size if there is a missed event, otherwise return the current step size.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

trigger

public ptolemy.actor.TypedIOPort trigger
The trigger port. Single port with type double.


errorTolerance

public ptolemy.data.expr.Parameter errorTolerance
The parameter of error tolerance of type double. By default, it contains a DoubleToken of 1e-4.


level

public ptolemy.data.expr.Parameter level
The parameter that specifies the level threshold. By default, it contains a DoubleToken of value 0.0. Note, a change of this parameter at run time will not be applied until the next iteration.


defaultEventValue

public ptolemy.data.expr.Parameter defaultEventValue
The parameter that specifies the default output event value if the input port is not connected to any thing. If the input is connected, this value is ignored. By default, it contains a DoubleToken of value 0.0.


useEventValue

public ptolemy.data.expr.Parameter useEventValue
The parameter that indicates whether to use the default event value.


_level

protected double _level
Constructor Detail

LevelCrossingDetector

public LevelCrossingDetector(ptolemy.kernel.CompositeEntity container,
                             java.lang.String name)
                      throws ptolemy.kernel.util.IllegalActionException,
                             ptolemy.kernel.util.NameDuplicationException
Construct an actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.

Parameters:
container - The subsystem that this actor is lived in
name - The actor's name
Throws:
ptolemy.kernel.util.IllegalActionException - If the entity cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If name coincides with an entity already in the container.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.IllegalActionException
Update the attribute if it has been changed. If the attribute is errorTolerance then update the local cache.

Parameters:
attribute - The attribute that has changed.
Throws:
ptolemy.kernel.util.IllegalActionException - If the attribute change failed.

clone

public java.lang.Object clone(ptolemy.kernel.util.Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the value public variable in the new object to equal the cloned parameter in that new object.

Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.

fire

public void fire()
          throws ptolemy.kernel.util.IllegalActionException
Consume the trigger token. The trigger token will be used for finding the level crossing in the isThisStepAccurate() method to control the step size. If it is discrete phase, and if the trigger equals the level (within the given error tolerance), output a discrete event with the value of specified level.

Specified by:
fire in interface ptolemy.actor.Executable
Throws:
ptolemy.kernel.util.IllegalActionException - If no token is available.

hasCurrentEvent

public boolean hasCurrentEvent()
Return true if there is an event at the current time.

Specified by:
hasCurrentEvent in interface CTEventGenerator
Returns:
True if there is an event at the current time.

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
Initialize the execution.

Specified by:
initialize in interface ptolemy.actor.Executable
Throws:
ptolemy.kernel.util.IllegalActionException - If thrown by the super class.

isThisStepAccurate

public boolean isThisStepAccurate()
Return true if this step does not cross the threshold. The current trigger token will be compared to the previous trigger token. If they cross the level threshold, this step is not accurate. A special case is taken care so that if the previous trigger and the current trigger both equal to the level value, then no new event is detected. If this step crosses the level threshold, then the refined integration step size is computed by linear interpolation. If this is the first iteration after initialize() is called, then always return true, since there is no history to compare with.

Specified by:
isThisStepAccurate in interface CTStepSizeControlActor
Returns:
True if the trigger input in this integration step does not cross the level threshold.

postfire

public boolean postfire()
Prepare for the next iteration, by making the current trigger token to be the history trigger token.

Specified by:
postfire in interface ptolemy.actor.Executable
Returns:
True always.

predictedStepSize

public double predictedStepSize()
Return the maximum Double, since this actor does not predict step size.

Specified by:
predictedStepSize in interface CTStepSizeControlActor
Returns:
java.Double.MAX_VALUE.

prefire

public boolean prefire()
                throws ptolemy.kernel.util.IllegalActionException
If the level has changed during the last iteration, update the parameter value. Note that only after the calling of this method, would the new value of level be used for detection.

Specified by:
prefire in interface ptolemy.actor.Executable
Returns:
Same as that in the super class.
Throws:
ptolemy.kernel.util.IllegalActionException - If the getToken() method of the level parameter throws it.

preinitialize

public void preinitialize()
                   throws ptolemy.kernel.util.IllegalActionException
Make sure the actor runs inside a CT domain.

Specified by:
preinitialize in interface ptolemy.actor.Executable
Throws:
ptolemy.kernel.util.IllegalActionException - If the director is not a CTDirector or the parent class throws it.

refinedStepSize

public double refinedStepSize()
Return the refined step size if there is a missed event, otherwise return the current step size.

Specified by:
refinedStepSize in interface CTStepSizeControlActor
Returns:
The refined step size.