util
Class PIDControl

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.PIDControl
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class PIDControl
extends PropertyBundles

PID (Proportional-Integral-Differential) Controllers are basic applications in servo motor controls. If the difference between nominal and actual is denoted as an error e(t), the output of the PID controller, i.e. the required correction c(t) can be writtn as:

   c(t)=kp·e(t)+ki·∫e(t)dt+kd·de(t)/dt
   
The name PID comes from these three proportional constant, that are related to the signal itself, its integral, respectively differential with time. Determining the values of this three parameter is some science on its own.

This class allows basic access to PID-control. It allows registering of an Integrator and Differentiator. The three constants are provided in the PIDControl's properties. Calling the getCorrection() method evaluates the formular above and returns the c(t).


Nested Class Summary
static class PIDControl.Test
          Test string representation.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static double DEFDIFFERENTIAL
          The default value of the differential constant.
private static Class DEFDIFFERENTIATOR
          The default differentiator class .
private static double DEFINTEGRAL
          The default value of the integral constant.
private static Class DEFINTEGRATOR
          The default integrator class .
private static double DEFLIMIT
          The default limit, zero=no limit.
private static double DEFPROPORTIONAL
          The default value of the proportional constant.
private  Differentiator differentiate
          The differentiator to use.
private  boolean initialized
          True after the first error has been added.
private  Integrator integrate
          The integrator to use.
static String KEY_DIFFERENTIAL
          The differential constant.
static String KEY_DIFFERENTIATOR
          The class name of the differentiator.
static String KEY_INTEGRAL
          The integral constant.
static String KEY_INTEGRATOR
          The class name of the integrator.
static String KEY_LIMIT
          The PID correction limit.
static String KEY_PROPORTIONAL
          The proportional constant.
private  double lastoffset
          The last offset added, used for the proportional term.
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
applet, DEFURLUSECONFIG, DEFURLUSECURRENT, DEFURLUSEHOME, KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
PIDControl(Map<String,String> info)
          Constructs a new PID-control.
PIDControl(String pid)
          Convenience constructor allowing instantiation with a string like
 
Method Summary
 void addError(double offset)
          Adds an error signal in the equal time-step case.
 void addError(double t, double offset)
          Adds an error signal with a varying time-step.
 void clear()
          Clears the PID and allows for a new run.
 double getCorrection()
          Returns the correction to the signal as derived from previous offsets.
 double getDifferential()
          Sets the differential term.
 double getIntegral()
          Sets the integral term.
 double getProportional()
          Gets the proportinal term.
private static boolean searchDouble(String key1, String keyset, Map<String,String> search, PropertySupplying where)
          Searches the map for a string representation of the key in the first argument, tries to convert this to a double and set this as the second string property in the property container.
 void setDifferential(double diff)
          Sets the differential term.
 void setIntegral(double integral)
          Sets the integral term.
 void setProportional(double prop)
          Sets the proportinal term.
 String toString()
          Returns the three main parameters of the pid as a string.
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, init, keyCreate, keyCreate, loadAppletResource, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 

Field Detail

KEY_PROPORTIONAL

public static final String KEY_PROPORTIONAL
The proportional constant.

See Also:
Constant Field Values

KEY_DIFFERENTIAL

public static final String KEY_DIFFERENTIAL
The differential constant.

See Also:
Constant Field Values

KEY_INTEGRAL

public static final String KEY_INTEGRAL
The integral constant.

See Also:
Constant Field Values

KEY_LIMIT

public static final String KEY_LIMIT
The PID correction limit. Corrections exceeding this are truncated.

See Also:
Constant Field Values

KEY_INTEGRATOR

public static final String KEY_INTEGRATOR
The class name of the integrator.

See Also:
Constant Field Values

KEY_DIFFERENTIATOR

public static final String KEY_DIFFERENTIATOR
The class name of the differentiator.

See Also:
Constant Field Values

DEFPROPORTIONAL

private static final double DEFPROPORTIONAL
The default value of the proportional constant.

See Also:
Constant Field Values

DEFDIFFERENTIAL

private static final double DEFDIFFERENTIAL
The default value of the differential constant.

See Also:
Constant Field Values

DEFINTEGRAL

private static final double DEFINTEGRAL
The default value of the integral constant.

See Also:
Constant Field Values

DEFLIMIT

private static final double DEFLIMIT
The default limit, zero=no limit.

See Also:
Constant Field Values

DEFINTEGRATOR

private static final Class DEFINTEGRATOR
The default integrator class .


DEFDIFFERENTIATOR

private static final Class DEFDIFFERENTIATOR
The default differentiator class .


lastoffset

private double lastoffset
The last offset added, used for the proportional term.


integrate

private Integrator integrate
The integrator to use.


differentiate

private Differentiator differentiate
The differentiator to use.


initialized

private boolean initialized
True after the first error has been added.

Constructor Detail

PIDControl

public PIDControl(String pid)
Convenience constructor allowing instantiation with a string like
P=0.5:I=0.2:D=0.0:L=20.


PIDControl

public PIDControl(Map<String,String> info)
Constructs a new PID-control. It is the user's responsibility to not call the getCorrection() method before enough differences had been added with addError(double) for the integrator/differentiator to work. Additionally, the user must be aware that the integrator/ differentiator supplied in the properties is compliant with the addError(double) method used, i.e. whether a fixed time-step or a (error-t) pair is used.

Method Detail

searchDouble

private static final boolean searchDouble(String key1,
                                          String keyset,
                                          Map<String,String> search,
                                          PropertySupplying where)
Searches the map for a string representation of the key in the first argument, tries to convert this to a double and set this as the second string property in the property container.

Returns:
True, if double was entered.

addError

public void addError(double offset)
Adds an error signal in the equal time-step case. It is the users responsibility to supply an integrator/differntiator that can work with equal step-size integration/differentiation. The default integrator and differentiator can only work with this method.


clear

public void clear()
Clears the PID and allows for a new run.


addError

public void addError(double t,
                     double offset)
Adds an error signal with a varying time-step. It is the users responsibility to supply an integrator/differntiator that can work with non-equal step-size integration/differentiation. The default integrator and differentiator can not work with this method.


getCorrection

public double getCorrection()
Returns the correction to the signal as derived from previous offsets. May not be called prior to adding enough offsets using the addError(double) method.


getProportional

public double getProportional()
Gets the proportinal term.


setProportional

public void setProportional(double prop)
Sets the proportinal term.


getDifferential

public double getDifferential()
Sets the differential term.


setDifferential

public void setDifferential(double diff)
Sets the differential term.


getIntegral

public double getIntegral()
Sets the integral term.


setIntegral

public void setIntegral(double integral)
Sets the integral term.


toString

public String toString()
Returns the three main parameters of the pid as a string.

Overrides:
toString in class PropertyContainer