How can I get a simulink model to execute in real-time?

조회 수: 1 (최근 30일)
Ryan
Ryan 2015년 8월 27일
댓글: Alma Martinez 2018년 6월 21일
I'm trying to get a Simulink model of a quadrotor and controller to accept inputs and run at real-time speed. My goal is to have this low-level controller interface with a higher level controller in Python

답변 (2개)

Walter Roberson
Walter Roberson 2015년 8월 28일
Simulink Real Time execution requires generating code . There is no way to talk to Python unless it is on a different system, or unless Python can be called as C or C++ that is able to run with the destination Real Time Operating System.
An alternative to Simulink Real Time is Simulink Coder which can generate C or C++ code that can be compiled for any target, possibly hosted (that is, has an operating system.) The ability to run in Real Time on a hosted target would depend upon the facilities provided by the host operating system; for example you can do it with some Linux and Linux-like operating systems, but it is problematic with MS Windows, which thinks it should be able to (for example) defragment your terabyte disk drives in the middle of patient surgery.
  댓글 수: 1
Ryan
Ryan 2015년 8월 28일
Code generation wouldn't be a problem, except I'm doing some quaternion algebra with functions that do not support code generation. I guess the workaround for this is to use quaternion operators written in C/C++?
To clarify the python situation, that program is executing in a separate process and communicates with Matlab over UDP. It is also responsible for transmitting the location and orientation of the vehicle to a separate simulation running remotely. One of the other issues I was running into was crappy UDP in Simulink vs. relatively flawless UDP when being called from a .m script.
Another possibility I was thinking of was as follows. I'm able to call a bash script from the Python side which starts Matlab in headless mode and executes a script that runs the Simulink model with inputs. Proceeding this way I could run a 5 second simulation that executes in say 2-3 seconds, take the resultant time and solution vectors and use python to send these out to the external simulation as if they were occurring in real-time, but this just seems like a big hack to me.
My motion capture system has to run on Windows (bleh) but I could run the quadrotor sim on OS X where the Python code is running. As much as I would prefer the latter option, from a latency perspective I would probably be better off running the quad sim on the Windows box as well.
I appreciate any other feedback you might provide on this.

댓글을 달려면 로그인하십시오.


Bo Li
Bo Li 2015년 8월 28일
Regarding the communication from Python to MATLAB, you may consider Python Engine:
This feature was introduced in R2014b.
  댓글 수: 2
Ryan
Ryan 2015년 8월 28일
Very good, thanks for the reminder. I had been working on R2014a, but recently got set up with our R2015a license so I can use this instead of that bash rigamarole.
Alma Martinez
Alma Martinez 2018년 6월 21일
Hi, you can send data from python to matlab?, Using a 'communication in real time?, is it possible with python engine or another tool?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Real-Time Simulation and Testing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by