1 | /* Class Prop
|
---|
2 | *
|
---|
3 | * This class contains the constructor to create an instance of
|
---|
4 | * a Proportional gain controller and the methods
|
---|
5 | * needed to use this controller in control loops in the time
|
---|
6 | * domain, Laplace transform s domain or the z-transform z domain.
|
---|
7 | *
|
---|
8 | * This class is a subclass of the superclass BlackBox.
|
---|
9 | *
|
---|
10 | * Author: Michael Thomas Flanagan.
|
---|
11 | *
|
---|
12 | * Created: August 2002
|
---|
13 | * Updated: 20 April 2003, 3 May 2005, July 2006, 6 April 2008, 30 October 2009, 7 November 2009
|
---|
14 | * 24 May 2010
|
---|
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/Prop.html
|
---|
20 | * http://www.ee.ucl.ac.uk/~mflanaga/java/
|
---|
21 | *
|
---|
22 | * Copyright (c) 2002 - 2010 Michael Thomas Flanagan
|
---|
23 | *
|
---|
24 | * PERMISSION TO COPY:
|
---|
25 | * Permission to use, copy and modify this software and its documentation for
|
---|
26 | * NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
|
---|
27 | * to the author, Michael Thomas Flanagan at www.ee.ac.uk/~mflanaga, appears in all copies.
|
---|
28 | *
|
---|
29 | * Dr Michael Thomas Flanagan makes no representations about the suitability
|
---|
30 | * or fitness of the software for any or for a particular purpose.
|
---|
31 | * Michael Thomas Flanagan shall not be liable for any damages suffered
|
---|
32 | * as a result of using, modifying or distributing this software or its derivatives.
|
---|
33 | *
|
---|
34 | ***************************************************************************************/
|
---|
35 |
|
---|
36 |
|
---|
37 | package agents.anac.y2015.agentBuyogV2.flanagan.control;
|
---|
38 | import agents.anac.y2015.agentBuyogV2.flanagan.complex.Complex;
|
---|
39 | import agents.anac.y2015.agentBuyogV2.flanagan.complex.ComplexPoly;
|
---|
40 | import agents.anac.y2015.agentBuyogV2.flanagan.plot.Plot;
|
---|
41 | import agents.anac.y2015.agentBuyogV2.flanagan.plot.PlotGraph;
|
---|
42 |
|
---|
43 | public class Prop extends BlackBox{
|
---|
44 | private double kp = 1.0D; // proportional gain
|
---|
45 |
|
---|
46 | // Constructor - unit proportional gain
|
---|
47 | public Prop(){
|
---|
48 | super("Prop");
|
---|
49 | super.setSnumer(new ComplexPoly(1.0D));
|
---|
50 | super.setSdenom(new ComplexPoly(1.0D));
|
---|
51 | super.setZtransformMethod(1);
|
---|
52 | super.addDeadTimeExtras();
|
---|
53 | super.sNumerScaleFactor = Complex.plusOne();
|
---|
54 | super.sDenomScaleFactor = Complex.plusOne();
|
---|
55 | }
|
---|
56 |
|
---|
57 | // Constructor - set P gain
|
---|
58 | public Prop(double kp){
|
---|
59 | super("Prop");
|
---|
60 | this.kp=kp;
|
---|
61 | super.setSnumer(new ComplexPoly(this.kp));
|
---|
62 | super.setSdenom(new ComplexPoly(1.0D));
|
---|
63 | super.setZtransformMethod(1);
|
---|
64 | super.addDeadTimeExtras();
|
---|
65 | super.sNumerScaleFactor = new Complex(kp, 0.0);
|
---|
66 | super.sDenomScaleFactor = Complex.plusOne();
|
---|
67 | }
|
---|
68 |
|
---|
69 | // Set the proportional gain
|
---|
70 | public void setKp(double kp){
|
---|
71 | this.kp=kp;
|
---|
72 | Complex num = new Complex(this.kp, 0.0D);
|
---|
73 | super.sNumer.resetCoeff(0, num);
|
---|
74 | super.addDeadTimeExtras();
|
---|
75 | super.sNumerScaleFactor = new Complex(kp, 0.0);
|
---|
76 | }
|
---|
77 |
|
---|
78 | // Get the proprtional gain
|
---|
79 | public double getKp(){
|
---|
80 | return this.kp;
|
---|
81 | }
|
---|
82 |
|
---|
83 | // Perform z transform using an already set delta T
|
---|
84 | public void zTransform(){
|
---|
85 | super.zNumerDeg = 0;
|
---|
86 | super.zDenomDeg = 0;
|
---|
87 | super.zNumer = new ComplexPoly(this.kp);
|
---|
88 | super.zDenom = new ComplexPoly(1.0D);
|
---|
89 | }
|
---|
90 |
|
---|
91 | // Perform z transform setting delta T
|
---|
92 | public void zTransform(double deltaT){
|
---|
93 | super.setDeltaT(deltaT);
|
---|
94 | this.zTransform();
|
---|
95 | }
|
---|
96 |
|
---|
97 | // Plots the time course for a step input
|
---|
98 | public void stepInput(double stepMag, double finalTime){
|
---|
99 |
|
---|
100 | // Calculate time course outputs
|
---|
101 | int n = 51; // number of points on plot
|
---|
102 | double incrT = finalTime/(double)(n-2); // plotting increment
|
---|
103 | double cdata[][] = new double [2][n]; // plotting array
|
---|
104 |
|
---|
105 | cdata[0][0]=0.0D;
|
---|
106 | cdata[0][1]=0.0D;
|
---|
107 | for(int i=2; i<n; i++){
|
---|
108 | cdata[0][i]=cdata[0][i-1]+incrT;
|
---|
109 | }
|
---|
110 | double kpterm = this.kp*stepMag;
|
---|
111 | cdata[1][0]=0.0D;
|
---|
112 | for(int i=1; i<n; i++){
|
---|
113 | cdata[1][i] = kpterm;
|
---|
114 | }
|
---|
115 | if(super.deadTime!=0.0D)for(int i=0; i<n; i++)cdata[0][i] += super.deadTime;
|
---|
116 |
|
---|
117 | // Plot
|
---|
118 | PlotGraph pg = new PlotGraph(cdata);
|
---|
119 |
|
---|
120 | pg.setGraphTitle("Step Input Transient: Step magnitude = "+stepMag);
|
---|
121 | pg.setGraphTitle2(this.getName());
|
---|
122 | pg.setXaxisLegend("Time");
|
---|
123 | pg.setXaxisUnitsName("s");
|
---|
124 | pg.setYaxisLegend("Output");
|
---|
125 | pg.setPoint(0);
|
---|
126 | pg.setLine(3);
|
---|
127 | pg.plot();
|
---|
128 | }
|
---|
129 |
|
---|
130 | // Plots the time course for a unit step input
|
---|
131 | public void stepInput(double finalTime){
|
---|
132 | this.stepInput(1.0D, finalTime);
|
---|
133 | }
|
---|
134 |
|
---|
135 | // Plots the time course for an nth order ramp input (at^n)
|
---|
136 | public void rampInput(double rampGradient, int rampOrder, double finalTime){
|
---|
137 |
|
---|
138 | if(rampOrder==0){
|
---|
139 | // Check if really a step input (rampOrder, n = 0)
|
---|
140 | this.stepInput(rampGradient, finalTime);
|
---|
141 | }
|
---|
142 | else{
|
---|
143 | // Calculate time course outputs
|
---|
144 | int n = 50; // number of points on plot
|
---|
145 | double incrT = finalTime/(double)(n-1); // plotting increment
|
---|
146 | double cdata[][] = new double [2][n]; // plotting array
|
---|
147 | double sum = 0.0D; // integration sum
|
---|
148 |
|
---|
149 | cdata[0][0]=0.0D;
|
---|
150 | cdata[1][0]=0.0D;
|
---|
151 | for(int i=1; i<n; i++){
|
---|
152 | cdata[0][i]=cdata[0][i-1]+incrT;
|
---|
153 | cdata[1][i] = rampGradient*Math.pow(cdata[0][i],rampOrder)*this.kp;
|
---|
154 | }
|
---|
155 | if(super.deadTime!=0.0D)for(int i=0; i<n; i++)cdata[0][i] += super.deadTime;
|
---|
156 |
|
---|
157 | // Plot
|
---|
158 | PlotGraph pg = new PlotGraph(cdata);
|
---|
159 |
|
---|
160 | pg.setGraphTitle("Ramp (a.t^n) Input Transient: ramp gradient (a) = "+rampGradient + " ramp order (n) = " + rampOrder);
|
---|
161 | pg.setGraphTitle2(this.getName());
|
---|
162 | pg.setXaxisLegend("Time");
|
---|
163 | pg.setXaxisUnitsName("s");
|
---|
164 | pg.setYaxisLegend("Output");
|
---|
165 | pg.setPoint(0);
|
---|
166 | pg.plot();
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Plots the time course for an nth order ramp input (t^n)
|
---|
171 | public void rampInput(int rampOrder, double finalTime){
|
---|
172 | double rampGradient = 1.0D;
|
---|
173 | this.rampInput(rampGradient, rampOrder, finalTime);
|
---|
174 | }
|
---|
175 |
|
---|
176 | // Plots the time course for a first order ramp input (at)
|
---|
177 | public void rampInput(double rampGradient, double finalTime){
|
---|
178 | int rampOrder = 1;
|
---|
179 | this.rampInput(rampGradient, rampOrder, finalTime);
|
---|
180 | }
|
---|
181 |
|
---|
182 | // Plots the time course for a unit ramp input (t)
|
---|
183 | public void rampInput(double finalTime){
|
---|
184 | double rampGradient = 1.0D;
|
---|
185 | int rampOrder = 1;
|
---|
186 | this.rampInput(rampGradient, rampOrder, finalTime);
|
---|
187 | }
|
---|
188 |
|
---|
189 | // Get the s-domain output for a given s-value and a given input.
|
---|
190 | public Complex getOutputS(Complex sValue, Complex iinput){
|
---|
191 | super.sValue=sValue;
|
---|
192 | super.inputS=iinput;
|
---|
193 | super.outputS=super.inputS.times(this.kp);
|
---|
194 | if(super.deadTime!=0.0D)super.outputS = super.outputS.times(Complex.exp(super.sValue.times(-super.deadTime)));
|
---|
195 | return super.outputS;
|
---|
196 | }
|
---|
197 |
|
---|
198 | // Get the s-domain output for the stored input and s-value.
|
---|
199 | public Complex getOutputS(){
|
---|
200 | super.outputS=super.inputS.times(this.kp);
|
---|
201 | if(super.deadTime!=0.0D)super.outputS = super.outputS.times(Complex.exp(super.sValue.times(-super.deadTime)));
|
---|
202 | return super.outputS;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | // Calculate the current time domain output for a given input and given time
|
---|
207 | // resets deltaT
|
---|
208 | public void calcOutputT(double ttime, double inp){
|
---|
209 | super.setInputT(ttime, inp);
|
---|
210 | this.calcOutputT();
|
---|
211 | }
|
---|
212 |
|
---|
213 | // Get the output for the stored sampled input and time.
|
---|
214 | public void calcOutputT(){
|
---|
215 | // proportional term
|
---|
216 | super.outputT[super.sampLen-1] = this.kp*super.inputT[super.sampLen-1];
|
---|
217 | }
|
---|
218 |
|
---|
219 | // Get the s-domain zeros
|
---|
220 | public Complex[] getZerosS(){
|
---|
221 | System.out.println("Proportional gain controller has no s-domain zeros");
|
---|
222 | return null;
|
---|
223 | }
|
---|
224 |
|
---|
225 | // Get the s-domain poles
|
---|
226 | public Complex[] getPolesS(){
|
---|
227 | System.out.println("Proportional gain controller has no s-domain poles");
|
---|
228 | return null;
|
---|
229 | }
|
---|
230 |
|
---|
231 | // Deep copy
|
---|
232 | public Prop copy(){
|
---|
233 | if(this==null){
|
---|
234 | return null;
|
---|
235 | }
|
---|
236 | else{
|
---|
237 | Prop bb = new Prop();
|
---|
238 | this.copyBBvariables(bb);
|
---|
239 |
|
---|
240 | bb.kp = this.kp;
|
---|
241 | return bb;
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | // Clone - overrides Java.Object method clone
|
---|
246 | public Object clone(){
|
---|
247 | return (Object)this.copy();
|
---|
248 | }
|
---|
249 | } |
---|