Class ControllerDeviceBaseClass

java.lang.Object
neqsim.util.NamedBaseClass
neqsim.process.controllerdevice.ControllerDeviceBaseClass
All Implemented Interfaces:
Serializable, ControllerDeviceInterface, NamedInterface
Direct Known Subclasses:
IntegratedSafetySystemExample.ESDController, IntegratedSafetySystemExample.HIPPSController

public class ControllerDeviceBaseClass extends NamedBaseClass implements ControllerDeviceInterface
Discrete PID controller implementation providing common features for process control in NeqSim. The class supports anti-windup clamping, derivative filtering, gain scheduling, event logging and performance metrics as well as auto-tuning utilities.

The controller operates on a MeasurementDeviceInterface transmitter and exposes a standard PID API through ControllerDeviceInterface.

Version:
$Id: $Id
Author:
ESOL
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version UID.
      See Also:
    • logger

      static org.apache.logging.log4j.Logger logger
      Logger object for class.
    • calcIdentifier

      protected UUID calcIdentifier
      Unique identifier of which solve/run call was last called successfully.
    • unit

      private String unit
    • transmitter

      private MeasurementDeviceInterface transmitter
    • controllerSetPoint

      private double controllerSetPoint
    • oldError

      private double oldError
    • oldoldError

      private double oldoldError
    • error

      private double error
    • response

      private double response
    • propConstant

      int propConstant
    • reverseActing

      private boolean reverseActing
    • Kp

      private double Kp
    • Ti

      private double Ti
    • Td

      private double Td
    • stepResponseTuningMethod

      private ControllerDeviceInterface.StepResponseTuningMethod stepResponseTuningMethod
    • TintValue

      private double TintValue
    • derivativeState

      private double derivativeState
    • derivativeFilterTime

      private double derivativeFilterTime
    • minResponse

      private double minResponse
    • maxResponse

      private double maxResponse
    • isActive

      boolean isActive
    • gainSchedule

      private NavigableMap<Double,double[]> gainSchedule
    • eventLog

      private List<ControllerEvent> eventLog
    • totalTime

      private double totalTime
    • integralAbsoluteError

      private double integralAbsoluteError
    • lastTimeOutsideBand

      private double lastTimeOutsideBand
    • settlingTolerance

      private double settlingTolerance
  • Constructor Details

    • ControllerDeviceBaseClass

      public ControllerDeviceBaseClass()

      Constructor for ControllerDeviceBaseClass.

    • ControllerDeviceBaseClass

      public ControllerDeviceBaseClass(String name)

      Constructor for ControllerDeviceBaseClass.

      Parameters:
      name - Name of PID controller object
  • Method Details

    • setActive

      public void setActive(boolean isActive)

      setActive.

      Set if controller is active
      Specified by:
      setActive in interface ControllerDeviceInterface
      Parameters:
      isActive - Set true to make controller active.
    • isActive

      public boolean isActive()

      isActive.

      Specifies if controller is active
      Specified by:
      isActive in interface ControllerDeviceInterface
      Returns:
      a boolean
    • setTransmitter

      public void setTransmitter(MeasurementDeviceInterface device)

      setTransmitter.

      Specified by:
      setTransmitter in interface ControllerDeviceInterface
      Parameters:
      device - a MeasurementDeviceInterface object
    • getMeasuredValue

      public double getMeasuredValue()

      getMeasuredValue.

      Specified by:
      getMeasuredValue in interface ControllerDeviceInterface
      Returns:
      a double
    • getMeasuredValue

      public double getMeasuredValue(String unit)

      getMeasuredValue.

      Specified by:
      getMeasuredValue in interface ControllerDeviceInterface
      Parameters:
      unit - a String object
      Returns:
      a double
    • runTransient

      public void runTransient(double initResponse, double dt, UUID id)

      runTransient.

      Calculates controller output. Sets calc identifier UUID.

      If no engineering unit is configured, the controller falls back to the legacy percent-based error formulation used by earlier NeqSim versions.

      Specified by:
      runTransient in interface ControllerDeviceInterface
      Parameters:
      initResponse - Init value for response calculation
      dt - Delta time [s]
      id - Calculation identifier
    • setControllerSetPoint

      public void setControllerSetPoint(double signal)

      setControllerSetPoint.

      Specified by:
      setControllerSetPoint in interface ControllerDeviceInterface
      Parameters:
      signal - a double
    • setControllerSetPoint

      public void setControllerSetPoint(double signal, String unit)

      setControllerSetPoint.

      Specified by:
      setControllerSetPoint in interface ControllerDeviceInterface
      Parameters:
      signal - a double
      unit - a String object
    • getControllerSetPoint

      public double getControllerSetPoint()

      getControllerSetPoint.

      Specified by:
      getControllerSetPoint in interface ControllerDeviceInterface
      Returns:
      current controller set point
    • getUnit

      public String getUnit()

      getUnit.

      Specified by:
      getUnit in interface ControllerDeviceInterface
      Returns:
      a String object
    • setUnit

      public void setUnit(String unit)

      setUnit.

      Specified by:
      setUnit in interface ControllerDeviceInterface
      Parameters:
      unit - a String object
    • getResponse

      public double getResponse()

      getResponse.

      Specified by:
      getResponse in interface ControllerDeviceInterface
      Returns:
      a double
    • isReverseActing

      public boolean isReverseActing()

      isReverseActing.

      Specified by:
      isReverseActing in interface ControllerDeviceInterface
      Returns:
      a boolean
    • setReverseActing

      public void setReverseActing(boolean reverseActing)

      setReverseActing.

      Specified by:
      setReverseActing in interface ControllerDeviceInterface
      Parameters:
      reverseActing - a boolean
    • setOutputLimits

      public void setOutputLimits(double min, double max)

      Set minimum and maximum controller output for anti-windup handling.

      Set minimum and maximum controller output for anti-windup handling.

      Specified by:
      setOutputLimits in interface ControllerDeviceInterface
      Parameters:
      min - Minimum controller response
      max - Maximum controller response
    • setDerivativeFilterTime

      public void setDerivativeFilterTime(double timeConstant)

      Set derivative filter time constant. Set to zero to disable filtering.

      Set derivative filter time constant. Set to zero to disable filtering.

      Specified by:
      setDerivativeFilterTime in interface ControllerDeviceInterface
      Parameters:
      timeConstant - Filter time constant in seconds
    • getKp

      public double getKp()

      Get proportional gain of PID controller.

      Returns:
      Proportional gain of PID controller
    • setKp

      public void setKp(double Kp)

      Set proportional gain of PID controller.

      Parameters:
      Kp - Proportional gain of PID controller
    • setControllerParameters

      public void setControllerParameters(double Kp, double Ti, double Td)

      Set PID tuning parameters.

      Specified by:
      setControllerParameters in interface ControllerDeviceInterface
      Parameters:
      Kp - Proportional gain
      Ti - Integral time in seconds
      Td - Derivative time in seconds
    • getTi

      public double getTi()

      Get integral time of PID controller.

      Returns:
      Integral time in seconds
    • setTi

      public void setTi(double Ti)

      Set integral time of PID controller.

      Parameters:
      Ti - Integral time in seconds
    • getTd

      public double getTd()

      Get derivative time of PID controller.

      Returns:
      Derivative time of controller
    • setTd

      public void setTd(double Td)

      Set derivative time of PID controller.

      Parameters:
      Td - Derivative time in seconds
    • setStepResponseTuningMethod

      public void setStepResponseTuningMethod(ControllerDeviceInterface.StepResponseTuningMethod method)
      Description copied from interface: ControllerDeviceInterface

      Select the tuning correlations that should be used when calling one of the step response auto-tuning helpers.

      Specified by:
      setStepResponseTuningMethod in interface ControllerDeviceInterface
      Parameters:
      method - tuning rule to use
    • getStepResponseTuningMethod

      public ControllerDeviceInterface.StepResponseTuningMethod getStepResponseTuningMethod()
      Description copied from interface: ControllerDeviceInterface

      Retrieve the currently selected step-response tuning correlations.

      Specified by:
      getStepResponseTuningMethod in interface ControllerDeviceInterface
      Returns:
      the active tuning method
    • autoTune

      public void autoTune(double ultimateGain, double ultimatePeriod)

      Auto tune controller using ultimate gain and period from a closed-loop test.

      Specified by:
      autoTune in interface ControllerDeviceInterface
      Parameters:
      ultimateGain - Ultimate gain where oscillations start
      ultimatePeriod - Ultimate period of sustained oscillations [s]
    • autoTune

      public void autoTune(double ultimateGain, double ultimatePeriod, boolean tuneDerivative)

      Auto tune controller using ultimate gain and period from a closed-loop test with optional derivative tuning.

      Specified by:
      autoTune in interface ControllerDeviceInterface
      Parameters:
      ultimateGain - Ultimate gain where oscillations start
      ultimatePeriod - Ultimate period of sustained oscillations [s]
      tuneDerivative - true to tune derivative action, false to tune PI only
    • autoTuneStepResponse

      public void autoTuneStepResponse(double processGain, double timeConstant, double deadTime)

      Auto tune controller from an open-loop step response using process gain, time constant and dead time.

      Specified by:
      autoTuneStepResponse in interface ControllerDeviceInterface
      Parameters:
      processGain - Process gain from step response
      timeConstant - Process time constant [s]
      deadTime - Process dead time [s]
    • autoTuneStepResponse

      public void autoTuneStepResponse(double processGain, double timeConstant, double deadTime, boolean tuneDerivative)

      Auto tune controller from an open-loop step response using process gain, time constant and dead time with optional derivative tuning.

      Specified by:
      autoTuneStepResponse in interface ControllerDeviceInterface
      Parameters:
      processGain - Process gain from step response
      timeConstant - Process time constant [s]
      deadTime - Process dead time [s]
      tuneDerivative - true to tune derivative action, false to tune PI only
    • autoTuneFromEventLog

      public boolean autoTuneFromEventLog()

      Automatically tune the controller parameters using the recorded controller event log. The implementation typically analyses a previously executed step test and estimates the process dynamics before calculating PID settings.

      Specified by:
      autoTuneFromEventLog in interface ControllerDeviceInterface
      Returns:
      true if tuning succeeded, otherwise false
    • autoTuneFromEventLog

      public boolean autoTuneFromEventLog(boolean tuneDerivative)

      Automatically tune the controller parameters using the recorded controller event log with the option to omit derivative tuning.

      Specified by:
      autoTuneFromEventLog in interface ControllerDeviceInterface
      Parameters:
      tuneDerivative - true to tune derivative action, false to tune PI only
      Returns:
      true if tuning succeeded, otherwise false
    • addGainSchedulePoint

      public void addGainSchedulePoint(double processValue, double Kp, double Ti, double Td)

      Add a gain schedule point that switches controller parameters when the measured value exceeds the specified threshold.

      Specified by:
      addGainSchedulePoint in interface ControllerDeviceInterface
      Parameters:
      processValue - Measurement threshold for parameter set
      Kp - Proportional gain at this operating point
      Ti - Integral time [s] at this operating point
      Td - Derivative time [s] at this operating point
    • getEventLog

      public List<ControllerEvent> getEventLog()

      Retrieve the controller event log.

      Specified by:
      getEventLog in interface ControllerDeviceInterface
      Returns:
      list of controller events
    • resetEventLog

      public void resetEventLog()

      Reset the controller event log.

      Specified by:
      resetEventLog in interface ControllerDeviceInterface
    • getIntegralAbsoluteError

      public double getIntegralAbsoluteError()

      Get the integral of absolute error accumulated during the simulation.

      Specified by:
      getIntegralAbsoluteError in interface ControllerDeviceInterface
      Returns:
      integral of absolute error
    • getSettlingTime

      public double getSettlingTime()

      Get the settling time computed from the event log.

      Specified by:
      getSettlingTime in interface ControllerDeviceInterface
      Returns:
      settling time in seconds
    • resetPerformanceMetrics

      public void resetPerformanceMetrics()

      Reset accumulated performance metrics.

      Specified by:
      resetPerformanceMetrics in interface ControllerDeviceInterface
    • applyGainSchedule

      private void applyGainSchedule(double measurement)
      Apply gain-scheduled controller parameters based on the current measurement value. The schedule selects the parameter set with the highest threshold not exceeding the measurement.
      Parameters:
      measurement - current process value
    • averageOfLast

      private double averageOfLast(int count, ToDoubleFunction<ControllerEvent> extractor)
      Calculate the average value of the ControllerEvent properties for the last entries in the event log.
      Parameters:
      count - number of samples to include in the average
      extractor - function returning the value to average from the event
      Returns:
      average of the selected event property