ptolemy.domains.de.lib
Class PID

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.de.kernel.DEActor
                              extended by ptolemy.domains.de.lib.DETransformer
                                  extended by ptolemy.domains.de.lib.PID
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TimedActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class PID
extends DETransformer

Generate PID output for a given input. The output is the sum of a proportional gain (P), discrete integration (I), and discrete derivative (D).

The proportional component of the output is immediately available, such that yp[n]=Kp*x[n], where yp is the proportional component of the output, Kp is the proportional gain, and x is the input value.

For integral gain, the output is available after two input symbols have been received, such that yi[n]=Ki*(yi[n-1]+(x[n] + x[n-1]))*dt[n]/2, where yi is the integral component of the output, Ki is the integral gain, and dt[n] is the time differential between input events x[n] and x[n-1].

For derivative gain, the output is available after two input symbols have been received, such that yd[n] = Kd*(x[n]-x[n-1])/dt, where yd is the derivative component of the output, Kd is the derivative gain, and dt is the time differential between input events events x[n] and x[n-1].

The output of this actor is constrained to be a double, and input must be castable to a double. If the input signal is not left-continuous and the derivative constant is nonzero, then this actor will throw an exception as the derivative will be either infinite or undefined. If the derivative constant is zero, then this actor may recieve discontinuous input.

y[0]=Kp*x[0]
y[n] = yp[n] + yi[n] + yd[n]
y[n] = Kp*x[n] + Ki*sum{x=1}{n}{(x[n]+x[n-1])/2*dt[n]} + Kd*(x[n]-x[n-1]/dt[n])

In postfire(), if an event is present on the reset port, this actor resets to its initial state, where integral and derivative components of output will not be present until two subsequent inputs have been consumed. This is useful if the input signal is switched on and off, in which case the time gap between events becomes large and would otherwise effect the value of the derivative (for one sample) and the integral.

Since:
Ptolemy II 8.0
Version:
$Id: PID.java 59203 2010-09-23 21:41:27Z cxh $
Author:
Jeff C. Jensen
See Also:
Integrator, Derivative, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  DoubleToken _accumulated
           
private  TimedEvent _currentInput
           
private  TimedEvent _lastInput
           
 Parameter Kd
          Derivative gain of the controller.
 Parameter Ki
          Integral gain of the controller.
 Parameter Kp
          Proportional gain of the controller.
 TypedIOPort reset
          The reset port, which has undeclared type.
 
Fields inherited from class ptolemy.domains.de.lib.DETransformer
input, output
 
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
PID(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          If the attribute is Kp, Ki, or Kd then ensure that the value is numeric.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Consume at most one token from the input port and output the PID control.
 void initialize()
          Reset to indicate that no input has yet been seen.
 boolean postfire()
          Record the most recent input as the latest input.
 
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, preinitialize, 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, preinitialize, 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

reset

public TypedIOPort reset
The reset port, which has undeclared type. If this port receives a token, this actor resets to its initial state, and no output is generated until two inputs have been received.


Kp

public Parameter Kp
Proportional gain of the controller. Default value is 1.0.


Ki

public Parameter Ki
Integral gain of the controller. Default value is 0.0, which disables integral control.


Kd

public Parameter Kd
Derivative gain of the controller. Default value is 0.0, which disables derivative control. If Kd=0.0, this actor can receive discontinuous signals as input; otherwise, if Kd is nonzero and a discontinuous signal is received, an exception will be thrown.


_currentInput

private TimedEvent _currentInput

_lastInput

private TimedEvent _lastInput

_accumulated

private DoubleToken _accumulated
Constructor Detail

PID

public PID(CompositeEntity container,
           java.lang.String name)
    throws NameDuplicationException,
           IllegalActionException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

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

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 has has an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the attribute is Kp, Ki, or Kd then ensure that the value is numeric.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If the value is non-numeric.

initialize

public void initialize()
                throws IllegalActionException
Reset to indicate that no input has yet been seen.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it.

fire

public void fire()
          throws IllegalActionException
Consume at most one token from the input port and output the PID control. If there has been no previous iteration, only proportional output is generated. If there is no input, then produce no output.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If addition, multiplication, subtraction, or division is not supported by the supplied tokens.

postfire

public boolean postfire()
                 throws IllegalActionException
Record the most recent input as the latest input. If a reset event has been received, process it here.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If the base class throws it.