(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