hio_4_transport_unit.cpp
Go to the documentation of this file.
1 /** @file hio_4_transport_unit.cpp
2 
3 Tutorial, transport chain example for hiosys plugin.
4 
5 @ingroup Tutorials
6 
7 @include hio_4_transport_unit.cpp
8 
9 */
10 
11 #include "libfaudes.h"
12 
13 // make the faudes namespace available to our program
14 using namespace faudes;
15 using namespace std;
16 
17 /** Transport chain example to demonstrate hierarchical I/O controller synthesis */
19 
20 /*
21  This tutorial treats controller synthesis for a chain of an exemplary number of 8 transport units
22  (TU's) that shall transport a workpiece from the left to the right.
23  The hierarchy can be extended to an arbitrary number of TU's, with
24  linear growth of complexity, measured in the sum of states of all involved generators.
25  By allowing for only one workpiece at a time, the example is kept at a simple tutorial level
26  such that the involved generators remain readable in a graphical view.
27  However, linear complexity is still achieved in the case of parallel transport of as
28  many workpieces as physically possible, see the real-world conveyor belt chain example.
29 
30  The TU's are numbered
31  alphabetically from left to right. For each TU, an I/O plant model has to be provided as HioPlant.
32  Note that these plant model components, e.g. plantA and plantB, must not share events; the
33  membership of each event to the respective component is indicated by the suffixes _A and
34  _B in the event labels, e.g. idle_A and idle_B. First, each TU is provided with a local controller
35  using the synthesis function HioSynthMonolithic. For that, a specification has to be given as
36  HioPlant describing the desired external behaviour of the locally controlled TU.
37 
38  To design a control hierarchy,
39  we compound groups of two TU's, e.g. TU A and TU B. As the I/O based
40  approach allows for abstraction-based control, each locally controlled TU is abstracted by its
41  specification, so next the I/O shuffle of the specifications of two transport units is
42  computed. An environment model has to be provided as HioEnvironment that describes the
43  internal interaction of the two TU's within each other and the external interaction with the
44  remaining environment. With a given specification of the group's desired behaviour, the
45  function HioSynthHierarchical computes an I/O controller for the group. By specifying that
46  each group of TU's shall behave exactly as a single TU, we can derive all remaining controllers
47  of the hierarchy for 8 TU's by exploiting symmetry.
48 */
49 
50 //######################################################################
51  //*****
52  //***** controller synthesis for plantA:*****
53  //*****
54 //######################################################################
55 
56  /*
57  We consider a simple transport unit (TU), described as HioPlant
58  (data/4_transport_unit/4_transport_unit/plantA.gen).
59 
60  The TU consists of a conveyor belt carrying a box that can hold the workpiece to be transported.
61  A spring sensor inside the box detects the absence or presence of a workpiece (empty, full).
62  The initial state (state 1) is defined such that the sensor reports empty. The operator
63  can choose between three different commands (state 2). After the no_op (no operation)
64  command, the TU does not move, and the system remains in the initial state. The command
65  del_tr (deliver to right) leads to an error state as there is currently no workpiece present to deliver.
66  Choosing the command take_fl (take from left) prompts the TU to move the box to its
67  left border (state 3). Now it depends on the environment if a workpiece is provided from the
68  left, which is modeled by the event req_fl unobservable to the operator. For a plant description
69  that is independent from the environment, we introduce the environment-events pack and nack
70  (positive/negative acknowledge) respecting that the environment may or may not comply with the
71  requests of the plant. If the environment is not in the condition to provide a workpiece (nack),
72  the request is repeated. When a workpiece is provided from the environment, the sensor reports
73  full. Now (state 6), the command take_fl leads to an error behaviour (the box can carry only
74  one workpiece), and after no_op the plant still reports full. By the command del_tr, the belt
75  moves the box to the right border. The event req_tr models the need for the workpiece to be withdrawn
76  to the right by the environment. In case of pack, the system returns to its initial state.
77 
78  By (UP,YP) := ({no_op, take_fl, del_tr}, {empty, full}), we identify the interaction with the operator,
79  (UE,YE) := ({pack,nack}, {req_fl, req_tr}) describes interaction with the environment.
80  Note that (UP,YP,UE,YE,LPE) features all I/O-plant properties posed in the formal Definition.
81  */
82 
83  cout <<endl<< "******************** reading files..." << endl;
84 
85  //read plant, spec and constraints:
86 
87  HioPlant plantA("data/4_transport_unit/plantA.gen");
88  plantA.Write("tmp_hio_tu_plantA.gen");
89 
90  HioPlant specA("data/4_transport_unit/specA.gen");
91  specA.Write("tmp_hio_tu_spec_A.gen");
92 
93  HioConstraint constrE_A("data/4_transport_unit/constrE_A.gen");
94  constrE_A.Write("tmp_hio_tu_constrE_A.gen");
95 
96  HioConstraint constrP_A("data/4_transport_unit/constrP_A.gen");
97  constrP_A.Write("tmp_hio_tu_constrP_A.gen");
98 
99  // The operator constraint constrC of specification A is minimal.
100  // So, informally, it can be passed as an epsilon-language.
101  HioConstraint constrC_A;
102  constrC_A.InsInitState("1");
103  constrC_A.SetMarkedState("1");
104 
105  // compute I/O controller:
106 
107  HioController controllerA, controllerB;
108  HioSynthMonolithic(plantA, specA, constrC_A, constrP_A, constrE_A, controllerA);
109  controllerA.Write("tmp_hio_tu_IOcontroller_A.gen");
110 
111  // plantB, specB and consequently controllerB are identical
112  controllerA.Version("_A","_B",controllerB);
113  controllerB.Write("tmp_hio_tu_IOcontroller_B.gen");
114 
115  // inspect full and external closed loop
116  Generator full_loop,ext_loop;
117  Parallel(controllerA,plantA,full_loop);
118  full_loop.Write("tmp_hio_tu_full_loop_A.gen");
119  Project(full_loop,specA.Alphabet(),ext_loop);
120  ext_loop.Write("tmp_hio_tu_ext_loop_A.gen");
121 
122 //######################################################################
123  //*****
124  //***** plantAB: abstraction, I/O shuffle and environment.*****
125  //*****
126 //######################################################################
127 
128  // specA serves as abstraction of the closed loop of controllerA and plantA, and so does specB for controllerB and plantB
129  // read specB and corresp. environment constraint (op. constraint is minimal):
130  HioPlant specB("data/4_transport_unit/specB.gen");
131  HioConstraint constrE_B("data/4_transport_unit/constrE_B.gen");
132 
133  cout <<endl<< "******************** IOshuffle: tmp_hio_tu_shuffAB.gen/.png" << endl;
134 
135  HioPlant shuffAB;
136  HioShuffle(specA, specB, shuffAB);
137  //HioShuffleTU(spec, specB, yc + ycB, uc + ucB, ye + yeB, ue + ueB, 1, shuffABnotmin);
138  StateMin(shuffAB,shuffAB);
139  cout<<endl<<"(sizeof shuffAB after statemin: "<<shuffAB.Size()<<").."<<endl;
140  shuffAB.StateNamesEnabled(false);
141  shuffAB.Name("IO shuffle AB");
142  shuffAB.Write("tmp_hio_tu_shuffAB.gen");
143 
144 //read environment:
145 
146  HioEnvironment envAB("data/4_transport_unit/envAB.gen");
147  envAB.Write("tmp_hio_tu_envAB.gen");
148 
149 
150 //######################################################################
151  //*****
152  //***** controller synthesis for plantAB:*****
153  //*****
154 //######################################################################
155 
156 cout <<endl<<"********************"<<endl <<"******************** ready for Controller synthesis for plantAB"<< endl<<"********************"<<endl;
157 
158 //read specAB
159  HioPlant specAB("data/4_transport_unit/specAB.gen");
160  specAB.Write("tmp_hio_tu_specAB.gen");
161  // alternatively, the specification "specA_ARB_FEEDBACK.gen"
162  // can be used. It does not specify an "idle"-feedback
163  // after EACH wp transport, but after an ARBITRARY amount
164  // instead. The same result is achieved for controller A
165  // because of the Yc-Acyclic property. However, this spec
166  // cannot be used as plant abstraction, as there are no
167  // constraints w.r.t. which this plant model is YP-live.
168 
169  // The operator constraint constrC of specification AB is minimal.
170  // So, informally, it can be passed as an epsilon-language.
171  HioConstraint constrC_AB;
172  constrC_AB.InsInitState("1");
173  constrC_AB.SetMarkedState("1");
174 
175 
176 //read environment constraint of specification AB (op. constraint is minimal)
177  HioConstraint constrL_AB("data/4_transport_unit/constrL_AB.gen");
178  constrL_AB.Write("tmp_hio_tu_constrL_AB.gen");
179 
180 // local constraints: composition of env. constraints for spec. A and spec B (op. constraints for both are minimal)
181  Generator locConstrAB;
182  Parallel(constrE_A,constrE_B,locConstrAB);
183 
184 //calculate IO controller for plantAB
185  HioController controllerAB;
186  HioSynthHierarchical(shuffAB, envAB, specAB, locConstrAB, constrC_AB, constrL_AB, controllerAB);
187 
188 // marking does not count in controller
189  PrefixClosure(controllerAB);
190  StateMin(controllerAB,controllerAB);
191  controllerAB.StateNamesEnabled(false);
192  controllerAB.Name("Controller AB");
193  controllerAB.Write("tmp_hio_tu_IOcontrollerAB.gen");
194  cout<<endl<<">>>>> Synthesis done for Controller AB. <<<<<"<<endl;
195  controllerAB.SWrite();
196 
197 // Again, we specify the same behaviour for plants C and D to receive a structurally
198 // identical controller CD.
199 // Moreover, specification (ie abstract plant model) AB is structurally identical to specA and specB.
200 // Hence, the controller ABCD for spec (abstract plant model) AB and CD is structurally identical to
201 // controller AB or CD ! The same holds for environment ABCD, which is derived directly from
202 // environment AB.
203 
204 //######################################################################
205  //*****
206  //***** remaining plant- and controller hierarchy *****
207  //*****
208 //######################################################################
209 
210 // we derive all remaining components of the hierarchy by creating versions of the previous components.
211 
212  HioPlant plantX;
213 
214  plantA.Version("_A","_B",plantX);
215  plantX.Write("tmp_hio_tu_plantB.gen");
216  plantA.Version("_A","_C",plantX);
217  plantX.Write("tmp_hio_tu_plantC.gen");
218  plantA.Version("_A","_D",plantX);
219  plantX.Write("tmp_hio_tu_plantD.gen");
220  plantA.Version("_A","_E",plantX);
221  plantX.Write("tmp_hio_tu_plantE.gen");
222  plantA.Version("_A","_F",plantX);
223  plantX.Write("tmp_hio_tu_plantF.gen");
224  plantA.Version("_A","_G",plantX);
225  plantX.Write("tmp_hio_tu_plantG.gen");
226  plantA.Version("_A","_H",plantX);
227  plantX.Write("tmp_hio_tu_plantH.gen");
228 
229  HioEnvironment envXtmp,envX;
230 
231  envAB.Version("_AB","_CD",envX);
232  envX.Version("_A","_C",envXtmp);
233  envXtmp.Version("_B","_D",envX);
234  envX.Write("tmp_hio_tu_IOenvironmentCD.gen");
235 
236  envAB.Version("_AB","_EF",envX);
237  envX.Version("_A","_E",envXtmp);
238  envXtmp.Version("_B","_F",envX);
239  envX.Write("tmp_hio_tu_IOenvironmentEF.gen");
240 
241  envAB.Version("_AB","_aBCD",envX);
242  envX.Version("_A","_AB",envXtmp);
243  envXtmp.Version("_B","_CD",envX);
244  envX.Version("_aBCD","_ABCD",envXtmp);
245  envXtmp.Write("tmp_hio_tu_IOenvironmentABCD.gen");
246 
247  envAB.Version("_AB","_EFGH",envX);
248  envX.Version("_A","_EF",envXtmp);
249  envXtmp.Version("_B","_GH",envX);
250  envX.Write("tmp_hio_tu_IOenvironmentEFGH.gen");
251 
252  envAB.Version("_AB","_a_H",envX);
253  envX.Version("_A","_ABCD",envXtmp);
254  envXtmp.Version("_B","_EFGH",envX);
255  envX.Version("_a_H","_A_H",envXtmp);
256  envXtmp.Write("tmp_hio_tu_IOenvironmentA_H.gen");
257 
258  HioController controllerX,controllerXtmp;
259 
260  controllerAB.Version("_AB","_CD",controllerX);
261  controllerX.Version("_A","_C",controllerXtmp);
262  controllerXtmp.Version("_B","_D",controllerX);
263  controllerX.Write("tmp_hio_tu_IOcontrollerCD.gen");
264 
265  controllerAB.Version("_AB","_EF",controllerX);
266  controllerX.Version("_A","_E",controllerXtmp);
267  controllerXtmp.Version("_B","_F",controllerX);
268  controllerX.Write("tmp_hio_tu_IOcontrollerEF.gen");
269 
270  controllerAB.Version("_AB","_aBCD",controllerX);
271  controllerX.Version("_A","_AB",controllerXtmp);
272  controllerXtmp.Version("_B","_CD",controllerX);
273  controllerX.Version("_aBCD","_ABCD",controllerXtmp);
274  controllerXtmp.Write("tmp_hio_tu_IOcontrollerABCD.gen");
275 
276  controllerAB.Version("_AB","_EFGH",controllerX);
277  controllerX.Version("_A","_EF",controllerXtmp);
278  controllerXtmp.Version("_B","_GH",controllerX);
279  controllerX.Write("tmp_hio_tu_IOcontrollerEFGH.gen");
280 
281  controllerAB.Version("_AB","_a_H",controllerX);
282  controllerX.Version("_A","_ABCD",controllerXtmp);
283  controllerXtmp.Version("_B","_EFGH",controllerX);
284  controllerX.Version("_a_H","_A_H",controllerXtmp);
285  controllerXtmp.Write("tmp_hio_tu_IOcontrollerA_H.gen");
286 
287  // Now, the hierarchy is completed for a chain of 8 TU's and can be extended to an
288  // arbitrary chain length.
289 
290  return;
291 }
292 
293 /** Run the tutorial */
294 int main() {
295  // call simple machine example
296  try {
297  transport_chain();
298  }
299  catch (Exception& e) {
300  std::cout << "function: " << e.Where() << std::endl;
301  std::cout << "exception description: " << e.What() << std::endl;
302  std::cout << "exception id: " << e.Id() << std::endl;
303 }
304  return 0;
305 }

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen