Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Ryan
Ryan el 27 de Ag. de 2015
Comentada: Alma Martinez el 21 de Jun. de 2018
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

Respuestas (2)

Walter Roberson
Walter Roberson el 28 de Ag. de 2015
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 comentario
Ryan
Ryan el 28 de Ag. de 2015
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.

Iniciar sesión para comentar.


Bo Li
Bo Li el 28 de Ag. de 2015
Regarding the communication from Python to MATLAB, you may consider Python Engine:
This feature was introduced in R2014b.
  2 comentarios
Ryan
Ryan el 28 de Ag. de 2015
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 el 21 de Jun. de 2018
Hi, you can send data from python to matlab?, Using a 'communication in real time?, is it possible with python engine or another tool?

Iniciar sesión para comentar.

Categorías

Más información sobre Block Libraries en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by