Translating Simulink Models to Modelica Using the Nsp Platform
Total Page:16
File Type:pdf, Size:1020Kb
Translating Simulink Models to Modelica using the {\NSP} Platform TranslatingTranslating Simulink Simulink Models Models to Modelica to Modelicausing the {\NSP} using Platform the Nsp Platform Chancelier, Jean-Philippe and Furic, Sébastien and Weis, Pierre 1 2 2 841 Jean-Philippe Chancelier Sébastien Furic Pierre Weis 1Université Paris-Est, CERMICS (ENPC), 77455 Marne-la-Vallée 2, France, [email protected] 2 Inria Paris, 2 rue Simone Iff, 75589 Paris, France & Université Paris-Est, CERMICS (ENPC), 77455 Marne-la-Vallée 2, France {sebastien.furic,pierre.weis}@inria.fr Abstract blocks. Up to our knowledge this work remains the most advanced effort in that direction. It is however no We present a new Simulink (Simulink) to Modelica (Mod- longer maintained. In the Scicos software environment, elica) translation chain embedded into Nsp. Translated the Coselica library offers signal models to allow users models can be edited (original Simulink diagrams are pre- to better exploit Modelica from within Scicos by propos- served through translation) and simulated. This transla- ing a large set of Modelica submodels in the same spirit as tion chain makes use of the Simport tool, originally de- the standard Modelica library (MSL). Many Simulink-like signed to translate Simulink models to Scicos models, and blocks are also available in Coselica. also relies on Modelicac, i.e. Scicos’ Modelica companion The approach presented here differs from Mike compiler. Dempsey’s and Dirk Reusch’s approaches in that trans- Using some examples, we demonstrate the effective- lation of original blocks is not attempted on a one-to-one ness of the translation process and detail some techni- basis. Instead, we use a two steps translation process: the cal aspects of it. This new Nsp feature extends Nsp’s first step translates the Simulink model into an equivalent simulation capabilities and makes it a reference platform Scicos native model; the second step translates the Scicos for users looking for means to simulate Simulink models native model to Modelica code. within a Modelica framework. Resulting Modelica code To handle the initial Simulink to Scicos translation, can even be exported to other Modelica compatible tools. we use an external tool named Simport: it translates a Keywords: Nsp; Simulink; Modelica Simulink model by translating each block in the original Simulink model with one or several blocks of the Scicos 1 Introduction native block library, so that original semantics is preserved Nsp is a Matlab-like numerical environment which can run with a high degree of confidence. the Scicos modeling environment, a Simulink-like block For the second step, we developed a set of Nsp special diagram editor and simulator. purpose compilation routines to translate Scicos blocks to From 2003 to 2008, in the course of funded projects genuine Modelica blocks. When a Scicos block has a di- SimPA and SimPA2, a Modelica compiler named Modeli- rect Coselica equivalent, the compilation routine simply cac has been developed allowing Scicos to handle genuine emits thre corresponding Coselica block; when there is Modelica models. This integration of Modelica within no Coselica equivalent, the compilation routine generates Scicos has been the subject of several papers published an entirely new block containing ad-hoc Modelica code at the Modelica conference (Nikoukhah and Najafi, 2008; to handle the Scicos block behavior. Using this compile- Nikoukhah and Furic, 2009). The purpose of using Mod- time Modelica code generation and the two steps transla- elica is to serve as a high-level description language to tion process was the key ideas to fill the huge semantic gap extend Scicos expressiveness: Modelica allows users to between Simulink and Modelica. compose “acausal” models where the original environ- We give in this paper a detailed description of this new ment forced users to describe their models as block dia- translation chain hosted by the Nsp environment. grams. 2 Involved Tools In this paper we focus on a new application of Modelica within Scicos under Nsp, that is as a target language for As mentioned above, the translation chain relies on a com- Simulink model translation. bination of several tools. We give hereafter a short de- Several Simulink to Modelica translation tools have al- scription of each of them. ready been proposed in the past, we mention in partic- 2.1 Nsp, a Programming Environment for Nu- ular Mike Dempsey’s Simelica and AdvancedBlocks li- brary (Dempsey, 2003) and Dirk Reusch’s Coselica ini- merical Applications tiative (Reusch). AdvancedBlocks was a fairly complete Nsp (Nsp) is a mature Matlab-like Scientific Software library of Modelica blocks which allowed users to use Package developed under the GPL license. Nsp features Modelica blocks as a one-to-one replacement for Simulink a high-level, safe imperative programming language with DOI Proceedings of the 13th International Modelica Conference 841 10.3384/ecp19157841 March 4-6, 2019, Regensburg, Germany Translating Simulink Models to Modelica using the {\NSP} Platform automatic memory management. This language can be produces a Scicos model data structure. Second, using used interactively, giving users an easy access to efficient Nsp scripts we are able to convert, in a Scicos model data numerical routines; It can also be used as a more conven- structure, some Scicos blocks to Modelica blocks. tional programming language to extend Nsp’s capabilities. In the conversion process from Simulink to Modelica, Nsp contains internally a class system with simple in- the scicos compiler/scheduler also plays a key role. It heritance and interface implementation. When used as an infers dimensions and types used in the Modelica blocs. interactive computing environment, it comes with online This is quite an exciting feature since it gives the possibil- help facilities and an easy access to GUI facilities and ity to have Modelica blocks for which the associated Mod- graphics. elica model is not a fixed Modelica class but a specific one A large set of libraries are available and it is moreover adapted to specific dimensions and types generated on the easy to implement new functionalities. External libraries fly. can also be used: this requires writing some wrapper code (also called interface) to live in harmony with Nsp’s inter- 2.3 Modelicac, a Simple Yet Useful Modelica nal state. The interface mechanism can be either static or Compiler dynamic. By using dynamic functionalities one is able to Development of Modelicac started in 2003 as a joint work build toolboxes. between Inria and TNI-Valiosys (now Dassault Systèmes) Nsp shares many traits with other Matlab-like Scientific in the course of the SimPA (SIMulation pour le Procédé Softwares such as Matlab, Octave, ScilabGtk (ScilabGtk; et l’Automatique) french funded project. The goal was to Campbell et al., 2006), and also with scripting languages make Scicos compatible with a significant subset of the such as Python. Modelica language in order for users to be able to de- The main toolbox used in this work is Scicos that we scribe complex hybrid models without having to resort to describe now. low-level block diagram descriptions. Indeed, building a 2.2 Scicos, a Block Diagram Modeler and Sim- block diagram from a physical model requires 1)perform- ing a complete analysis of physical phenomena into play ulator (to determine which elementary blocks to use in the dia- Scicos (Scicos) is a graphical dynamical system modeler gram), and 2)determining how data flows between blocks and simulator originally developed in the Metalau project (to connect elementary blocks together). On the other at INRIA, Paris-Rocquencourt center. With Scicos, users hand, Modelica tools considerably ease physical model can create block diagrams to model and simulate the dy- construction by automatically analysing the overall struc- namics of hybrid dynamical systems and compile models ture of physical models described in a much more user- into executable code. Scicos is used for signal process- friendly way: familiar physical components (e.g. springs, ing, systems control, queuing systems, and to study phys- transistors, hydraulic pumps, etc.) can be used to build ical and biological systems. Extensions allow generation models. Translation from this high-level description to of component-based modeling of electrical and hydraulic low-level data flow is performed automatically in a quite circuits using the Modelica language. satisfactory way, which frees users from a painful work. We consider in this paper the Scicos/Nsp version of Sci- Moreover, even slight modifications of physical models cos maintained and developed at ENPC. Scicos/Nsp is a may require considerable changes in corresponding block- Nsp toolbox and runs in the Nsp environment. Having ac- diagram descriptions; this is not the case with a high-level cess to Nsp functions when designing simulation models description. is of great importance. In its initial version, Modelicac essentially focussed on Scicos users often needs to use Nsp functions such as the “continuous part” of hybrid models. This mainly com- those dedicated to filter design for signal processing or prises differential equations and event-trigerring mecha- controller design in the construction of simulation mod- nisms (e.g. , “when equations”). Difference equations els. Nsp’s programming language can be used for batch were however also be described, although with many re- processing of multiple simulation tasks, and more gener- strictions, because the idea was to discourage users from ally, models designed by Scicos can be used as functions writing discrete equations in Modelica. Indeed, Scicos is in Nsp. Nsp’s graphical facilities can be used for post pro- primarily a hybrid modelling environment and, in particu- cessing simulation results. But the integration of Scicos lar, it handles discrete, event-trigered changes, much more and Nsp goes beyond that. The Scicos editor is entirely robustly than Modelica because of its synchronous roots. written in Nsp’s language.