/* Class Transducer
*
* This class contains the constructor to create an instance of
* a Transducer with a time constant, tConst, and a gain, tGain
* and the methods needed to use this process in simulation
* of control loops.
*
* This class is a subclass of the superclass BlackBox.
*
* Author: Michael Thomas Flanagan.
*
* Created: October 2009
* Updates: 2-7 November 2009, 24 May 2010, 27 April 2012
*
*
* DOCUMENTATION:
* See Michael T Flanagan's JAVA library on-line web page:
* http://www.ee.ucl.ac.uk/~mflanaga/java/Transducer.html
* http://www.ee.ucl.ac.uk/~mflanaga/java/
*
* Copyright (c) 2002 - 2010 Michael Thomas Flanagan
*
* PERMISSION TO COPY:
*
* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
* and associated documentation or publications.
*
* Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions
* and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
*
* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
*
* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
* or its derivatives.
*
***************************************************************************************/
package flanagan.control;
import flanagan.complex.Complex;
import flanagan.complex.ComplexPoly;
import flanagan.plot.*;
public class Transducer extends BlackBox{
private double tGain = 1.0D; // transducer gain
private double tConst = 0.0D; // transducer time constant
private double aConst = 0.0D; // a constant in equivalent first order process
private double bConst = 1.0D; // b constant in equivalent first order process
private double cConst = 1.0D; // c constant in equivalent first order process
// Constructor
// gain set to 1; time constant set to 0
public Transducer(){
super("Transducer");
super.sPoles = Complex.oneDarray(1);
super.setSnumer(new ComplexPoly(1.0D));
super.setSdenom(new ComplexPoly(1.0D, 0.0D));
super.setZtransformMethod(1);
super.addDeadTimeExtras();
}
// Constructor
// within constants set from argument list
public Transducer(double tGain, double tConst){
super("Transducer");
this.tGain = tGain;
this.tConst = tConst;
this.aConst = tConst;
this.bConst = 1.0;
this.cConst = tGain;
super.sPoles = Complex.oneDarray(1);
super.setSnumer(new ComplexPoly(this.cConst));
super.setSdenom(new ComplexPoly(this.bConst, this.aConst));
super.setZtransformMethod(1);
super.addDeadTimeExtras();
}
// Constructor
// time constant set to zero
public Transducer(double tGain){
super("Transducer");
this.tGain = tGain;
this.tConst = 0.0;
this.aConst = 0.0;
this.bConst = 1.0;
this.cConst = tGain;
super.sPoles = Complex.oneDarray(1);
super.setSnumer(new ComplexPoly(this.cConst));
super.setSdenom(new ComplexPoly(this.bConst, this.aConst));
super.setZtransformMethod(1);
super.addDeadTimeExtras();
}
// Set coefficients
public void setCoeff(double ttGain, double tConstt){
if(this.aConst==0.0){
if(this.bConst==0.0){
this.aConst = tConstt;
this.bConst = 1.0;
}
else{
this.aConst = tConstt*this.bConst;
}
}
else{
if(this.bConst==0.0){
this.aConst = tConstt;
this.bConst = 1.0;
}
else{
this.aConst = this.aConst*tConstt/this.tConst;
}
}
this.tConst = tConstt;
if(this.cConst==0.0){
if(this.bConst==0.0){
this.cConst = ttGain;
this.bConst = 1.0;
}
else{
this.cConst = ttGain*this.bConst;
}
}
else{
if(this.bConst==0.0){
this.cConst = ttGain;
this.bConst = 1.0;
}
else{
this.cConst = this.cConst*ttGain/this.tConst;
}
}
this.tGain = ttGain;
super.sPoles = Complex.oneDarray(1);
super.setSnumer(new ComplexPoly(this.cConst));
super.setSdenom(new ComplexPoly(this.bConst, this.aConst));
this.calcPolesZerosS();
super.addDeadTimeExtras();
}
public void setTimeConstant(double tConstt){
if(this.aConst==0.0){
if(this.bConst==0.0){
this.aConst = tConstt;
this.bConst = 1.0;
}
else{
this.aConst = tConstt*this.bConst;
}
}
else{
if(this.bConst==0.0){
this.aConst = tConstt;
this.bConst = 1.0;
}
else{
this.aConst = this.aConst*tConstt/this.tConst;
}
}
this.tConst = tConstt;
super.sPoles = Complex.oneDarray(1);
super.setSnumer(new ComplexPoly(this.cConst));
super.setSdenom(new ComplexPoly(this.bConst, this.aConst));
this.calcPolesZerosS();
super.addDeadTimeExtras();
}
public void setGain(double ttGain){
if(this.cConst==0.0){
if(this.bConst==0.0){
this.cConst = ttGain;
this.bConst = 1.0;
}
else{
this.cConst = ttGain*this.bConst;
}
}
else{
if(this.bConst==0.0){
this.cConst = ttGain;
this.bConst = 1.0;
}
else{
this.cConst = this.cConst*ttGain/this.tGain;
}
}
this.tGain = ttGain;
super.sPoles = Complex.oneDarray(1);
super.setSnumer(new ComplexPoly(this.cConst));
super.setSdenom(new ComplexPoly(this.bConst, this.aConst));
this.calcPolesZerosS();
super.addDeadTimeExtras();
}
// Get coefficients
public double getGain(){
return this.tGain;
}
public double getTimeConstant(){
return this.tConst;
}
// Calculate the zeros and poles in the s-domain
protected void calcPolesZerosS(){
super.sPoles = Complex.oneDarray(1);
super.sPoles[0].setReal(-bConst/aConst);
super.sNumerScaleFactor = super.sNumer.coeffCopy(0);
super.sNumerScaleFactor = BlackBox.scaleFactor(super.sNumer, super.sPoles);
}
// Plots the time course for a step input
public void stepInput(double stepMag, double finalTime){
if(this.tConst==0.0){
// Calculate time course outputs
int n = 51; // number of points on plot
double incrT = finalTime/(double)(n-2); // plotting increment
double cdata[][] = new double [2][n]; // plotting array
cdata[0][0]=0.0D;
cdata[0][1]=0.0D;
for(int i=2; i
Ads help maintain this website.