我需要运行simulink并设置超时和超时罚款。因此,我需要一个块来给我CPU时间(实际世界时间)。
时钟模块给出了模拟时间:
CAN超时检测是离散的,它不能与我的连续求解器一起使用。
Matlab功能块使模拟变得如此缓慢。
还有其他选择吗?
答案 0 :(得分:0)
通常在(加速)模拟中使用真实世界时钟并不是一个好主意。 这是一个使用m脚本设置超时的简单示例。它主要基于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
如果您不喜欢轮询,也可以使用callbacks实现,但这需要在模型中插入回调。