public class Clock extends TimedSource
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) |
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
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.
|
protected Time |
_tentativeNextOutputTime
The tentative time for the next 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.
|
stopTime, stopTimeIsLocal
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
Clock(CompositeEntity container,
java.lang.String name)
Construct an actor with the specified container and name.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
wrapup()
Override the base class to indicate that the actor has not
been initialized.
|
getModelStopTime, getStopTime
_customTypeConstraints
_containedTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
addInitializable, preinitialize, removeInitializable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
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
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.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 TypedAtomicActor
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.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class TimedSource
IllegalActionException
- If the superclass throws it.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..