1 | /* Class ClosedLoop
|
---|
2 | *
|
---|
3 | * This class supports the creation of a path of Black Boxes
|
---|
4 | * i.e. of instances of BlackBox and of any of its subclasses,
|
---|
5 | * e.g. PropIntDeriv, FirstOrder, and the methods to combine
|
---|
6 | * these into both a single instance of BlackBox and a Vector
|
---|
7 | * of analogue segments, digital segments and converters,
|
---|
8 | * with a feedback path from the last box on the forward path to the first box on the forward path
|
---|
9 | *
|
---|
10 | * Author: Michael Thomas Flanagan.
|
---|
11 | *
|
---|
12 | * Created: August 2002
|
---|
13 | * Updated: 14 May 2005, 6 April 2008, 5 July 2008, 2-7 November 2009
|
---|
14 | *
|
---|
15 | * DOCUMENTATION:
|
---|
16 | * See Michael T Flanagan's JAVA library on-line web page:
|
---|
17 | * http://www.ee.ucl.ac.uk/~mflanaga/java/OpenLoop.html
|
---|
18 | * http://www.ee.ucl.ac.uk/~mflanaga/java/
|
---|
19 | *
|
---|
20 | *
|
---|
21 | * Copyright (c) 2002 - 2008 Michael Thomas Flanagan
|
---|
22 | *
|
---|
23 | * PERMISSION TO COPY:
|
---|
24 | * Permission to use, copy and modify this software and its documentation for
|
---|
25 | * NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
|
---|
26 | * to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies.
|
---|
27 | *
|
---|
28 | * Dr Michael Thomas Flanagan makes no representations about the suitability
|
---|
29 | * or fitness of the software for any or for a particular purpose.
|
---|
30 | * Michael Thomas Flanagan shall not be liable for any damages suffered
|
---|
31 | * as a result of using, modifying or distributing this software or its derivatives.
|
---|
32 | *
|
---|
33 | ***************************************************************************************/
|
---|
34 |
|
---|
35 | package agents.anac.y2015.agentBuyogV2.flanagan.control;
|
---|
36 |
|
---|
37 | import java.util.Vector;
|
---|
38 |
|
---|
39 | import agents.anac.y2015.agentBuyogV2.flanagan.complex.Complex;
|
---|
40 | import agents.anac.y2015.agentBuyogV2.flanagan.complex.ComplexPoly;
|
---|
41 | import agents.anac.y2015.agentBuyogV2.flanagan.control.OpenLoop;
|
---|
42 |
|
---|
43 | import java.util.ArrayList;
|
---|
44 |
|
---|
45 | public class ClosedLoop extends BlackBox{
|
---|
46 | private OpenLoop forwardPath = new OpenLoop(); // forward path boxes
|
---|
47 | private OpenLoop closedPath = new OpenLoop(); // full closed path boxes
|
---|
48 |
|
---|
49 | private ArrayList<BlackBox> feedbackPath = new ArrayList<BlackBox>(); // feedback path boxes
|
---|
50 | private int nFeedbackBoxes = 0; // number of boxes in feedback path
|
---|
51 |
|
---|
52 | private boolean checkNoMix = true; // true - no ADC or DAC
|
---|
53 | private boolean checkConsolidate = false; // true if consolidate has been called
|
---|
54 |
|
---|
55 | private double deadTimeSum = 0.0; // dead time is replaced by Pade approximation to facilitate division
|
---|
56 | // sNumer and sDenom equated to sNumerPade and sDenomPade
|
---|
57 | // super.deadTime is replaced by zero
|
---|
58 | // true dead time stored in deadTimeSum which is returned by this classes getDeadTime method
|
---|
59 |
|
---|
60 | // Constructor
|
---|
61 | public ClosedLoop(){
|
---|
62 | super("ClosedLoop");
|
---|
63 | }
|
---|
64 |
|
---|
65 | // Add box to the forward path
|
---|
66 | public void addBoxToForwardPath(BlackBox box){
|
---|
67 | this.forwardPath.addBoxToPath(box);
|
---|
68 | }
|
---|
69 |
|
---|
70 | // Add box to the open path
|
---|
71 | public void addBoxToFeedbackPath(BlackBox box){
|
---|
72 | this.feedbackPath.add(box);
|
---|
73 | this.nFeedbackBoxes++;
|
---|
74 | }
|
---|
75 |
|
---|
76 | // Consolidate all boxes into appropriate segments and
|
---|
77 | // combine all boxes into either on forward path box or one closed loop box
|
---|
78 | public void consolidate(){
|
---|
79 |
|
---|
80 | // add feedback boxes to forward path boxes
|
---|
81 | this.closedPath = this.forwardPath.copy();
|
---|
82 | for(int i=0; i<this.nFeedbackBoxes; i++){
|
---|
83 | this.closedPath.addBoxToPath(this.feedbackPath.get(i));
|
---|
84 | }
|
---|
85 |
|
---|
86 | // combine forward path boxes
|
---|
87 | this.forwardPath.consolidate();
|
---|
88 | if(!this.forwardPath.getCheckNoMix())this.checkNoMix = false;
|
---|
89 |
|
---|
90 | // combine closed path boxes
|
---|
91 | this.closedPath.consolidate();
|
---|
92 | if(!this.closedPath.getCheckNoMix())this.checkNoMix = false;
|
---|
93 |
|
---|
94 | // Calculate transfer function
|
---|
95 | ComplexPoly fpNumer = this.forwardPath.getSnumer();
|
---|
96 | ComplexPoly fpDenom = this.forwardPath.getSdenom();
|
---|
97 | ComplexPoly cpNumer = this.closedPath.getSnumer();
|
---|
98 | ComplexPoly cpDenom = this.closedPath.getSdenom();
|
---|
99 | if(fpDenom.isEqual(cpDenom)){
|
---|
100 | super.setSnumer(fpNumer.copy());
|
---|
101 | super.setSdenom((cpNumer.plus(fpDenom)).copy());
|
---|
102 | }
|
---|
103 | else{
|
---|
104 | super.setSnumer(fpNumer.times(cpDenom));
|
---|
105 | super.setSdenom((cpNumer.times(fpDenom)).plus(cpDenom.times(fpDenom)));
|
---|
106 | }
|
---|
107 | this.checkConsolidate = true;
|
---|
108 | this.deadTimeSum = this.closedPath.getDeadTime();
|
---|
109 | super.deadTime = 0.0;
|
---|
110 | this.checkConsolidate = true;
|
---|
111 | }
|
---|
112 |
|
---|
113 | // Return number of boxes in the forward path
|
---|
114 | public int getNumberOfBoxesInForwardPath(){
|
---|
115 | if(!checkConsolidate)this.consolidate();
|
---|
116 | return this.forwardPath.getNumberOfBoxes();
|
---|
117 | }
|
---|
118 |
|
---|
119 | // Return number of boxes in the closed path
|
---|
120 | public int getNumberOfBoxesInClosedLoop(){
|
---|
121 | if(!checkConsolidate)this.consolidate();
|
---|
122 | return this.closedPath.getNumberOfBoxes();
|
---|
123 | }
|
---|
124 |
|
---|
125 | // Return segment ArrayList for forward path
|
---|
126 | public ArrayList<Object> getForwardPathSegmentsArrayList(){
|
---|
127 | if(!checkConsolidate)this.consolidate();
|
---|
128 | return this.forwardPath.getSegmentsArrayList();
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Return segment Vector for forward path
|
---|
132 | public Vector<Object> getForwardPathSegmentsVector(){
|
---|
133 | if(!checkConsolidate)this.consolidate();
|
---|
134 | return this.forwardPath.getSegmentsVector();
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | // Return segment ArrayList for closed path
|
---|
139 | public ArrayList<Object> getClosedLoopSegmentsArrayList(){
|
---|
140 | if(!checkConsolidate)this.consolidate();
|
---|
141 | return this.closedPath.getSegmentsArrayList();
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Return segment Vector for closed path
|
---|
145 | public Vector<Object> getClosedLoopSegmentsVector(){
|
---|
146 | if(!checkConsolidate)this.consolidate();
|
---|
147 | return this.closedPath.getSegmentsVector();
|
---|
148 | }
|
---|
149 |
|
---|
150 | // Return number of segments in the forward path
|
---|
151 | public int getNumberOfSegmentsInForwardPath(){
|
---|
152 | if(!checkConsolidate)this.consolidate();
|
---|
153 | return this.forwardPath.getNumberOfSegments();
|
---|
154 | }
|
---|
155 |
|
---|
156 | // Return number of segments in the closed path
|
---|
157 | public int getNumberOfSegmentsInClosedLoop(){
|
---|
158 | if(!checkConsolidate)this.consolidate();
|
---|
159 | return this.closedPath.getNumberOfSegments();
|
---|
160 | }
|
---|
161 |
|
---|
162 | // Return name of all boxes in forward path
|
---|
163 | public String getNamesOfBoxesInForwardPath(){
|
---|
164 | if(!checkConsolidate)this.consolidate();
|
---|
165 | return this.forwardPath.getNamesOfBoxes();
|
---|
166 | }
|
---|
167 |
|
---|
168 | // Return name of all boxes in closed path
|
---|
169 | public String getNamesOfBoxesInClosedLoop(){
|
---|
170 | if(!checkConsolidate)this.consolidate();
|
---|
171 | return this.closedPath.getNamesOfBoxes();
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Remove all boxes from the path
|
---|
175 | public void removeAllBoxes(){
|
---|
176 | this.forwardPath.removeAllBoxes();
|
---|
177 | this.closedPath.removeAllBoxes();
|
---|
178 | this.feedbackPath.clear();
|
---|
179 | this.checkNoMix = true;
|
---|
180 | this.checkConsolidate = false;
|
---|
181 | this.nFeedbackBoxes = 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | // Get stored dead times
|
---|
185 | public double getDeadTime(){
|
---|
186 | return this.deadTimeSum;
|
---|
187 | }
|
---|
188 |
|
---|
189 | // Deep copy
|
---|
190 | // Deep copy
|
---|
191 | public ClosedLoop copy(){
|
---|
192 | if(this==null){
|
---|
193 | return null;
|
---|
194 | }
|
---|
195 | else{
|
---|
196 | ClosedLoop bb = new ClosedLoop();
|
---|
197 | this.copyBBvariables(bb);
|
---|
198 |
|
---|
199 | bb.nFeedbackBoxes = this.nFeedbackBoxes;
|
---|
200 | bb.checkNoMix = this.checkNoMix;
|
---|
201 | bb.checkConsolidate = this.checkConsolidate;
|
---|
202 | bb.forwardPath = this.forwardPath.copy();
|
---|
203 | bb.closedPath = this.closedPath.copy();
|
---|
204 | bb.feedbackPath = new ArrayList<BlackBox>();
|
---|
205 | if(this.feedbackPath.size()!=0){
|
---|
206 | for(int i=0; i<feedbackPath.size(); i++)bb.feedbackPath.add((this.feedbackPath.get(i)).copy());
|
---|
207 | }
|
---|
208 |
|
---|
209 | return bb;
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | // Clone - overrides Java.Object method clone
|
---|
214 | public Object clone(){
|
---|
215 | return (Object)this.copy();
|
---|
216 | }
|
---|
217 | } |
---|