ptolemy.domains.ct.lib
Class LevelCrossingDetector

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

public class LevelCrossingDetector
extends TypedAtomicActor
implements CTStepSizeControlActor, CTEventGenerator

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

The direction parameter can constrain the actor to detect only rising or falling transitions. It has three possible values, "rising", "falling", and "both", where "both" is the default.

When the trigger equals the level threshold (within the specified errorTolerance), this actor outputs a discrete event with value defaultEventValue if useEventValue is selected. Otherwise, the actor outputs a discrete event with the value as the level threshold.

This actor controls the step size such that level crossings never occur during an integration. So, this actor is only used in Continuous-Time domain.

Since:
Ptolemy II 2.0
Version:
$Id: LevelCrossingDetector.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (hyzheng)
Proposed Rating:
Yellow (hyzheng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  boolean _detectFallingCrossing
           
private  boolean _detectRisingCrossing
           
private  double _errorTolerance
           
private  boolean _eventMissed
           
private  boolean _eventNow
           
private  double _lastTrigger
           
protected  double _level
          The level threshold this actor detects.
private  double _thisTrigger
           
 Parameter defaultEventValue
          A parameter that specifies the value of output events if the useEventValue parameter is checked.
 StringParameter direction
          A parameter that can be used to limit the detected level crossings to rising or falling.
 Parameter errorTolerance
          The parameter of error tolerance of type double.
 Parameter level
          The parameter that specifies the level threshold.
 TypedIOPort output
          The output port.
 TypedIOPort trigger
          The trigger port.
 Parameter useDefaultEventValue
          The parameter that indicates whether to use the default event value.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
LevelCrossingDetector(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          Update the attribute if it has been changed.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Produce a discrete event if level crossing happens.
 boolean hasCurrentEvent()
          Return true if there is an event at the current time.
 void initialize()
          Initialize the execution.
 boolean isOutputAccurate()
          Return true if there is no event detected during the current step size.
 boolean isStateAccurate()
          Always return true because this actor is not involved in resolving states.
 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.
 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, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

defaultEventValue

public Parameter defaultEventValue
A parameter that specifies the value of output events if the useEventValue parameter is checked. By default, it contains a DoubleToken of 0.0.


direction

public StringParameter direction
A parameter that can be used to limit the detected level crossings to rising or falling. There are three choices: "falling", "rising", and "both". The default value is "both".


errorTolerance

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


level

public 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.


output

public TypedIOPort output
The output port. The type is at least the type of the defaultEventValue parameter.


trigger

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


useDefaultEventValue

public Parameter useDefaultEventValue
The parameter that indicates whether to use the default event value.


_level

protected double _level
The level threshold this actor detects.


_detectRisingCrossing

private boolean _detectRisingCrossing

_detectFallingCrossing

private boolean _detectFallingCrossing

_errorTolerance

private double _errorTolerance

_eventMissed

private boolean _eventMissed

_eventNow

private boolean _eventNow

_lastTrigger

private double _lastTrigger

_thisTrigger

private double _thisTrigger
Constructor Detail

LevelCrossingDetector

public LevelCrossingDetector(CompositeEntity container,
                             java.lang.String name)
                      throws IllegalActionException,
                             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:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If name coincides with an entity already in the container.
Method Detail

attributeChanged

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

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the attribute change failed.

clone

public java.lang.Object clone(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.

Overrides:
clone in class AtomicActor
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.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Produce a discrete event if level crossing happens. If the current execution is in a continuous phase, the current trigger is recorded but no event can be produced. If the current execution is in a discrete phase, the current and previous trigger tokens are compared to find whether a level crossing happens. If there is a crossing, a discrete event is generated.

The value of this event may be the specified level, or the default event value if the usingDefaultEventValue is configured true (checked).

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If can not get token from the trigger port or can not send token through the output port.

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 IllegalActionException
Initialize the execution.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If thrown by the super class.

isOutputAccurate

public boolean isOutputAccurate()
Return true if there is no event detected during the current step size.

Specified by:
isOutputAccurate in interface CTStepSizeControlActor
Returns:
True if there is no event detected in the current iteration.

isStateAccurate

public boolean isStateAccurate()
Always return true because this actor is not involved in resolving states.

Specified by:
isStateAccurate in interface CTStepSizeControlActor
Returns:
true.

postfire

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

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True always.
Throws:
IllegalActionException - If thrown by the super class.

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.

preinitialize

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

Specified by:
preinitialize in interface Initializable
Overrides:
preinitialize in class AtomicActor
Throws:
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.