Michael Thomas Flanagan's Java Scientific Library

PropIntDeriv Class:     Proportional Integral Derivative (PID) Controller

     

Last update: 13 April 2012                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor to create an instance of a Proportional, Integral and Derivative (PID) controller and the methods to use this in both continuous time and discrete control simulations.
This is a subclass of the superclass BlackBox

The PID controller may be described by the Equation 1:

where i(t) is the input to the controller, o(t) is the output and kp, ki and kd are the proportional gain, the integral gain and the derivative gain.
Equation 1 may be expressed as:

where the integral time constant, τi = kp/ki and the derivative time constant, τd = kd/kp. Both implementations are covered in this class.
Methods incorporating a Laplace transform of the first derivative assume a quiescent state before the input at zero time.

import directive: import flanagan.control.PropIntDeriv;

SUMMARY OF CONSTRUCTORS AND METHODS

METHODS FOUND ONLY IN THE SUBCLASS PropIntDeriv

Constructors   public PropIntDeriv()
  public PropIntDeriv(double kp, double ki, double kd)
Set up the controller
Set the PID gains public void setKp(double kp)
public void setKi(double ki)
public void setKd(double kd)
Get the PID gains public double getKp()
public double getKi()
public double getKd()
Set the integral and derivative time constants public void setTi(double ti)
public void setTd(double td)
Get the integral and derivative time constants public double getTi()
public double getTd()

METHODS INHERITED FROM THE SUPERCLASS BlackBox

Deep Copy   public PropIntDeriv copy()
Overridden
public Object clone()
Overridden
s-domain transfer function Get the numerator degree public int getSnumerDeg()
Not overridden
Get the numerator polynomial public ComplexPoly getSnumer()
Not overridden
Get the denominator degree public int getSdenomDeg()
Not overridden
Get the denominator polynomial public ComplexPoly getSdenom()
Not overridden
Get the s-values of the poles publicComplex[ ] getPolesS()
Not overridden
Get the s-values of the zeros publicComplex[ ] getZerosS()
Not overridden
Plot poles and zeros public void plotPolesZeroS()
Not overridden
Set the value of the Laplace s variable public void setS(Complex sValue)
Not overridden
public void setS(double sReal, double sImag)
Not overridden
public void setS(double sImag)
Not overridden
Get the Laplace s value public Complex getS()
Not overridden
Evaluate transfer function public Complex evalTransFunctS()
Not overridden
public Complex evalTransFunctS(Complex sValue)
Not overridden
public Complex evalTransFunctS(double freq)
Not overridden
Evaluate transfer function magnitude public double evalMagTransFunctS()
Not overridden
public double evalMagTransFunctS(Complex sValue)
Not overridden
public double evalMagTransFunctS(double freq)
Not overridden
Evaluate transfer function phase public double evalPhaseTransFunctS()
Not overridden
public double evalPhaseTransFunctS(Complex sValue)
Not overridden
public double evalPhaseTransFunctS(double freq)
Not overridden
Bode plots (magnitude and phase) public void plotBode(double lowFreq, double highFreq,)
Not overridden
Inverse Laplace Transform public static Complex[ ] [ ] inverseTransform(ComplexPoly numer, ComplexPoly Not overridden
public static Complex timeTerm(double time, Complex coeff, Complex constant, Complex power)
Not overridden
Set the input in the s-domain public void setInputS(Complex input)
Not overridden
Get the input in the s-domain public Complex getInputS()
Not overridden
Get the output in the s-domain public Complex getOutputS()
Overridden
public Complex getOutputS(Complex sValue, Complex input)
Overridden
Dead Time
(transportation time)
Set the dead time public void setDeadtime(double deadTime)
Not overridden
public void setDeadtime(double deadTime, double padeOrder)
Not overridden
Get the dead time public double getDeadtime()
Not overridden
Set the Pade order public void setPadeOrder(double padeorder)
Not overridden
Get the Pade order public void setPadeOrder(double padeorder)
Not overridden
Continuous time domain
(uses the s-domain transfer function)
Plot step input transient public void stepInput(double finaltime)
Overridden
public void stepInput(double mag, double finaltime)
Overridden
Plot ramp input transient public void rampInput(double finaltime)
Overridden
public void rampInput(double mag, double finaltime)
Overridden
public void rampInput(int order, double finaltime)
Overridden
public void rampInput(double mag, int order, double finaltime)
Overridden
z-domain transfer function Map s-transfer function into the z-domain public void zTransform()
Overridden
public void zTransform(double deltaT)
Overridden
Get the numerator degree public int getZnumerDeg()
Not overridden
Get the numerator polynomial public ComplexPoly getZnumer()
Not overridden
Get the denominator degree public int getZdenomDeg()
Not overridden
Get the denominator polynomial public ComplexPoly getZdenom()
Not overridden
Get the z-values of the poles publicComplex[ ] getPolesZ()
Not overridden
Get the z-values of the zeros publicComplex[ ] getZerosZ()
Not overridden
Plot poles and zeros public void plotPolesZeroZ()
Not overridden
Set the value of the z variable public void setZ(Complex zValue)
Not overridden
public void setZ(double zReal, double zImag)
Not overridden
Get the z value public Complex getZ()
Not overridden
Evaluate transfer function public Complex evalTransFunctZ()
Not overridden
public Complex evalTransFunctZ(Complex zValue)
Not overridden
Evaluate transfer function magnitude public double evalMagTransFunctZ()
Not overridden
public double evalMagTransFunctZ(Complex zValue)
Not overridden
Evaluate transfer function phase public double evalPhaseTransFunctZ()
Not overridden
public double evalPhaseTransFunctZ(Complex zValue)
Not overridden
Sampled signal Set the sampling length public void setSampleLdength(int samplelength)
Not overridden
Get the sampling length public int getSampleLength()
Not overridden
Set the sampling period public void setDeltaT(double deltaT)
Not overridden
Get the sampling period public double getDeltaT()
Not overridden
Set the sampling frequency public void setSampFreq(double sfreq)
Not overridden
Get the sampling frequency public double getSampFreq()
Not overridden
Set the sampled input and time public void setInputT(double time, double input)
Not overridden
Get the current value of the time public double getCurrentTime()
Not overridden
Get the array of times public double[] getTime()
Not overridden
Get the current value of the input public double getCurrentInputT()
Not overridden
Get the array of the inputs public double[] getInputT()
Not overridden
Calculate the current value of the output public double calcOutputT()
Overridden
public double calcOutputT(double time, double input) Overridden
Get the current value of the output public double getCurrentOutputT()
Not overridden
Get the array of the outputs public double getOutputT()
Not overridden
Set numerical integration method public void setIntegrateMethod(int integMethod)
Not overridden
public void setIntegrateMethod(String integMethodOpt)
Not overridden
Get numerical integration method public int getIntegrateMethod()
Not overridden
Set the exponential forgetting factor public void setForgetFactor(double forgetfactor)
Not overridden
public void setForgetFactor(double forgetfactor, int samplength )
Not overridden
Get the forgetting factor public double getForgetFactor()
Not overridden
General methods Reset all inputs, outputs and times to zero public void resetZero()
Not overridden
Set the name of the black box public void setName(String name)
Not overridden
Get the name of the black box public String getName()
Not overridden

CONSTRUCTORS

public PropIntDeriv()
public PropIntDeriv(double kp, double ki, double kd)
Usage:                      PropIntDeriv pid = new PropIntDeriv();
This constructor creates a new instance of PropIntDeriv with the proportional gain, kp, initialised to unity and with the integral gain, ki, and derivative gain, kd, initialised to zero. It also calculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles.

Usage:                      PropIntDeriv pid = new PropIntDeriv(kp, ki, kd);
This constructor creates a new instance of PropIntDeriv with the proportional gain, kp, set to kp, with the integral gain, ki, set to ki and derivative gain, kd, set to kd . It also calculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles.



SET UP THE PID CONTROLLER

SET THE PID GAINS
public void setKp(double kp)
Usage:                      pid.setKp(kp);
Resets the proportional gain, kp, to the value in the double passed in the argument list, e.g. to kp in the above usage. It also recalculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles.

public void setKi(double ki)
Usage:                      pid.setKi(ki);
Resets the integral gain, ki, to the value in the double passed in the argument list, e.g. to ki in the above usage. It also recalculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles. It also recalculates the integral time constant, τi, as kp/ki.

public void setKd(double kd)
Usage:                      pid.setKd(kd);
Resets the derivative gain, kd, to the value in the double passed in the argument list, e.g. to kd in the above usage. It also recalculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles. It also recalculates the derivative time constant, τd, as kd/kp.



SET THE INTEGRAL AND DERIVATIVE TIME CONSTANTS
public void setTi(double ti)
Usage:                      pid.setTi(ti);
Resets the integral time constant, τi, to the value in the double passed in the argument list, e.g. to ti in the above usage. It also recalculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles. It also recalculates the integral gain, ki, as kp/τi.

public void setTd(double td)
Usage:                      pid.setTd(td);
Resets the derivative time constant, τd, to the value in the double passed in the argument list, e.g. to td in the above usage. It also calculates and stores the s-domain transfer function numerator polynomial, denominator polynomial, zeros and poles. It also recalculates the derivative gain, kd, as kp.τd.



GET THE PID GAINS
public double getKp()
Usage:                      kp = pid.getKp();
Returns the proportional gain, kp.

public double getKi()
Usage:                      ki = pid.getKi();
Returns the integral gain, ki.

public double getKd()
Usage:                      kd = pid.getKd();
Returns the derivative gain, kd.



GET THE INTEGRAL AND DERIVATIVE TIME CONSTANTS
public double getTi()
Usage:                      ti = pid.getTi();
Returns the integral time constant.

public double getTd()
Usage:                      td = pid.getTd();
Returns the derivative time constant.



GET THE OUTPUT IN THE SAMPLED TIME DOMAIN
public Complex getOutputT()
public Complex getOutputT(double time, Complex input)
Usage:                      output = pid.getOutputT();
Returns the output for a stored sampled input, time and sampling period, deltaT. This method overrides the BlackBox method getOutputT().

Usage:                      output = pid.getOutputT(svalue, input);
Returns the output for a given sampled input and time. The sampling period, deltaT, is calculated using the previous sampling time. This method overloads the BlackBox method getOutputT().



OTHER CLASSES USED BY THIS CLASS

This class is a subclass of BlackBox which uses the following classes in this library:
PropIntDeriv also calls directly:

This page was prepared by Dr Michael Thomas Flanagan