(Simulink) How can I communicate with hardware (Arduino, Raspberry Pi, I2C, etc.) in real time?

8 visualizaciones (últimos 30 días)
I am running a Hardware in the Loop test with Simulink and would like to control Arduinos, Raspberry Pis, as well as recieve information from I2C devices. I would like for my personal computer to run the simulation as it is large and computationally intensive, however I would like to communicate Simulink values to the mentioned hardware. I am aware that there are Arduino and Raspberry Pi support software, however I believe that they only allow the Hardware to run the models, and do not seem to be able to let the hardware recieve data. I am also aware that the Real Time add-on exists, but the documentation only deals with the Speedgoat software, and I am unsure of whether it would work with other hardware. There is also the Digital Output blocks and Serial Send blocks from the Data Acquisition and HDL Coder packages, however I am unsure if they will connect to the Arduino or Raspberry Pi.
I would like to know what is my best option to have my computer run the simulation and have it export the data in real time to hardware, and also for the hardware to give data in real time for the simulation to use.

Respuestas (2)

Madhu Govindarajan
Madhu Govindarajan el 10 de Sept. de 2018
Editada: Madhu Govindarajan el 10 de Sept. de 2018
Here is my attempt to answer the questions that you have -
1) MCUs such as Arduino cannot run "hard" real-time as they do not have dedicated real-time Operating system monitoring them. Simulink Real-time to my knowledge works only with devices that have real-time OS such as Speedgoat so that is probably not the way to go for Arduinos and such.
2) That being said, MCUs can still do "soft" real-time. To communicate between Simulink models and Arduinos, serial send and receive are a great way. You can have a simulink model that uses serial send to send appropriate data and on the Arduino side, deploy a model from Simulink that has serial receive and possibly whatever algorithm that you want your Arduino to respond to these requests.
HTH,
Madhu
  3 comentarios
Madhu Govindarajan
Madhu Govindarajan el 11 de Mzo. de 2019
The simulation mode should not impact the communication, ensure your solver step time and sampling time of serial send are going to match with the expectations on the receiver side.
Gao Yang
Gao Yang el 6 de Feb. de 2020
Hello,sir! I also met the simialr problem. I have used the python to code a UDP server in python to receive the real-time simulation datas. How do you parse these datas in python and send them back to simulink?

Iniciar sesión para comentar.


Gao Yang
Gao Yang el 6 de Feb. de 2020
Hello,sir! I also met the simialr problem. I have used the python to code a UDP server in python to receive the real-time simulation datas. How do you parse these datas in python and send them back to simulink?

Categorías

Más información sobre Run on Target Hardware en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by