Package ptolemy.domains.continuous.lib
Class PeriodicSampler
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.Transformer
-
- ptolemy.domains.continuous.lib.PeriodicSampler
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class PeriodicSampler extends Transformer
This actor generates discrete events by periodically sampling the input signal. The sampling rate is given by parameter samplePeriod, which has default value 0.1. Specifically, if the actor is initialized at time t and the sample period is T, then the output will have the value of the input at times t + nT, for all natural numbers n. By default, this sampler will send to the output the initial value of the input (the input value at microstep 0), but will send it one microstep later (at microstep 1). This ensures that the output at microstep 0 is always absent, thus ensuring continuity from the left. That is, the input is absent prior to the sample time, so continuity requires that it be absent at microstep 0 at the sample time.To get this sampler to record values other than the initial value, set the microstep parameter to a value greater than 0. Setting it to 1, for example, will record the input value after a discontinuity rather than before the discontinuity. Note that
Sampler
normally records its inputs at microstep 1 (because it is triggered by a discrete signal, which has events at microstep 1), and therefore if you want this PeriodicSampler to behave the same as Sampler, you should set microstep to 1.This actor has multiport inputs and outputs. Signals in each input channel are sampled and produced to corresponding output channel.
Note that this actor does not tolerate changing input or output connections during execution.
- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description Parameter
microstep
The microstep at which to read the input.Parameter
samplePeriod
The parameter for the sampling period.-
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description PeriodicSampler(CompositeEntity container, java.lang.String name)
Construct an actor in the specified container with the specified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
If the attribute is microstep, adjust the causality interface.java.lang.Object
clone(Workspace workspace)
Clone this actor into the specified workspace.void
fire()
Generate an output if the current time is one of the sampling times and the microstep matches.void
initialize()
Set the next sampling time for each input as the start time (i.e.boolean
isStrict()
Return false if the microstep value is zero.boolean
postfire()
If the current microstep is zero, sample the inputs and request a refiring at the current time.void
preinitialize()
Make sure the actor runs inside a domain that understands superdense time.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, 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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, 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
-
-
-
-
Constructor Detail
-
PeriodicSampler
public PeriodicSampler(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. The actor can be either dynamic, or not. It must be set at the construction time and can't be changed thereafter. A dynamic actor will produce a token at its initialization phase.- Parameters:
container
- The container of this actor.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
If the attribute is microstep, adjust the causality interface.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the superclass throws it.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone this actor into the specified workspace. The new actor is not added to the directory of that workspace (you must do this yourself if you want it there). The result is a new actor with the same ports as the original, but no connections and no container. A container must be set before much can be done with this actor.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- A new ComponentEntity.
- Throws:
java.lang.CloneNotSupportedException
- If cloned ports cannot have as their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
fire
public void fire() throws IllegalActionException
Generate an output if the current time is one of the sampling times and the microstep matches. In addition, if the microstep parameter has value 0, produce the output only if the current microstep is 1. The value of the event is the value of the input signal at the current time at the microstep specified by the microstep parameter.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the transfer of tokens failed.
-
initialize
public void initialize() throws IllegalActionException
Set the next sampling time for each input as the start time (i.e. the current time). We do not register the start time as a breakpoint, since the director will fire at the start time any way.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If thrown by the supper class.
-
isStrict
public boolean isStrict()
Return false if the microstep value is zero. In that case, this actor can produce some outputs even the inputs are unknown. This actor is usable for breaking feedback loops. It does not read inputs in the fire() method.- Specified by:
isStrict
in interfaceExecutable
- Overrides:
isStrict
in classAtomicActor<TypedIOPort>
- Returns:
- False.
-
postfire
public boolean postfire() throws IllegalActionException
If the current microstep is zero, sample the inputs and request a refiring at the current time. If it is one, then request a refiring at the next sample time.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True.
- Throws:
IllegalActionException
- If the superclass throws it.
-
preinitialize
public void preinitialize() throws IllegalActionException
Make sure the actor runs inside a domain that understands superdense time.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the director is not a SuperdenseTimeDirector or the parent class throws it.
-
-