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

7 次查看(过去 30 天)
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.

回答(2 个)

Madhu Govindarajan
Madhu Govindarajan 2018-9-10
编辑:Madhu Govindarajan 2018-9-10
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 个评论
Madhu Govindarajan
Madhu Govindarajan 2019-3-11
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 2020-2-6
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?

请先登录,再进行评论。


Gao Yang
Gao Yang 2020-2-6
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?

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by