|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.Source
ptolemy.actor.lib.TimedSource
ptolemy.actor.lib.Clock
public class Clock
This actor produces a periodic signal, a sequence of events at regularly spaced intervals. At the beginning of each time interval of length given by period, starting from the time at which initialize() is invoked, this actor initiates a sequence of output events with values given by values and offset into the period given by offsets. These parameters contain arrays, which are required to have the same length. The offsets array contains doubles, which must be nondecreasing and nonnegative, or an exception will be thrown when it is set. If any entry is greater than or equal to the period then the corresponding output will never be produced.
The values parameter by default contains an array of IntTokens with values 1 and 0. The default offsets array is {0.0, 1.0}. Thus, the default output will be alternating 1 and 0 with 50% duty cycle. The default period is 2.0.
The type of the output can be any token type. This type is inferred from the element type of the values parameter.
If the period is changed at any time, either by providing an input or by changing the parameter, then the new period will take effect as soon as possible. That is, if there is already a period in progress, it may be cut short if the new period is shorter so that its time matches the new period. But it will only be cut short if current time has not passed the cycle start time plus the new period. Otherwise, the period in progress will run to completion.
This actor can generate finite sequences by specifying a finite numberOfCycles. The numberOfCycles has a default value UNBOUNDED, indicating infinite length of executions. If numberOfCycles is a positive number, once the specified number of cycles has been completed, then this actor returns false from the postfire() method, which indicates to the director that the actor should not be fired again. (A cycle is "completed" each time the last event in the values array is produced).
The actor can also generate a finite sequence by giving a finite value to the stopTime parameter. This gives a time rather than a number of cycles, and thus can be used to stop the clock in the middle of a cycle, unlike numberOfCycles. Just like numberOfCycles, when the stop time is reached, the actor's postfire() method returns false.
If the trigger input is connected, then an output will only be produced if a input has been received since the last output. The trigger input has no effect on the first output. After the first output event, no further output event will be produced until a time greater than or equal to the time at which a trigger input is received. At that time, the output produced will have whatever value would have been produced if the trigger input was not connected. Note that this trigger is typically useful in a feedback situation, where the output of the clock eventually results in a trigger input. If the time-stamp of that trigger input is less than the time between clock events, then the clock will behave as if there were no trigger input. Otherwise, it will "skip beats."
This actor can be a bit tricky to use inside a ModalModel. In particular, if the actor is in a state refinement, then it may "skip a beat" because of the state not being the current state at the time of the beat. If this occurs, the clock will simply stop firing, and will produce no further outputs. To prevent this, the clock may be reinitialized (by setting the reset flag of a modal model transition). Alternatively, you can assign a value to the the period of the Clock in the setActions of the transition. This will also have the effect of waking up the clock, but with a subtle difference. If you use a reset transition, the clock starts over upon entering the destination state. If you set the period parameter instead, then the clock behaves as if it had been running all along (except that its period may get changed). Thus, in the first case, the output events are aligned with the time of the transition, while in the second case, they are aligned with the start time of the model execution.
This actor is a timed source; the untimed version is Pulse.
Yellow (yuhong) |
Yellow (eal) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.Entity |
---|
Entity.ContainedObjectsIterator |
Field Summary | |
---|---|
protected int |
_cycleCount
The count of cycles executed so far, or 0 before the start. |
protected Time |
_cycleStartTime
The most recent cycle start time. |
protected boolean |
_enabled
Indicator of whether the specified number of cycles have been completed. |
protected boolean |
_firstOutputProduced
Indicator of whether the first output has been produced. |
protected Time |
_nextOutputTime
The time for the next output. |
protected double[] |
_offsets
Cache of offsets array value. |
protected boolean |
_outputProduced
Indicator of whether an output was produced in this iteration. |
protected int |
_phase
The phase of the next output. |
private double |
_previousPeriod
The previous value of the period. |
private boolean |
_tentative
Flag indicating that an update to period is occurring in the fire() method. |
private Time |
_tentativeCycleStartTime
The tentative start time of the most recent cycle. |
private boolean |
_tentativeEnabled
The indicator of whether the specified number of cycles have been completed. |
protected Time |
_tentativeNextOutputTime
The tentative time for the next output. |
private int |
_tentativePhase
The tentative phase of the next output. |
private boolean |
_tentativeTriggered
Tentative indicator of triggered state. |
private boolean |
_triggered
Indicator of whether trigger inputs have arrived since the last output. |
Parameter |
numberOfCycles
The number of cycles to produce, or UNBOUNDED to specify no limit. |
Parameter |
offsets
The offsets at which the specified values will be produced. |
PortParameter |
period
The period of the output waveform. |
Parameter |
values
The values that will be produced at the specified offsets. |
Fields inherited from class ptolemy.actor.lib.TimedSource |
---|
stopTime, stopTimeIsLocal |
Fields inherited from class ptolemy.actor.lib.Source |
---|
output, trigger |
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 |
Constructor Summary | |
---|---|
Clock(CompositeEntity container,
java.lang.String name)
Construct an actor with the specified container and name. |
Method Summary | |
---|---|
protected void |
_catchUp()
Catch up the tentative view of what the next output time should be. |
protected Token |
_getValue(int index)
Get the specified output value, checking the form of the values parameter. |
protected boolean |
_isTimeForOutput()
Return true if the current time is the right time for an output. |
protected void |
_updateStates()
Update the states and request refiring if necessary. |
protected void |
_updateTentativeValues()
Copy values committed in initialize() or in the last postfire() into the corresponding tentative variables. |
void |
attributeChanged(Attribute attribute)
If the argument is the offsets parameter, check that the array is nondecreasing and has the right dimension; if the argument is period, check that it is positive. |
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace. |
void |
fire()
Output the current value of the clock if the time is right and, if connected, a trigger has been received. |
void |
initialize()
Schedule the first firing and initialize local variables. |
boolean |
postfire()
Update the state of the actor and schedule the next firing, if appropriate. |
boolean |
prefire()
Check that the length of the values and offsets parameters are the same. |
Methods inherited from class ptolemy.actor.lib.TimedSource |
---|
getModelStopTime, getStopTime, wrapup |
Methods inherited from class ptolemy.actor.TypedAtomicActor |
---|
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints |
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 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, stop, stopFire, terminate |
Methods inherited from interface ptolemy.actor.Initializable |
---|
addInitializable, preinitialize, removeInitializable |
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 |
---|
public Parameter numberOfCycles
public Parameter offsets
public PortParameter period
public Parameter values
protected transient int _cycleCount
protected transient Time _cycleStartTime
protected transient boolean _enabled
protected transient boolean _firstOutputProduced
protected transient Time _nextOutputTime
protected transient double[] _offsets
protected transient boolean _outputProduced
protected transient int _phase
protected transient Time _tentativeNextOutputTime
private transient double _previousPeriod
private transient Time _tentativeCycleStartTime
private transient boolean _tentative
private transient boolean _tentativeEnabled
private transient int _tentativePhase
private transient boolean _tentativeTriggered
private transient boolean _triggered
Constructor Detail |
---|
public Clock(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container
- The container.name
- The name of this actor.
IllegalActionException
- If the entity cannot be contained
by the proposed container.
NameDuplicationException
- If the container already has an
actor with this name.Method Detail |
---|
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class TimedSource
attribute
- The attribute that changed.
IllegalActionException
- If the offsets array is not
nondecreasing and nonnegative, or if the director will not
respect the fireAt() call.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class AtomicActor
workspace
- The workspace for the new object.
java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Source
IllegalActionException
- If
the value in the offsets parameter is encountered that is greater
than the period, or if there is no director.public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class TimedSource
IllegalActionException
- If the parent class throws it,
or if the values parameter is not a row vector, or if the
fireAt() method of the director throws it, or if the director will not
respect the fireAt() call.public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class TimedSource
IllegalActionException
- If the director throws it when
scheduling the next firing.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class TimedSource
IllegalActionException
- If the values and
offsets parameters do not have the same length.protected void _catchUp() throws IllegalActionException
IllegalActionException
- If the period is invalid.protected Token _getValue(int index) throws IllegalActionException
index
- The index of the output values.
IllegalActionException
- If the index is out of the range of
the values parameter.protected boolean _isTimeForOutput() throws IllegalActionException
IllegalActionException
- If the time is not right an
a refiring cannot be requested.protected void _updateTentativeValues() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected void _updateStates() throws IllegalActionException
IllegalActionException
- If the numberOfCycles parameter does
not contain a valid parameter or can not request refiring, or if the director will not
respect the fireAt() call..
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |