hio_4_transport_unit.cpp

Go to the documentation of this file.
00001 /** @file hio_4_transport_unit.cpp
00002 
00003 Tutorial, transport chain example for  hiosys plugin.
00004 
00005 @ingroup Tutorials 
00006 
00007 @include hio_4_transport_unit.cpp
00008 
00009 */
00010 
00011 #include "libfaudes.h"
00012 
00013 // make the faudes namespace available to our program
00014 using namespace faudes;
00015 using namespace std;
00016 
00017 /** Transport chain example to demonstrate hierarchical I/O controller synthesis */ 
00018 void transport_chain() {
00019  
00020 /*
00021   This tutorial treats controller synthesis for a chain of an exemplary number of 8 transport units
00022   (TU's) that shall transport a workpiece from the left to the right.
00023   The hierarchy can be extended to an arbitrary number of TU's, with
00024   linear growth of complexity, measured in the sum of states of all involved generators.
00025   By allowing for only one workpiece at a time, the example is kept at a simple tutorial level
00026   such that the involved generators remain readable in a graphical view.
00027   However, linear complexity is still achieved in the case of parallel transport of as
00028   many workpieces as physically possible, see the real-world conveyor belt chain example.
00029 
00030   The TU's are numbered
00031   alphabetically from left to right. For each TU, an I/O plant model has to be provided as HioPlant.
00032   Note that these plant model components, e.g. plantA and plantB, must not share events; the
00033   membership of each event to the respective component is indicated by the suffixes _A and
00034   _B in the event labels, e.g. idle_A and idle_B. First, each TU is provided with a local controller
00035   using the synthesis function HioSynthMonolithic. For that, a specification has to be given as
00036   HioPlant describing the desired external behaviour of the locally controlled TU.
00037 
00038   To design a control hierarchy,
00039   we compound groups of two TU's, e.g. TU A and TU B. As the I/O based
00040   approach allows for abstraction-based control, each locally controlled TU is abstracted by its
00041   specification, so next the I/O shuffle of the specifications of two transport units is
00042   computed. An environment model has to be provided as HioEnvironment that describes the
00043   internal interaction of the two TU's within each other and the external interaction with the
00044   remaining environment. With a given specification of the group's desired behaviour, the
00045   function HioSynthHierarchical computes an I/O controller for the group. By specifying that
00046   each group of TU's shall behave exactly as a single TU, we can derive all remaining controllers
00047   of the hierarchy for 8 TU's by exploiting symmetry.
00048 */
00049 
00050 //######################################################################
00051   //*****
00052   //***** controller synthesis for plantA:*****
00053   //*****
00054 //######################################################################
00055 
00056   /* 
00057   We consider a simple transport unit (TU), described as HioPlant
00058   (data/4_transport_unit/4_transport_unit/plantA.gen).
00059   
00060   The TU consists of a conveyor belt carrying a box that can hold the workpiece to be transported.
00061   A spring sensor inside the box detects the absence or presence of a workpiece (empty, full).
00062   The initial state (state 1) is defined such that the sensor reports empty. The operator
00063   can choose between three different commands (state 2). After the no_op (no operation)
00064   command, the TU does not move, and the system remains in the initial state. The command
00065   del_tr (deliver to right) leads to an error state as there is currently no workpiece present to deliver.
00066   Choosing the command take_fl (take from left) prompts the TU to move the box to its
00067   left border (state 3). Now it depends on the environment if a workpiece is provided from the
00068   left, which is modeled by the event req_fl unobservable to the operator. For a plant description
00069   that is independent from the environment, we introduce the environment-events pack and nack
00070   (positive/negative acknowledge) respecting that the environment may or may not comply with the
00071   requests of the plant. If the environment is not in the condition to provide a workpiece (nack),
00072   the request is repeated. When a workpiece is provided from the environment, the sensor reports
00073   full. Now (state 6), the command take_fl leads to an error behaviour (the box can carry only
00074   one workpiece), and after no_op the plant still reports full. By the command del_tr, the belt
00075   moves the box to the right border. The event req_tr models the need for the workpiece to be withdrawn
00076   to the right by the environment. In case of pack, the system returns to its initial state.
00077   
00078   By  (UP,YP) := ({no_op, take_fl, del_tr}, {empty, full}), we identify the interaction with the operator,
00079   (UE,YE) := ({pack,nack}, {req_fl, req_tr}) describes interaction with the environment.
00080   Note that (UP,YP,UE,YE,LPE) features all I/O-plant properties posed in the formal Definition.
00081   */
00082   
00083   cout <<endl<< "******************** reading files..."  << endl;
00084 
00085   //read plant, spec and constraints:
00086   
00087   HioPlant plantA("data/4_transport_unit/plantA.gen");
00088   plantA.Write("tmp_hio_tu_plantA.gen");
00089   
00090   HioPlant specA("data/4_transport_unit/specA.gen");
00091   specA.Write("tmp_hio_tu_spec_A.gen");
00092   
00093   HioConstraint constrE_A("data/4_transport_unit/constrE_A.gen");
00094   constrE_A.Write("tmp_hio_tu_constrE_A.gen");
00095   
00096   HioConstraint constrP_A("data/4_transport_unit/constrP_A.gen");
00097   constrP_A.Write("tmp_hio_tu_constrP_A.gen");
00098   
00099   // The operator constraint constrC of specification A is minimal.
00100   // So, informally, it can be passed as an epsilon-language.
00101   HioConstraint constrC_A;
00102   constrC_A.InsInitState("1");
00103   constrC_A.SetMarkedState("1");
00104 
00105   // compute I/O controller:
00106   
00107   HioController controllerA, controllerB;
00108   HioSynthMonolithic(plantA, specA, constrC_A, constrP_A, constrE_A, controllerA);
00109   controllerA.Write("tmp_hio_tu_IOcontroller_A.gen");
00110   
00111   // plantB, specB and consequently controllerB are identical
00112   controllerA.Version("_A","_B",controllerB);
00113   controllerB.Write("tmp_hio_tu_IOcontroller_B.gen");
00114   
00115   // inspect full and external closed loop
00116   Generator full_loop,ext_loop;
00117   Parallel(controllerA,plantA,full_loop);
00118   full_loop.Write("tmp_hio_tu_full_loop_A.gen");
00119   Project(full_loop,specA.Alphabet(),ext_loop);
00120   ext_loop.Write("tmp_hio_tu_ext_loop_A.gen");
00121 
00122 //######################################################################  
00123   //*****
00124   //***** plantAB: abstraction, I/O shuffle and environment.*****
00125   //*****
00126 //######################################################################
00127   
00128   // specA serves as abstraction of the closed loop of controllerA and plantA, and so does specB for controllerB and plantB
00129   // read specB and corresp. environment constraint (op. constraint is minimal):
00130   HioPlant specB("data/4_transport_unit/specB.gen");
00131   HioConstraint constrE_B("data/4_transport_unit/constrE_B.gen");
00132 
00133   cout <<endl<< "******************** IOshuffle: tmp_hio_tu_shuffAB.gen/.png"  << endl;
00134   
00135   HioPlant shuffAB;
00136   HioShuffle(specA, specB, shuffAB);
00137   //HioShuffleTU(spec, specB, yc + ycB, uc + ucB, ye + yeB, ue + ueB, 1, shuffABnotmin);
00138   StateMin(shuffAB,shuffAB);
00139   cout<<endl<<"(sizeof shuffAB after statemin: "<<shuffAB.Size()<<").."<<endl;
00140   shuffAB.StateNamesEnabled(false);
00141   shuffAB.Name("IO shuffle AB");
00142   shuffAB.Write("tmp_hio_tu_shuffAB.gen");
00143   
00144 //read environment:
00145 
00146   HioEnvironment envAB("data/4_transport_unit/envAB.gen");
00147   envAB.Write("tmp_hio_tu_envAB.gen");
00148 
00149   
00150 //######################################################################
00151   //*****
00152   //***** controller synthesis for plantAB:*****
00153   //*****
00154 //######################################################################
00155 
00156 cout <<endl<<"********************"<<endl <<"******************** ready for Controller synthesis for plantAB"<< endl<<"********************"<<endl;
00157 
00158 //read specAB
00159   HioPlant specAB("data/4_transport_unit/specAB.gen");
00160   specAB.Write("tmp_hio_tu_specAB.gen");  
00161   // alternatively, the specification "specA_ARB_FEEDBACK.gen"
00162   // can be used. It does not specify an "idle"-feedback
00163   // after EACH wp transport, but after an ARBITRARY amount
00164   // instead. The same result is achieved for controller A 
00165   // because of the Yc-Acyclic property. However, this spec
00166   // cannot be used as plant abstraction, as there are no
00167   // constraints w.r.t. which this plant model is YP-live.
00168   
00169   // The operator constraint constrC of specification AB is minimal.
00170   // So, informally, it can be passed as an epsilon-language.
00171   HioConstraint constrC_AB;
00172   constrC_AB.InsInitState("1");
00173   constrC_AB.SetMarkedState("1");
00174 
00175 
00176 //read environment constraint of specification AB (op. constraint is minimal)
00177   HioConstraint constrL_AB("data/4_transport_unit/constrL_AB.gen");
00178   constrL_AB.Write("tmp_hio_tu_constrL_AB.gen");
00179 
00180 // local constraints: composition of env. constraints for spec. A and spec B (op. constraints for both are minimal)
00181   Generator locConstrAB;
00182   Parallel(constrE_A,constrE_B,locConstrAB);
00183   
00184 //calculate IO controller for plantAB
00185   HioController controllerAB;
00186   HioSynthHierarchical(shuffAB, envAB, specAB, locConstrAB, constrC_AB, constrL_AB, controllerAB);
00187   
00188 // marking does not count in controller
00189   PrefixClosure(controllerAB);
00190   StateMin(controllerAB,controllerAB);
00191   controllerAB.StateNamesEnabled(false);
00192   controllerAB.Name("Controller AB");
00193   controllerAB.Write("tmp_hio_tu_IOcontrollerAB.gen");
00194   cout<<endl<<">>>>> Synthesis done for Controller AB. <<<<<"<<endl;
00195   controllerAB.SWrite();
00196   
00197 // Again, we specify the same behaviour for plants C and D to receive a structurally 
00198 // identical controller CD.
00199 // Moreover, specification (ie abstract plant model)  AB is structurally identical to  specA and specB.
00200 // Hence, the controller ABCD for spec (abstract plant model) AB and CD is structurally identical to 
00201 // controller AB or CD ! The same holds for environment ABCD, which is derived directly from
00202 // environment AB.
00203 
00204 //######################################################################
00205   //*****
00206   //***** remaining plant- and controller hierarchy *****
00207   //*****
00208 //######################################################################
00209 
00210 // we derive all remaining components of the hierarchy by creating versions of the previous components.
00211   
00212   HioPlant plantX;
00213   
00214   plantA.Version("_A","_B",plantX);
00215   plantX.Write("tmp_hio_tu_plantB.gen");
00216   plantA.Version("_A","_C",plantX);
00217   plantX.Write("tmp_hio_tu_plantC.gen");
00218   plantA.Version("_A","_D",plantX);
00219   plantX.Write("tmp_hio_tu_plantD.gen");
00220   plantA.Version("_A","_E",plantX);
00221   plantX.Write("tmp_hio_tu_plantE.gen");
00222   plantA.Version("_A","_F",plantX);
00223   plantX.Write("tmp_hio_tu_plantF.gen");
00224   plantA.Version("_A","_G",plantX);
00225   plantX.Write("tmp_hio_tu_plantG.gen");
00226   plantA.Version("_A","_H",plantX);
00227   plantX.Write("tmp_hio_tu_plantH.gen");
00228   
00229   HioEnvironment envXtmp,envX;
00230   
00231   envAB.Version("_AB","_CD",envX);
00232   envX.Version("_A","_C",envXtmp);
00233   envXtmp.Version("_B","_D",envX);
00234   envX.Write("tmp_hio_tu_IOenvironmentCD.gen");
00235   
00236   envAB.Version("_AB","_EF",envX);
00237   envX.Version("_A","_E",envXtmp);
00238   envXtmp.Version("_B","_F",envX);
00239   envX.Write("tmp_hio_tu_IOenvironmentEF.gen");
00240   
00241   envAB.Version("_AB","_aBCD",envX);
00242   envX.Version("_A","_AB",envXtmp);
00243   envXtmp.Version("_B","_CD",envX);
00244   envX.Version("_aBCD","_ABCD",envXtmp);
00245   envXtmp.Write("tmp_hio_tu_IOenvironmentABCD.gen");
00246   
00247   envAB.Version("_AB","_EFGH",envX);
00248   envX.Version("_A","_EF",envXtmp);
00249   envXtmp.Version("_B","_GH",envX);
00250   envX.Write("tmp_hio_tu_IOenvironmentEFGH.gen");
00251   
00252   envAB.Version("_AB","_a_H",envX);
00253   envX.Version("_A","_ABCD",envXtmp);
00254   envXtmp.Version("_B","_EFGH",envX);
00255   envX.Version("_a_H","_A_H",envXtmp);
00256   envXtmp.Write("tmp_hio_tu_IOenvironmentA_H.gen");
00257   
00258   HioController controllerX,controllerXtmp;
00259   
00260   controllerAB.Version("_AB","_CD",controllerX);
00261   controllerX.Version("_A","_C",controllerXtmp);
00262   controllerXtmp.Version("_B","_D",controllerX);
00263   controllerX.Write("tmp_hio_tu_IOcontrollerCD.gen");
00264   
00265   controllerAB.Version("_AB","_EF",controllerX);
00266   controllerX.Version("_A","_E",controllerXtmp);
00267   controllerXtmp.Version("_B","_F",controllerX);
00268   controllerX.Write("tmp_hio_tu_IOcontrollerEF.gen");
00269   
00270   controllerAB.Version("_AB","_aBCD",controllerX);
00271   controllerX.Version("_A","_AB",controllerXtmp);
00272   controllerXtmp.Version("_B","_CD",controllerX);
00273   controllerX.Version("_aBCD","_ABCD",controllerXtmp);
00274   controllerXtmp.Write("tmp_hio_tu_IOcontrollerABCD.gen");
00275   
00276   controllerAB.Version("_AB","_EFGH",controllerX);
00277   controllerX.Version("_A","_EF",controllerXtmp);
00278   controllerXtmp.Version("_B","_GH",controllerX);
00279   controllerX.Write("tmp_hio_tu_IOcontrollerEFGH.gen");
00280   
00281   controllerAB.Version("_AB","_a_H",controllerX);
00282   controllerX.Version("_A","_ABCD",controllerXtmp);
00283   controllerXtmp.Version("_B","_EFGH",controllerX);
00284   controllerX.Version("_a_H","_A_H",controllerXtmp);
00285   controllerXtmp.Write("tmp_hio_tu_IOcontrollerA_H.gen");
00286   
00287   // Now, the hierarchy is completed for a chain of 8 TU's and can be extended to an
00288   // arbitrary chain length.
00289   
00290   return;
00291 }
00292 
00293 /** Run the tutorial */
00294 int main() {
00295   // call simple machine example
00296   try {
00297   transport_chain();
00298   }
00299   catch (Exception& e) {
00300   std::cout << "function: " << e.Where() << std::endl;
00301   std::cout << "exception description: " << e.What() << std::endl;
00302   std::cout << "exception id: " << e.Id() << std::endl;
00303 }
00304   return 0;
00305 }

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen