Run your Simulink models & libraries in Python.
Running software-in-the-loop tests with Simulink becomes time consuming with Matlab & Simulink overhead. There are ways to reduce it (Model reference, etc) however nothing has shown to be as fast as a precompiled shared library.
Python has a very mature set of tools and packages to automate testing.
Testing can be distributed to machines without Matlab/Simulink licenses.
There are more and more Python developers. Being able to hand off a Simulink Library for further use there is a good feature.
pytest
to run Software-in-the-Loop (SIL) tests on Simulink subsystems.This repository is a set of instructions, with examples, on how to create a Pythonic wrapper for Simulink models. It is not a turnkey Python module to do this:
import simulinkdll simulinkdll.run("my_model.slx") do_stuff()
For a given library or model configuring the Python should only need done when the Simulink Parameters/Signals change. The end developer will then be able do a import simulink_model
, but it takes development time.
.dll
, .so
) in Python and run the model.SimulinkGlobal
vs ExportedGlobal
in Simulink.Parameter
and Simulink.Signal
variables.A simple discrete transfer function. Compiled with a 1st order low pass filter.
There are two example notebooks for Example 2.
Example 2 also contains sample pytest
tests in the tests
directory. This demonstrates how you can use pytest
to test Simulink models. Sample test results are shown shown in Example2/test_results.md.
Tests can be run on GitHub actions as well. An example of pipeline file is provided: .github/workflows/blank.yml.
Adapted from Mathworks's Simulation of a Bouncing Ball
Running a Simulation in Simulink also has some overhead. By compiling the model to a shared library and executing it, this overhead is eliminated.
bouncing_ball_benchmark.m
benchmarks the model by testing increasingly smaller time steps. The model was then compiled and tested in Python and the corresponding times are recorded below.
This project also serves as a proof of concept for using CI/CD devops techniques with Simulink Models. There is a Jenkinsfile
that will build each of the examples and archive the artifacts:
.dll
).h
)Jenkins Pipeline screenshot:
Jenkins Artifacts screenshot:
Discussion, Questions & FeedbackRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4