source: src/main/java/agents/anac/y2015/agentBuyogV2/flanagan/control/HighPassPassive.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 6.2 KB
Line 
1/* Class HighPassPassive
2*
3* This class contains the constructor to create an instance of
4* a low pass filter:
5* V(out) = V(in)RCjomega/(1 +RCjomega)
6* and the methods needed to use this process in simulation
7* of control loops.
8*
9* This class is a subclass of the superclass BlackBox.
10*
11* Author: Michael Thomas Flanagan.
12*
13* Created: 21 May 2005
14* Updated: 2 July 2006, 6 April 2008, 2 December 2008, 2-7 November 2009
15*
16*
17* DOCUMENTATION:
18* See Michael T Flanagan's JAVA library on-line web page:
19* http://www.ee.ucl.ac.uk/~mflanaga/java/HighPassPassive.html
20* http://www.ee.ucl.ac.uk/~mflanaga/java/
21*
22* Copyright (c) 2005 - 2009 Michael Thomas Flanagan
23*
24* PERMISSION TO COPY:
25*
26* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is
27* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
28* and associated documentation or publications.
29*
30* Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice,
31* this list of conditions and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
32*
33* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
34* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission
35* from the Michael Thomas Flanagan:
36*
37* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
38* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
39* or its derivatives.
40*
41***************************************************************************************/
42
43package agents.anac.y2015.agentBuyogV2.flanagan.control;
44import agents.anac.y2015.agentBuyogV2.flanagan.complex.Complex;
45import agents.anac.y2015.agentBuyogV2.flanagan.complex.ComplexPoly;
46
47public class HighPassPassive extends BlackBox{
48
49 private double resistance = 0.0D; // Resistance value, R ohms
50 private double capacitance = 0.0D; // Capacitance value, C farads
51 private double timeConstant = 0.0D; // Time constant, RC seconds
52 private boolean setR = false; // = true when resistance set
53 private boolean setC = false; // = true when capacitance set
54
55 // Constructor
56 // Sets time constant and order to unity
57 public HighPassPassive(){
58 super("PassiveHighPass");
59 super.sZeros = Complex.oneDarray(1);
60 super.sPoles = Complex.oneDarray(1);
61 super.setSnumer(new ComplexPoly(0.0D, 1.0D));
62 super.setSdenom(new ComplexPoly(1.0D, 1.0D));
63 super.setZtransformMethod(1);
64 super.addDeadTimeExtras();
65 this.timeConstant = 1.0D;
66 }
67
68
69 public void setResistance(double res){
70 this.resistance = res;
71 this.timeConstant = res*this.capacitance;
72 this.calcPolesZerosS();
73 super.sNumer = ComplexPoly.rootsToPoly(this.sZeros);
74 for(int i=0; i<=super.sNumerDeg;i++)super.sNumer.resetCoeff(i, super.sNumer.coeffCopy(i).times(Math.pow(this.timeConstant, i)));
75 super.sDenom = ComplexPoly.rootsToPoly(this.sPoles);
76 super.addDeadTimeExtras();
77 this.setR = true;
78 }
79
80 public void setCapacitance(double cap){
81 this.capacitance = cap;
82 this.timeConstant = cap*this.resistance;
83 this.calcPolesZerosS();
84 super.sNumer = ComplexPoly.rootsToPoly(this.sZeros);
85 for(int i=0; i<=super.sNumerDeg;i++)super.sNumer.resetCoeff(i, super.sNumer.coeffCopy(i).times(Math.pow(this.timeConstant, i)));
86 super.sDenom = ComplexPoly.rootsToPoly(this.sPoles);
87 super.addDeadTimeExtras();
88 this.setC = true;
89 }
90
91 public void setTimeConstant(double tau){
92 this.timeConstant = tau;
93 this.calcPolesZerosS();
94 super.sNumer = ComplexPoly.rootsToPoly(this.sZeros);
95 for(int i=0; i<=super.sNumerDeg;i++)super.sNumer.resetCoeff(i, super.sNumer.coeffCopy(i).times(Math.pow(this.timeConstant, i)));
96 super.sDenom = ComplexPoly.rootsToPoly(this.sPoles);
97 super.addDeadTimeExtras();
98 }
99
100 public double getResistance(){
101 if(this.setR){
102 return this.resistance;
103 }
104 else{
105 System.out.println("Class; HighPassPassive, method: getResistance");
106 System.out.println("No resistance has been entered; zero returned");
107 return 0.0D;
108 }
109 }
110
111 public double getCapacitance(){
112 if(this.setC){
113 return this.capacitance;
114 }
115 else{
116 System.out.println("Class; HighPassPassive, method: getCapacitance");
117 System.out.println("No capacitance has been entered; zero returned");
118 return 0.0D;
119 }
120 }
121
122 public double getTimeConstant(){
123 return this.timeConstant;
124 }
125
126 // Calculate the zeros and poles in the s-domain
127 protected void calcPolesZerosS(){
128 super.sZeros[0].setReal(0.0D);
129 super.sPoles[0].setReal(-this.timeConstant);
130 super.sNumerScaleFactor = BlackBox.scaleFactor(super.sNumer, super.sZeros);
131 super.sDenomScaleFactor = BlackBox.scaleFactor(super.sDenom, super.sPoles);
132 }
133
134 // Deep copy
135 public HighPassPassive copy(){
136 if(this==null){
137 return null;
138 }
139 else{
140 HighPassPassive bb = new HighPassPassive();
141 this.copyBBvariables(bb);
142
143 bb.resistance = this.resistance;
144 bb.capacitance = this.capacitance;
145 bb.timeConstant = this.timeConstant;
146 bb.setR = this.setR;
147 bb.setC = this.setC;
148
149 return bb;
150 }
151 }
152
153 // Clone - overrides Java.Object method clone
154 public Object clone(){
155 return (Object)this.copy();
156 }
157}
Note: See TracBrowser for help on using the repository browser.