Matlab Simulink Stateflow for Supervisory Control Simulation and Automated Code Generation Anderson S. Carvalho * Felipe Alves Pereira * Marcelo G¨ otz * Ivan M¨ uller ** * Departamento de Automa¸ c˜ao e Energia, Universidade Federal do Rio Grande do Sul, RS (e-mails: andercarvalho04@gmail.com, felipepereira82@gmail.com, mgoetz@ufrgs.br). ** Departamento de Engenharia El´ etrica, Universidade Federal do Rio Grande do Sul, RS (e-mail: ivan.muller@ufrgs.br) Abstract: In manufacturing systems, a class of Discrete Event Systems (DES), plant behavior can be modeled through automata which serve as the basis for synthesizing controllers using Supervisory Control Theory (SCT). The present paper proposes the usage of Matlab Simulink Stateflow for modeling automata and for automated code generation. The usage of Matlab Simulink is encouraged by its widespread acceptance in industry providing, also, an intrinsic possibility of simulation and flexible automated code generation capability. The feasibility of the proposal is shown by preparing a testbed based on an embedded system target used to set up a hardware-in-the-loop simulation architecture. Keywords: Discrete Event Systems; Supervisory Control Theory; Hardware-in-the-loop simulation; Matlab Simulink Stateflow; Embedded System. 1. INTRODUCTION Discrete Event Systems (DES) refers to a system class that differs essentially from Continuous Variable Systems (CVS). DES is event-driven and deals with discrete states (Cassandras and Lafortune (2008)). Several systems are DES examples: software tasks in a computation system that need to be processed by the microprocessor; traf- fic lights for controlling vehicles in streets intersections; people in a queue standing to be served in a bus stop; manufacturing plants with machines, conveyors, belts, etc. Manufacturing systems, especially, has received more at- tention in the past years since this area seeks new formal- ism and methods to enable high performance and flexible plants design (Fabian and Hellgren (1998); Hasdemir et al. (2008)). Different modeling techniques, such as Petri Nets, Markov Chains, queueing theory, automata form the most basic class of DES models , as mentioned in Cassandras and Lafortune (2008). Ramadge and Wonham (1987) proposes a formalism and a methodology to derive a DES controller using automata, the Supervisory Control Theory (SCT). Even though SCT provides a powerful framework for designing DES controller using a systematic and formal methodology, especially to manufacturing systems, it has not gained acceptance in the industry yet (Wonham et al. (2018)). This is mostly since SCT implementation on Programmable Logic Controllers (PLCs), which is the still most used technology in the manufacturing industry, has some obstacles to be overcome. PLCs are basically synchronous systems, in counterpart to the essentially asynchronous modeling bases of SCT theory (Fabian and Hellgren (1998)). Moreover, PLCs have been used widely in industry for more than 25 years, and it forms the bases technology for the most current and new applica- tions (Hasdemir et al. (2008)). Academic society, however, has demonstrated a great in- terest for DES and SCT theory. Several attempts to over- come the gap between scientific achievements and indus- trial use have been promoted, like Fabian and Hellgren (1998); Hasdemir et al. (2008); Afzalian et al. (2008); Jean-Marc ROUSSEL (2005). Additionally, several aca- demic software tools have being developed, like for instance Ricker et al. (2006); Moor et al. (2008); Rudie (2006); Preischadt et al. (2015); Thomas Moor, Klaus Schmidt et al. (2010); Jordan et al. (2017), enabling the design and simulation of plants and controllers for manufacturing systems. In this direction, it is proposed the usage of Matlab Simulink Stateflow for modeling supervisor and plant au- tomata, a widespread development tool well accepted in the industry and academia. In addition, the controller is deployed using the automated code generator, also supported in Matlab Simulink. In this paper, Embedded Coder was used. Nevertheless, Matlab Simulink provides automated code generation for other languages and en- vironments, like Hardware Description Language (HDL) suitable for Field Programmable Gate Array (FPGA). DOI: 10.17648/sbai-2019-111467 2219