Run Matlab script automatically in parallel to simulation

조회 수: 4 (최근 30일)
Florian Bayer
Florian Bayer 2020년 11월 25일
댓글: Smriti Mehrotra 2022년 3월 3일
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