首页 文章

在simulink期间访问CPU时间?

提问于
浏览
2

我需要运行simulink并设置超时和超时罚款 . 因此,我需要一个块来给我CPU时间(实际世界时间) .

Real world time

时钟模块给出了模拟时间:

Simulink Clock block

CAN超时检测是离散的,它不适用于我的连续求解器 .

Simulink CAN timeout

Matlab功能块使模拟变得如此缓慢 .

还有其他选择吗?

1 回答

  • 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实现,但这需要在模型中插入回调 .

相关问题