Running Simscape on the Computer and get Data from a TCP/Client.

3 views (last 30 days)
I want to couple a simscape Model in Simulink with a TCP Client for Software in the Loop testing. How can i execute Simscape on my Computer nearly in Real Time? How can i send data to the client with a fix Delay like 100ms. I tried a lot in the solvers, but i am far away from a good solution. I didnt want to use a hardware like speedgoat to execute my programm. I want to execute it on the computer and want to comunicate to a client on the network card. Is there any oppertunity to run the simulation with a constant timedelay (frequency). I wan to Send Data To the Client, and get Data from the Client an want to put the data into the simscape modell.
  2 Comments
Jonas
Jonas on 3 Jul 2020
Edited: Jonas on 3 Jul 2020
What is the sample time you are using to calculate the Simscape model?
Which domains have you implemented in Simscape?
For high sample rates and complex models you will need an FPGA with a SpeedGoat to be able to execute the Simscape model in real-time. Your desktop PC won't be able to reach the sample rate.
If you are calculating something like a slow temperature fluid model it may work, but certainly not for fast electrical systems for example.
David Mees
David Mees on 3 Jul 2020
Hello Jonas,
My sample time in simscape is 0.001 Seconds. If i go slover it gets faults. I used a Real Time Pacer, so the simulated time is near the real time. But one step in the timeline seams to be a half second. The changed values like Displayvalues and the timeline is updated in these time step.
The Simscape Modell is a gasmodell with a thermalmodell for a Airconditioning. It musst'nt be fast. A sampletime of 0.1 Seconds for the communication would be enough. I use LabVIEW for the client program and these client program should "talk and listen" to the modell.
So with the RT Pacer it works. I may have to implement SubySystems or Atomic Subsystems that the Values from the client are transmitted and recieved with a fix sample rate. And the Modell is triggerd from the communication.
Can you give hints, wihch way is the best to realize these?
I found a way to execute Matlab Code directly in LabVIEW,like these Link.
https://forums.ni.com/t5/Example-Code/Running-Compiled-Simulink-Models-in-LabVIEW-and-in-VeriStand/ta-p/3889270?profile.language=en
If its not possible to run it in Simulink, may i do not use the tcp communication, rather i execute the simscape modell in labview.
So i hope i will find a good solution :D

Sign in to comment.

Answers (1)

Vasco Lenzi
Vasco Lenzi on 9 Jul 2020
Hi David
As you anticipated the solution that will work for sure with robustness and precision is Speedgoat.
If this is not possible for any reason, you can try the Instrument Control Toolbox. It offers a Simulink Library of TCP/IP, Serial and UDP input/output blocks. This should do the trick.
If your model is not fast enought, you can try to speed up execution by isolating simscape within a subsytem and use simulink coder to transform it in a s-function. This will convert the Simscape network in a C-based "black box" that execute fast.
For the real time part, you can then use the new Real-Time pacing feature of simulink starting from 2018a
You don't need the RT Pacer block from aerospace blockset anymore.
Alternatively for real-time you can take a look at Simulink Desktop Real-Time, which creates a real-time kernel on your windows machine where the simulink model is executed at near real-time.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!