stella.util
Class SineError

java.lang.Object
  extended by stella.util.SineError
All Implemented Interfaces:
Multidimensional

public class SineError
extends Object
implements Multidimensional

A class that models a time-dependend shift according to an overlay of sine functions. A PID is then used to correct for this shift, and as a test, the difference between the PID response and the true function is feed into the PID. For optimal performance, the frequencies should be plain integers.
To allow optimization of the PID with a simplex algorithm, this class also implements the Multidimensional interface that returns a measure of the goodness-of-leveling of the PID.


Nested Class Summary
static class SineError.Parse
          A command-line frontend to the sine-error class.
private static class SineError.Relaxation
          A class that simulates the reaction of the system to an offset.
 
Field Summary
static int ABSOLUTESUM
          The indicator for absoulte error-sum quality measure.
private  double[] amplitude
          The coefficients of the input function, amplitude.
private  double deadtime
          The deadtime until the system starts reacting, in PID-t units.
private  double[] frequency
          The coefficients of the input function, frequency.
private  double lag
          Latency until the system has reached the new output, in PID units.
private  int maxrelevant
          The maximum number of offsets allowed.
private  double noise
          The coefficient for thw gaussian noise.
private static double OVERREACT
          If the PID starts to oscilate, the correction will be higher as.
private  double[] phase
          The coefficients of the input function, phase.
private  PIDControl pid
          The PIDController handling the error function.
private  double pidfreq
          The frequency at which the PID is queried.
private  boolean pionly
          If true, only optimize PI parameters, keep D fixed.
private  int qualitymeasure
          The quality measure, 0-3.
private  int relaxfreq
          The period at which offsets are generated in PID-periods.
private static int RESOLUTION
          The number of steps skipped for error determination.
static int SQUARESUM
          The indicator for error square-sum quality measure.
static int TABSOLUTESUM
          The indicator for absolute error times t sum quality measure.
private static double TINY
          A small number to prevent division-by-zero in oscillating test.
static int TSQUARESUM
          The indicator for error squared times t sum quality measure.
private  Random white
          The random number generator.
 
Constructor Summary
SineError(double[] a, double[] f, double[] phi)
          Constructs a new sine error function specifiying the coefficients of the error function.
SineError(double[] a, double[] f, double[] phi, double random)
          Constructs a new sine error function specifiying the coefficients of the error function.
 
Method Summary
 int dimension()
          Return three for the three PID parameters.
 double evaluate(VectorG pidvals)
          Evaluate the PID.
 double getErrorFunction(double t)
          Calculates the error function at the given time.
 double getMinimumFrequency()
          Returns the time step of the simulation.
 double runPID(PrintWriter out)
          Runs an entire loop using the specified PID and the underlying error function.
 void setDelay(double newdeadtime)
          Sets the deadtime time.
 void setLatencySpeed(double newlag)
          Sets the lag time.
 void setMaxRelaxations(int relaxcount)
          Sets the number of maximal concurrent active relaxation processes.
 void setPID(PIDControl handle)
          Sets the PIDControler that should level the error function.
 void setPIDFrequency(double f)
          Sets the PID frequency.
 void setPIOnly(boolean onlypi)
          Sets the desired optimization strategy.
 void setQualityMeasure(int newqual)
          Sets the quality measurement.
 void setRelaxationPeriod(int relaxperiod)
          Set the frequency of the PID corrections as a multiple of the PID internal period.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SQUARESUM

public static final int SQUARESUM
The indicator for error square-sum quality measure.

See Also:
Constant Field Values

ABSOLUTESUM

public static final int ABSOLUTESUM
The indicator for absoulte error-sum quality measure.

See Also:
Constant Field Values

TSQUARESUM

public static final int TSQUARESUM
The indicator for error squared times t sum quality measure.

See Also:
Constant Field Values

TABSOLUTESUM

public static final int TABSOLUTESUM
The indicator for absolute error times t sum quality measure.

See Also:
Constant Field Values

amplitude

private double[] amplitude
The coefficients of the input function, amplitude.


frequency

private double[] frequency
The coefficients of the input function, frequency.


phase

private double[] phase
The coefficients of the input function, phase.


noise

private double noise
The coefficient for thw gaussian noise.


white

private Random white
The random number generator.


pid

private PIDControl pid
The PIDController handling the error function.


pidfreq

private double pidfreq
The frequency at which the PID is queried.


relaxfreq

private int relaxfreq
The period at which offsets are generated in PID-periods.


maxrelevant

private int maxrelevant
The maximum number of offsets allowed.


deadtime

private double deadtime
The deadtime until the system starts reacting, in PID-t units.


lag

private double lag
Latency until the system has reached the new output, in PID units.


qualitymeasure

private int qualitymeasure
The quality measure, 0-3.


pionly

private boolean pionly
If true, only optimize PI parameters, keep D fixed.


RESOLUTION

private static final int RESOLUTION
The number of steps skipped for error determination.

See Also:
Constant Field Values

OVERREACT

private static final double OVERREACT
If the PID starts to oscilate, the correction will be higher as.

See Also:
Constant Field Values

TINY

private static final double TINY
A small number to prevent division-by-zero in oscillating test.

See Also:
Constant Field Values
Constructor Detail

SineError

public SineError(double[] a,
                 double[] f,
                 double[] phi)
Constructs a new sine error function specifiying the coefficients of the error function. No white noise.


SineError

public SineError(double[] a,
                 double[] f,
                 double[] phi,
                 double random)
Constructs a new sine error function specifiying the coefficients of the error function. White noise is added.

Method Detail

setPID

public void setPID(PIDControl handle)
Sets the PIDControler that should level the error function.


setPIDFrequency

public void setPIDFrequency(double f)
Sets the PID frequency.


setMaxRelaxations

public void setMaxRelaxations(int relaxcount)
Sets the number of maximal concurrent active relaxation processes.


setRelaxationPeriod

public void setRelaxationPeriod(int relaxperiod)
Set the frequency of the PID corrections as a multiple of the PID internal period. If set to e.g. 5, only every fifth PID-loop will add an offset process.


setQualityMeasure

public void setQualityMeasure(int newqual)
Sets the quality measurement. Defines how the quality of the PID is measured. The values allowed are: All of the quality measurements are obtained only after the intial transient response, defined by the number of steps given in #RESPONSE.


setDelay

public void setDelay(double newdeadtime)
Sets the deadtime time. This is the time it takes the system to start reacting to a new signal. The time unit is the inverse of the PID frequency.


setLatencySpeed

public void setLatencySpeed(double newlag)
Sets the lag time. This is the time it takes the system to fully adjust to the new output value. The time unit is the inverse of the PID frequency.


setPIOnly

public void setPIOnly(boolean onlypi)
Sets the desired optimization strategy. If true, only P and I are changed.


getErrorFunction

public double getErrorFunction(double t)
Calculates the error function at the given time. The function is evaluated as
       f = Σiaiċsin(2πfi*t+φi
       


getMinimumFrequency

public double getMinimumFrequency()
Returns the time step of the simulation. This is the time that has to be used to produce a repetition in the error-function after t=1. Calculated correctly only if the frequencies are plain integers.


runPID

public double runPID(PrintWriter out)
Runs an entire loop using the specified PID and the underlying error function. If the PrintWriter supplied is not null, the result of each step are writtn within, The procedure is as follows.


dimension

public int dimension()
Return three for the three PID parameters.

Specified by:
dimension in interface Multidimensional

evaluate

public double evaluate(VectorG pidvals)
Evaluate the PID. This runs the PID and returns the offset. This offset, in turn, should be minimized. The parameters in the vector argument are interpreted as the proportional, integral, and differential parameter of the PID, in this order.

Specified by:
evaluate in interface Multidimensional