2
votes

I am using a Simulink to collect data real-time from drop tests. The Simulink works great, but my vision is to have a Matlab (v.7.10) script run the simulation for several trials without me having to run over to the computer between drops. This also allows me to pre-process the data before saving it. Both programs work great individually, but I cannot make the Simulink run properly in a script. Using sim() returns the error message:

    Cannot perform command line simulation of 'acc_DAC' in external mode.

Using set_param(sys, 'SimulationCommand', 'start') starts the simulation, but does not block the script. The script continues and returns errors because the outputs it is supposed to have don't exist yet. Notably, I read elsewhere that pausing Matlab will pause any simulations as well, though I couldn't get that far myself.

The Simulink runs until the impact is measured, and then stops and outputs accelerometer data to the workspace. What I am asking is:

A) Is there a way to sim() run an external, real-time simulation?

B) Is there a good way to make Matlab wait for either Simulink to finish, or variables to exist, without pausing the Simulink?

2
I took a shot at this tutorial. I got init_sim and start to work, and the simulation would finish and unload, but the script wouldn't progress any further. My guess is that the evalin command I stuck in the end of the Simulink wasn't working properly but have no idea where to go with that. - Spencer Williams

2 Answers

1
votes

You could try checking the SimulationStatus of the running model, and loop until it says stopped, although you'll need to be a little careful as there's a chance of entering an infinite loop.

Something like

set_param(sys,'SimulationCommand','start');
while ~strcmp(get_param(sys,'SimulationStatus'),'stopped')
    drawnow
end

The above will not work in any simulation mode, but may work in external mode.

0
votes

After a week of fiddling with timers and event callbacks, I found that if this is possible, it is absurdly difficult to do. Ultimately I created two functions, one that starts the simulation and one that processes the data output by the first. I have to run them manually, but its not that big of a deal for me. Hopefully this will help someone!