Can I use data from the OPC toolbox to run a real time simulation with Simulink Desktop Real-Time using a model that I created with Simscape?

10 views (last 30 days)
I'm creating a model using Simscape and I want to use real time data coming from a PLC to run a simulation using the Simulink Desktop Real-Time and the model created with Simscape, is it posible? Is there another way to get this real time data from the PLC?
I'm basically trying to develop a digital twin (using historical and real time data) for optimization purposes.
Matheus Andrade
Matheus Andrade on 10 Jul 2020
Edited: Matheus Andrade on 10 Jul 2020
Hi, Vasco! Thank you for the reply.
I'm actually using Matlab/Simulink for the first time and I'm not working on it yet because my university is not working,.so I might not have some of the answears you want, I'll try my best!
1) It will be probably a Siemens S7 1200 PLC, but it could be the Rockwell Micro850.
2) I don't know for sure, but my university have one of the latest, 2018 or 2019 I guess.
3) It could be OPC UA that is more recent. But it is not a "must-have", I found out that it could be the easiest, but I'm not stuck with it. It would be used just to provide some data from PLC to Simulink.
4) I don't have a model yet, but just for you to have a way to measure it, this will be the digital twin of a steam distilation system, so my variables don't change so fast and my simulation doesn't have to work so fast.
I hope this is enough to make you understand!

Sign in to comment.

Accepted Answer

Vasco Lenzi
Vasco Lenzi on 13 Jul 2020
Hi Matheus
Thank you for the additional information.
1) Deployment on PLC Itself:
First of all, with most PLC you can generate C code from the model and integrate it into the PLC itself. For instance for Siemens Simatic STEP7:
Usually the code generate is from a controller/state machine, but you can as easily generate code from a physical model of your plant ("digital twin") this would be then run on the PLC itself, with no hassle regarding the communication. A disadvantage would be the reduced possibility to perform optimization of parameters, because of the few computing ressources available on the PLC, depending on your application.
2) Industrial communication - OPC DA
Your idea of using OPC Toolbox and Simulink Desktop Real-Time is a valid one. Simulink Blocks of the OPC toolbox only exist for OPC DA. So you would need to setup the OPC DA, use the block in the model and then run it with Simulink Desktop Real-Time. This is good for simulations that requires a slow time-step such as 1-100 ms.
3) Industrial Communication - MODBUS-TCP/IP
This is particularly good for Siemens PLC. If the PLC suppots MODBUS or TCP/IP, you can use the Instrument Control Toolbox to setup a connection between Simulink and the PLC, and deploy it in near-real-time using Simulink Destop Real-Time. Modbus is supported through MATLAB command, but you may use them in a MATLAB function block in Simulink.
see an example here of controlling a PLC using MODBUS Explorer:
4) If hard real-time is a requirement, you may need to go through Simulink Real-Time and a Speedgoat machine
Hope this gives you some inputs and food for thought!
Matheus Andrade
Matheus Andrade on 14 Jul 2020
This digital twin you talked about may be somehow like mine.and it can help me a lot! Thank you for all the support!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by