I need to run simulink and set a timeout and a penalty on time out. Hence, I need a block to give me the CPU time (real world time).
The clock block gives the simulation time:
The CAN timeout detection is discrete and it does not work with my continuous solver.
The Matlab function blocks make simulation so slow.
Is there any alternative?
Typically using a real world clock in an (acceleralted) simulation is not a good idea. Here is a simple example using a m-script to set a timeout. It's primarily based on this documentation page
model='untitled';
timeout=10;
set_param(model,'SimulationCommand','start')
tic;
while(true)
if not(strcmpi(get_param(model,'SimulationStatus'),'running'))
disp('simulation exited')
break;
end
if toc>=timeout
disp('timout reached')
set_param(model,'SimulationCommand','stop')
break;
end
pause(1);
end
If you don't like polling, this could also be implemented using callbacks, but this requires inserting a callback into your model.