Skip to main content

Automated Code Generation for DES Controllers Modeled as Finite State Machines

  • Conference paper
  • First Online:
Formal Methods: Foundations and Applications (SBMF 2023)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 14414))

Included in the following conference series:

  • 101 Accesses

Abstract

Finite State Machines (\(\textrm{FSMs}\)) are the foundation to design Discrete Event Systems (\(\textrm{DESs}\)). A \(\textrm{FSM}\) that designs a \(\textrm{DES}\) model can be further processed using Supervisory Control Theory (\(\textrm{SCT}\)) to synthesize correct-by-construction software. When applied to industrial-scale \(\textrm{DESs}\), \(\textrm{FSMs}\) face limitations in the design, synthesis, and implementation steps. Supremica is a straightforward tool that facilitates design and synthesis but does not reach the implementation phase. This requires additional tools to convert \(\textrm{FSM}\) models into code. This paper presents the tool DEScMaker, which receives as input an \(\textrm{FSM}\) model outputting from Supremica and converts it into implementable C code. Our approach complements Supremica with code generation and allows taking advantage of its intuitive interface, useful simulator, and safe algorithms while automating a task that, in practice, consists of complex manual programming. An example illustrates the tool and quantifies its advantages.

This research was supported by the Brazilian National Council of Scientific and Technological Development (CNPq), under grant number 309946/2020-4, by CAPES (Coordination for the Improvement of Higher Level or Education Personnel), Brazil, financial code 001, FINEP (Funding Authority for Studies and Projects), Brazil, Araucária Foundation, Brazil, and IFC (Catarinense Federal Institute).

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://factoryio.com.

  2. 2.

    https://platformio.org.

  3. 3.

    https://espressif.com/en/products/devkits.

  4. 4.

    In order to measure the use of memory, the Inspect functionality of PlataformIO was used, available at: https://docs.platformio.org/en/stable/home/index.html#project-inspect.

References

  1. Akesson, K., et al.: Supremica (2019). http://www.supremica.org/

  2. Alves, L.V., Martins, L.R., Pena, P.N.: UltraDES - a library for modeling, analysis and control of DES. IFAC-PapersOnLine 50, 5831–5836 (2017). https://doi.org/10.1016/j.ifacol.2017.08.540

    Article  Google Scholar 

  3. Assmann, J.V., Gotz, M., Muller, I., Rettberg, A.: Distributed embedded platform for controllers following the SCT. In: International Conference on Electrical, Communication, and Computer Engineering, pp. 1–6. IEEE (2021). https://doi.org/10.1109/ICECCE52056.2021.9514113

  4. Basile, F., Chiacchio, P.: On the implementation of supervised control of discrete event systems. IEEE Trans. Control Syst. Technol. 15, 725–739 (2007). https://doi.org/10.1109/TCST.2006.890281

    Article  Google Scholar 

  5. van Beek, D.A., et al.: CIF 3: model-based engineering of supervisory controllers. In: Ábrahám, E., Havelund, K. (eds.) TACAS 2014. LNCS, vol. 8413, pp. 575–580. Springer, Heidelberg (2014). https://doi.org/10.1007/978-3-642-54862-8_48

    Chapter  Google Scholar 

  6. Cassandras, C.G., Lafortune, S.: Introduction to Discrete Event Systems, 3rd edn. Springer, Cham (2021). https://doi.org/10.1007/978-3-030-72274-6

    Book  MATH  Google Scholar 

  7. Clavijo, L.B., Basilio, J.C., Carvalho, L.K.: DESLAB: a scientific computing program for analysis and synthesis of discrete-event systems. IFAC Proc. Vol. 45, 349–355 (2012). https://doi.org/10.3182/20121003-3-MX-4033.00056

    Article  Google Scholar 

  8. Fokkink, W., Goorden, M., van de Mortel-Fronczak, J., Reijnen, F., Rooda, J.: Supervisor synthesis: bridging theory and practice. Computer 55, 48–54 (2022). https://doi.org/10.1109/MC.2021.3134934

    Article  Google Scholar 

  9. Fokkink, W., Goorden, M., van de Mortel-Fronczak, J., Reijnen, F., Rooda, J.: Supervisor synthesis: bridging theory and practice. Computer 55(10), 48–54 (2022)

    Article  Google Scholar 

  10. Gobe, F., Timmermanns, T., Ney, O., Kowalewski, S.: Synthesis tool for automation controller supervision. In: International Workshop on Discrete Event Systems, pp. 424–431. IEEE (2016). https://doi.org/10.1109/WODES.2016.7497883

  11. Harrison, R., Vera, D., Ahmad, B.: Engineering methods and tools for cyber-physical automation systems. Proc. IEEE 104(5), 973–985 (2016)

    Article  Google Scholar 

  12. Hasdemir, I.T., Kurtulan, S., Goren, L.: An implementation methodology for supervisory control theory. Int. J. Adv. Manuf. Technol. 36, 373–385 (2008). https://doi.org/10.1007/s00170-006-0843-5

    Article  Google Scholar 

  13. Leal, A.B., da Cruz, D.L.L., da S. Hounsell, M.: Supervisory control implementation into programmable logic controllers. In: International Conference on Emerging Technologies and Factory Automation, pp. 1–7. IEEE (2009). https://doi.org/10.1109/ETFA.2009.5347090

  14. Litchfield, S., Formby, D., Rogers, J., Meliopoulos, S., Beyah, R.: Rethinking the honeypot for cyber-physical systems. IEEE Internet Comput. 20(5), 9–17 (2016)

    Article  Google Scholar 

  15. Liu, Y., Peng, Y., Wang, B., Yao, S., Liu, Z.: Review on cyber-physical systems. IEEE/CAA J. Automatica Sinica 4(1), 27–40 (2017)

    Article  Google Scholar 

  16. Ljungkrantz, O., Akesson, K., Richardsson, J., Andersson, K.: Implementing a control system framework for automatic generation of manufacturing cell controllers. In: Proceedings 2007 IEEE International Conference on Robotics and Automation, pp. 674–679. IEEE (2007). https://doi.org/10.1109/ROBOT.2007.363064

  17. Malik, R., Åkesson, K., Flordal, H., Fabian, M.: Supremica-an efficient tool for large-scale discrete event systems. IFAC-PapersOnLine 50, 5794–5799 (2017)

    Article  Google Scholar 

  18. McCarthy, D., McMorrow, D., O’Dowd, N.P., McCarthy, C.T., Hinchy, E.P.: A model-based approach to automated validation and generation of plc code for manufacturing equipment in regulated environments. Appl. Sci. 12, 7506 (2022). https://doi.org/10.3390/app12157506

    Article  Google Scholar 

  19. Mohajerani, S., Malik, R., Fabian, M.: Compositional synthesis of supervisors in the form of state machines and state maps. Automatica 76, 277–281 (2017)

    Article  MathSciNet  MATH  Google Scholar 

  20. Moor, T., Schmidt, K., Perk, S.: libFAUDES - An open source C++ library for discrete event systems. In: 2008 9th International Workshop on Discrete Event Systems, pp. 125–130. IEEE (2008). https://doi.org/10.1109/WODES.2008.4605933

  21. Pinheiro, L.P., Lopes, Y.K., Leal, A.B., Junior, R.S.U.R.: Nadzoru: a software tool for supervisory control of DES. IFAC-PapersOnLine 48, 182–187 (2015). https://doi.org/10.1016/j.ifacol.2015.06.491

    Article  Google Scholar 

  22. Possato, T.: Automated code generator from Supremica to C (2023). bit.ly/3DTsCEu

    Google Scholar 

  23. Possato, T.: Automated code generator from Supremica to Python (2023). bit.ly/3saIY99

    Google Scholar 

  24. Possato, T.: DEScMaker case study (2023). bit.ly/47w3zoA

    Google Scholar 

  25. Possato, T.: DEScMaker case study video (2023). bit.ly/3KFqELY

    Google Scholar 

  26. Possato, T.: DESPythonMaker case study (2023). bit.ly/3OD0haF

    Google Scholar 

  27. Queiroz, M.H.D., Cury, J.E.R.: Modular multitasking supervisory control of composite discrete-event systems. In: 16th IFAC World Congress (2005)

    Google Scholar 

  28. de Queiroz, M., Cury, J.: Synthesis and implementation of local modular supervisory control for a manufacturing cell. In: International Workshop on Discrete Event Systems, pp. 377–382. IFAC (2002). https://doi.org/10.1109/WODES.2002.1167714

  29. Ramadge, P., Wonham, W.: The control of discrete event systems. Proc. IEEE 77(1), 81–98 (1989). https://doi.org/10.1109/5.21072

    Article  Google Scholar 

  30. Reniers, M., van de Mortel-Fronczak, J.: An engineering perspective on model-based design of supervisors. IFAC-PapersOnLine 51, 257–264 (2018). https://doi.org/10.1016/j.ifacol.2018.06.310

    Article  Google Scholar 

  31. Rosa, M., Teixeira, M., Malik, R.: Exploiting approximations in supervisory control with distinguishers. In: International Workshop on Discrete Event Systems. Sorrento, Italy (2018)

    Google Scholar 

  32. Silva, Y.G., de Queiroz, M.H.: Formal synthesis, simulation and automatic code generation of supervisory control for a manufacturing cell. In: Symposium Series in Mechatronics, pp. 418–426. ABCM (2010). https://www.abcm.org.br/anais/cobem/2009/pdf/COB09-1992.pdf

  33. Uzam, M.: A general technique for the plc-based implementation of RW supervisors with time delay functions. Int. J. Adv. Manuf. Technol. 62, 687–704 (2012). https://doi.org/10.1007/s00170-011-3817-1

    Article  Google Scholar 

  34. Vieira, A.D., Cury, J.E.R., de Queiroz, M.H.: A model for PLC implementation of supervisory control of DES. In: International Conference on Emerging Technologies and Factory Automation, pp. 225–232 (2006). https://doi.org/10.1109/ETFA.2006.355436

  35. Vieira, A.D., Santos, E.A.P., de Queiroz, M.H., Leal, A.B., de Paula Neto, A.D., Cury, J.E.R.: A method for PLC implementation of supervisory control of DES. IEEE Trans. Control Syst. Technol. 25, 175–191 (2017). https://doi.org/10.1109/TCST.2016.2544702

  36. Yang, J., Tan, K., Feng, L., El-Sherbeeny, A.M., Li, Z.: Reducing the learning time of reinforcement learning for the supervisory control of discrete event systems. IEEE Access 1, 1–14 (2023)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Marcelo Teixeira .

Editor information

Editors and Affiliations

Appendices

Appendix 1 Directory Tree of Generated Code

Figure 9 shows the representation of the directory and file structure generated by DEScMaker.

Fig. 9.
figure 9

Directory tree of generated code.

In this case, the input file has only one supervisor, named “sup”, which results in the files “sup.c” and “sup.h” under “src/supervisors/”. If the file has two or more supervisors, as in the modular approach, all code files and headers are placed in the folder “supervisors”.

Appendix 2 Code Generation Example

Consider the \(\textrm{FSM}\) in Fig. 10, corresponding to a supervisor with four states, seven transitions, and three different events. The Supremica file with this automaton was submitted to the DEScMaker, which created the code structure and saved it in “src/supervisors/sup.c”.

Fig. 10.
figure 10

Simple example of \(\textrm{FSM}\) for code generation.

Variables of type Alphabet are declared to create the list of events observed by the supervisor. This creates a variable with reserved memory space for an Alphabet structure, but its fields have no values assigned yet. Next, the alphabet variables are initialized and linked. This creates a list where it is possible to navigate from the first to the last event in the alphabet. In this example, the last element of the ‘sup_e3_evt2’ variable is NULL because there are no more elements in the list. This pattern also repeats when creating the other lists. The listing 1.1 shows the code for declaring, initializing, and linking the alphabet.

figure d

Then the variables of type State, for representing the \(\textrm{FSM}\) states, are declared as in Listing 1.2.

figure e

Once the alphabet and states are defined, the transition lists can be created and linked. Listing 1.3 exemplifies the transitions of the states q0 and q1.

figure f

The states are initialized in Listing 1.4, now filled with all the necessary information, especially the pointer to the corresponding list of transitions.

figure g

Finally, Listing 1.5 shows the structure of the supervisor, which will compose the list of supervisors (in the file “src/supervisors/supervisor_list.c”) used by the event handler to query the event status and perform transitions. The variable of type ’Supervisor’ is declared and initialized with pointers to the initial state, the current state, the last state (NULL because it has not yet been executed), the first item in the event list, and the supervisor’s name.

figure h

Rights and permissions

Reprints and permissions

Copyright information

© 2024 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Possato, T., Valentini, J.H., Southier, L.F.P., Teixeira, M. (2024). Automated Code Generation for DES Controllers Modeled as Finite State Machines. In: Barbosa, H., Zohar, Y. (eds) Formal Methods: Foundations and Applications. SBMF 2023. Lecture Notes in Computer Science, vol 14414. Springer, Cham. https://doi.org/10.1007/978-3-031-49342-3_7

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-49342-3_7

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-49341-6

  • Online ISBN: 978-3-031-49342-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics