Run Matlab script automatically in parallel to simulation

6 Ansichten (letzte 30 Tage)
Florian Bayer
Florian Bayer am 25 Nov. 2020
Kommentiert: Smriti Mehrotra am 3 Mär. 2022
Hi,
I'm simulating a rocket with an iterative guidance scheme. The equations of motion shall be evaluated continiously while guidance updates shall be taken into account as soon as they are available, until then the old parameters shall be used. I am not quite sure how to do this. My current solution is to run a script manually in parallel to the simulink model, reading the output, calcualting guidance updates and updating those parameters for the simulink model. Is there a way to automatically run the script in parallel when starting the simulation? Or are there better ways to include the guidance scheme into the model?
Thanks,
Flo

Antworten (1)

Kiran Felix Robert
Kiran Felix Robert am 16 Dez. 2020
Hi Florian,
I understand that you want to include a MATLAB Function (script) to be executed while your simulation is in execution. Refer the MATLAB Function block, which you can add it to the simulation loop. Also refer the Model Callbacks – PauseFcn / ContinueFcn to call a MATLAB script from the Simulink model.
Also refer the Run Multiple Simulations and Parallel Computing Toolbox Documentations, and to answers here and here for more information.
Kiran Felix Robert
  2 Kommentare
Florian Bayer
Florian Bayer am 16 Dez. 2020
Thanks for the reply. As I understand it a MATLAB function block evaluates its content within the current timestep. The script I'm running takes several seconds to converge to a set of guidance parameters. I do not want to halt the simulation so that each timestep takes as long as the script takes. Instead I want the simulation to keep running and only use the newly calculated parameters as soon as they are available.
I got it to work by forcing Simulink to write its logs so I have access to the current rocket states with
set_param(bdroot,'SimulationCommand','WriteDataLogs');
Then the script determains the new guidance parameters while the rocket continues to fly. At the end of the script I update the Simulink constants with
set_param(bdroot,'SimulationCommand','update');
Running this script in a while loop gets me what I want but I thought there was a more elegant way.
Smriti Mehrotra
Smriti Mehrotra am 3 Mär. 2022
Hi Florian,
Could you please expand on how you ran your matlab script and simulation? I'm trying to send the outputs of a tcp/ip block , transformed into a current profile (spreadhseet), into a signal builder to send into a model of an EV. I need to tcp socket, a matlab script and a simulation at the same time.
Any adivse would be really appreciated!
Thanks,
Smriti

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Event Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by