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

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen