Python pybamm and MATLAB/Simulink integration

19 ビュー (過去 30 日間)
yunus
yunus 2025 年 4 月 4 日
回答済み: Himanshu 2025 年 4 月 10 日
I have a battery model written in python (py 3.11) with pybamm 24.11.2 and casadi solver 3.6.7.
I want to use this model in simulink in real time. I want to dynamically run the current dependent pybamm model.
Websearch and other attempts did not work. How can I integrate simulink and pybamm?
  1 件のコメント
syed khaleduzzaman
syed khaleduzzaman 2025 年 4 月 5 日

Hi, I am planning on same thing to implement. Let me know if you get any direction!

サインインしてコメントする。

回答 (1 件)

Himanshu
Himanshu 2025 年 4 月 10 日
Hello,
I see that you are attempting to integrate PyBaMM (a Python-based tool) with MATLAB/Simulink in a real-time environment. MATLAB provides functionality to directly call Python using external language interfaces. The main challenge is enabling communication between Python and Simulink, as Simulink typically requires compiled C/C++ code or MATLAB functions. PyBaMM’s reliance on Python/CasADi complicates direct integration.
One viable approach is to use MATLAB’s Python Engine to call the PyBaMM model from Simulink via a MATLAB Function block. Ensure that MATLAB recognizes your Python environment by using:
pyenv("Version", "your_python_executable_path")
Then, create a MATLAB wrapper function that interacts with PyBaMM.
Another method is to use co-simulation via TCP/IP or UDP. The idea is to run the PyBaMM model as a separate process that communicates with Simulink over a network. In Simulink, you can use TCP/IP Send and Receive blocks to exchange data. On the Python side, set up a server to listen for Simulink's commands, run the model, and send back results. This decouples the two environments but requires handling synchronization and latency.
Please refer to the attached documentation for more information:
I hope this helps.

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by