Skip to content
forked from Kvixen/Simulix

A third-party Simulink tool to generate FMUs from models using the C-API

License

Notifications You must be signed in to change notification settings

tkorvola/Simulix

 
 

Repository files navigation

Simulix

FMU builder for Simulink models using the C-API.

Content

License

GNU GPL V.3

Simulix generates an FMU from a simulink model source code.

Copyright (C) 2018 Scania CV AB and Simulix contributors

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Usage

Download and Installation

Windows

Dependencies

To use Simulix, you will need the following

Windows Installation

In order to use Simulix you can either

  1. Clone the GitHub repository via git:

    git clone https://github.com/Kvixen/Simulix.git
    cd Simulix
    pip install -r requirements.txt

Linux

Linux Dependencies

To use Simulix, you need the following

  • Python 3
    • Lxml - Python package
  • CMake

Optional for cross compiling to Windows

  • mingw-w64

Linux Installation

  1. Install the dependencies:

    sudo apt-get --assume-yes python
    sudo apt-get --assume-yes cmake
  2. (OPTIONAL) If you want to be able to cross compile:

    sudo apt-get --assume-yes mingw-w64
  3. Clone the github repository:

    git clone https://github.com/Kvixen/Simulix.git
    cd Simulix
    pip install -r requirements.txt

Exporting your model from Simulink

In order for Simulix to function correctly, the correct code generation options need to be selected in Simulink.

Options

In Simulink, the code generation options are located under Code, C/C++ Code, Code Generation Options.

CodeG_list CodeG

In Code Generation, under Target selection, make sure that System target file is set to grt.tlc and that Language is set to C.

Under Build process, select Package code and artifacts. You can also fill in the name of the zip file that will be generated. If the field is left empty, the zip file will have the name of the Simulink model.

Interface_list Interface

In the submenu Interface to Code Generation, make sure all boxes for C API generation are ticked.

To build your model, simply press Ctrl+B on your keyboard.

Running Simulix

Simulix comes with certain flags

Requires Arguments:

  • ZN: Positional argument for name of zipfile
  • -p : Path for generating files and build folder
  • -t : Path to templates and includes folders (if not Simulix installation folder)
  • -zp: Path to zipfile
  • -m : Makefile program
  • -f : Build folder name
  • -e : Path to extension
  • -tf: Name of temp folder

Just specify flag, not arguments:

  • --DEBUG_BUILD: Do not build release configuration, but build debug configuration
  • --ONLY_BUILD : Do not regenerate files, only build existing
  • --NO-TEMP : Do not delete the temp folder
  • --NO-CMAKE : Do not execute CMAKE
  • --NO-MAKE : Do not execute MAKE program

Here are some examples of executing Simulix

The model zip file is called example.zip and exists in the current directory

Simulix.py example

The model zip file exists in a subfolder called zip and I want to build in a subfolder called generated

mkdir generated
Simulix.py example -p generated -zp zip

Extensions

With Simulink, there's a lot of toolboxes. Instead of waiting around for support of a special toolbox you can temporary do your own.

With our program, you can supply a path to your extension with the model when building. This extension can provide additional information and replace our template files.

In order to use it, make a new folder containing a extension.py file. This is the only required step. If this file exists, even if it's empty, the extension will be recognized.

With an extension, you can use certain functions inside extension.py that will be called.

get_template_info(replace_dict):
    return replace_dict

If this function exist, the dict Simulix uses to generate template files will be passed so you either can log the variables, change them or remove them.
In order for this to take effect, you have to return the replace_dict after your changes.

With an extension, you can also modify Simulix template files. If a template file is found inside the extension in a templates folder, Simulix will default to that template file. An example of an extension can look something like this

extension.py

get_template_info(replace_dict):
    replace_dict['TEXT_STRING'] = "Hello World"
    return replace_dict

templates/CMakeLists_template.txt

message(STATUS {TEXT_STRING})

Because we are using pythons format function on the entire file, to use brackets without replacing anything and without raising a KeyError error, use double brackets. An example can look like this

templates/CMakeLists_template.txt

set(STRING_VARIABLE {TEXT_STRING})
message(STATUS ${{STRING_VARIABLE}})

This will produce the CMakeLists file like so

ModelDir/CMakeLists.txt

set(STRING_VARIABLE "Hello World")
message(STATUS ${STRING_VARIABLE})

WIKI

Wiki pages are coming soon, so we can have less clutter in the read-me. This is not top-priority, but I promise, soon™.

Currently Work In Progress

Almost everything in this project is currently work in progress, even the project name. Feel free to contribute all you want.

Support

While we are in Alpha, we will list what we are currently supporting.

✓: We currently support this software/OS

✕: We currently do not support this software/OS

?: We are currently not able to test Simulix on this software and are unable to determine if we support it or not.

  • Windows
    • 32-bit: ✕
    • 64-bit: ✓
  • Linux: ✓
  • macOS: ?

About

A third-party Simulink tool to generate FMUs from models using the C-API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 83.8%
  • Python 10.1%
  • CMake 4.2%
  • Shell 1.9%