Run Matlab script automatically in parallel to simulation

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

回答(1 个)

Kiran Felix Robert
Kiran Felix Robert 2020-12-16
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 个评论
Florian Bayer
Florian Bayer 2020-12-16
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 2022-3-3
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by