欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Simulink 中 model advisor 檢查規則自定義

Model advisor 檢查規則自定義


1. Model advisor 檢查規則簡(jiǎn)介

model advisor是simulink自帶的靜態(tài)模型檢查器,能夠根據設定的規則對模型進(jìn)行檢查,并且能夠進(jìn)行部分錯誤的自動(dòng)修改。在汽車(chē)電子以及相關(guān)基于MBD(Model Based Design)開(kāi)發(fā)的嵌入式項目中有重要的作用,能夠幫助開(kāi)發(fā)人員和團隊搭建高質(zhì)量的模型和使用高度統一的風(fēng)格。自帶的檢查規則中,包含MAAB這種行業(yè)中應用廣泛的規則,隨著(zhù)團隊或者項目進(jìn)程的積累,后續會(huì )慢慢發(fā)展出屬于自己的一套建模規則和體系。此時(shí)則需要進(jìn)行對model advisor的檢查規則進(jìn)行自定義。

  • 下圖為Model advisor的界面截圖

2. 檢查規則自定義

自定義規則分兩種情況,一種是對現有規則進(jìn)行勾選,組合成團隊需要的檢查體系,另外一種是編寫(xiě)腳本,創(chuàng )建新的檢查規則。在確認現有檢查規則中無(wú)法滿(mǎn)足所需要的檢查,則可以進(jìn)行新規則的編寫(xiě)。例如:

  • 找出所有具有integer rounding mode 配置的模塊,并檢查這些模塊的這項配置是否配成Simplest。

這條模型檢查規則在官方自帶的檢查中就沒(méi)有,如果想要統一團隊風(fēng)格只能通過(guò)編寫(xiě)腳本或者組織人工審查,顯然作為程序員的我們對于這種選擇問(wèn)題的思考是不存在的,答案只有一個(gè),代碼擼起來(lái)。
本文主要針對這條規則需求進(jìn)行編寫(xiě)腳本的詳細說(shuō)明和示例。

2.1 創(chuàng )建新的規則及放到相應目錄中

既然是在model advisor中添加新的檢查規則,就需要將編寫(xiě)的檢查規則都放到統一文件夾目錄下,不能與其它檢查規則混用。

%--- test_int_round_mode_check function description----------------------------function test_int_round_mode_checkint_round_mode = ModelAdvisor.Check('int_round_mode');int_round_mode.Title = 'int_round_mode:Check the integer rounding mode 檢查整數舍入模式設定';int_round_mode.TitleTips = ['Fail if the rounding mode config is not <Simplest>'...                            '該模塊設置如果不為<Simplest>則判斷為違反本條規則'];int_round_mode.setCallbackFcn(@test_int_round_mode_checkCallback,'None','StyleOne');% publish the checkmdladvRoot = ModelAdvisor.Root;mdladvRoot.publish(int_round_mode,'TEST'); 

這些代碼定義了檢查規則的名字、簡(jiǎn)介、調用具體函數的句柄test_int_round_mode_checkCallback,并將這條規則發(fā)布在TEST文件夾下。

2.2 確定是否需要增加自動(dòng)修改功能

model advisor中,允許進(jìn)行部分規則的自動(dòng)修改,就是點(diǎn)一個(gè)按鈕直接把模型改的符合本條檢查規則,這個(gè)功能十分實(shí)用,尤其對于規模龐大的模型簡(jiǎn)直就是福音,所以回到本示例中,因為需要檢查的內容單一,規則明確,所以可以增加自動(dòng)修改的功能。當檢查出整數舍入模式?jīng)]有設置成Simplest的模塊,點(diǎn)擊一個(gè)按鈕,自動(dòng)將這些模塊舍入模式設成Simplest。

% fix action descriptionint_round_modeAct = ModelAdvisor.Action;int_round_modeAct.Name = 'Fix settings';int_round_modeAct.Description = ['Click the button to set all blocks to Simplest'...                                '按下按鈕,將所有模塊設置成 Simpleset'];int_round_modeAct.setCallbackFcn(@test_int_round_mode_checkActCallback);int_round_mode.setAction(int_round_modeAct);

這段代碼定義了修復按鈕,按鈕名字為Fix settings,點(diǎn)擊按鈕的句柄為test_int_round_mode_checkActCallback。

2.3 關(guān)鍵功能分析

  1. 對于模型中,相關(guān)模塊的查找,使用find_system(system,'RegExp','On','RndMeth','.'); 可以找出模型中所有具有 integer rouding mode 配置選項的模塊。
    • 其中system在腳本中表示當前檢查的模型
    • RegExp on 表示開(kāi)啟正則表達式
    • RndMeth 為模塊integer rounding mode選項的命令字
    • '.’ 指代正則表達式中,所有字符(不為空字符)
      綜上,這條命令是說(shuō),找到當前檢查模型中,所有’RndMeth’設置有任意字符的模塊。
  2. 使用get_param(all_rnd_meth_block{i},'RndMeth');得到模塊的整形舍入模式設定選項
  3. fix action 相關(guān)函數
    • 使用如下兩條命令創(chuàng )建修復列表模板和修復結果顯示
      int_round_mode_fc = ModelAdvisor.FormatTemplate('TableTemplate');
      int_round_mode_fc.setColTitles({'Block','Old Setting','New Setting'});
    • 使用如下命令在顯示面板上增加所修復的目標
      int_round_mode_fc.addRow({all_rnd_meth_block{i},current_rnd,correct_cfg_rnd});
    • 使用如下命令進(jìn)行模塊整數舍入模式選項的設置
      set_param(all_rnd_meth_block{i},'RndMeth',correct_cfg_rnd);
  4. 腳本的文件名字一定要為sl_customization.m ,并且在將規則添加到model advisor中要使用sl_refresh_customizations這條命令,在不打開(kāi)模型的條件下執行這條命令,這些是官方規定的操作,不能有改動(dòng)。

2.4 腳本源碼示例

%------------------------------------------------------------------------------%   Simulink scrip for customer check which used in model advisor.%   MATLAB version: R2017a%   Shibo Jiang    2017/8/20%   Version: 0.1%   Instructions: Type the 'sl_refresh_customizations' in matlab command %                 window with all the model closed. %------------------------------------------------------------------------------function sl_customization(cm)% --- register custom checkscm.addModelAdvisorCheckFcn(@test_int_round_mode_check);%-----Start of test_int_round_mode_check---------------------------------------    %--- test_int_round_mode_check function description------------------------    function test_int_round_mode_check    int_round_mode = ModelAdvisor.Check('int_round_mode');    int_round_mode.Title = 'int_round_mode:Check the integer rounding mode';    int_round_mode.TitleTips = ['Fail if the rounding mode config is not ' ...                                                                 '<Simplest>'];    int_round_mode.setCallbackFcn(@test_int_round_mode_checkCallback, ...                                  'None','StyleOne');    % fix action description    int_round_modeAct = ModelAdvisor.Action;    int_round_modeAct.Name = 'Fix settings';    int_round_modeAct.Description = ['Click the button to set all blocks' ...                                                              ' to Simplest'];    int_round_modeAct.setCallbackFcn(@test_int_round_mode_checkActCallback);    int_round_mode.setAction(int_round_modeAct);                            % publish the check    mdladvRoot = ModelAdvisor.Root;    mdladvRoot.publish(int_round_mode,'TEST');     %--------------creates test_int_round_mode_checkCallback function----------    function int_round_mode_result = test_int_round_mode_checkCallback(system)    int_round_mode_obj = Simulink.ModelAdvisor.getModelAdvisor(system);    int_round_mode_result={};    int_round_mode_fc = ModelAdvisor.FormatTemplate('ListTemplate');    int_round_mode_fc.setInformation(['This check looks for the blocks' ...               ' which integer rounding mode is not configed as [Simplest]']);    % find all blocks which have 'integer ronuding mode' setting    all_rnd_meth_block = find_system(system,'RegExp','On','RndMeth','.');    wrong_rnd_flag = 0;    if ~isempty(all_rnd_meth_block)        % find wrong config block        length_rnd = length(all_rnd_meth_block);        j = 1;        correct_cfg_rnd = 'Simplest';        for i = 1:length_rnd            current_rnd = get_param(all_rnd_meth_block{i},'RndMeth');             if 0 == strcmp(correct_cfg_rnd,current_rnd)                 wrong_rnd_flag = 1;                wrong_rnd_block{j} = all_rnd_meth_block{i};                j = j + 1;            else                % Do nothing            end        end    else        wrong_rnd_flag = 0;    end    % report finding results    if 0 == wrong_rnd_flag        int_round_mode_fc.setSubResultStatusText(['Check has passed.']);        int_round_mode_fc.setSubResultStatus('pass');        int_round_mode_obj.setCheckResultStatus(true);     else        int_round_mode_fc.setSubResultStatusText(['Check has failed.' ...                             ' The integer rounding mode config is wrong']);        int_round_mode_fc.setListObj(wrong_rnd_block);        int_round_mode_fc.setSubResultStatus('warn');        int_round_mode_fc.setRecAction(['Config the integer rounding' ...                                                  ' mode as [Simplest] .']);        int_round_mode_obj.setCheckResultStatus(false);         int_round_mode_obj.setActionEnable(true);    end    int_round_mode_fc.setSubBar(0);    int_round_mode_result{end+1} = int_round_mode_fc;      %--------------creates test_int_round_mode_checkActCallback function-------    function int_round_mode_ActResult = ...                                  test_int_round_mode_checkActCallback(taskobj)    int_round_mode_obj = taskobj.MAObj;    int_round_mode_ActResult = {};    system = getfullname(int_round_mode_obj.System);    int_round_mode_fc = ModelAdvisor.FormatTemplate('TableTemplate');    int_round_mode_fc.setColTitles({'Block','Old Setting','New Setting'})    % find all blocks which have 'integer ronuding mode' setting    all_rnd_meth_block = find_system(system,'RegExp','On','RndMeth','.');    % fix wrong config block    length_rnd = length(all_rnd_meth_block);    correct_cfg_rnd = 'Simplest';    for i = 1:length_rnd        current_rnd = get_param(all_rnd_meth_block{i},'RndMeth');         if 0 == strcmp(correct_cfg_rnd,current_rnd)             int_round_mode_fc.addRow({all_rnd_meth_block{i}, ...                                         current_rnd,correct_cfg_rnd});            set_param(all_rnd_meth_block{i},'RndMeth',correct_cfg_rnd);        else            % Do nothing        end    end    int_round_mode_fc.setSubBar(0);    int_round_mode_ActResult = int_round_mode_fc;      int_round_mode_obj.setActionEnable(false);%----End of test_int_round_mode_check -----------------------------------------

2.5 效果展示

  1. 將腳本放到matlab工作目錄下,然后在命令窗口輸入sl_refresh_customizations。

  2. 打開(kāi)模型,并打開(kāi)model advisor


    可以看到,我們編寫(xiě)的規則已經(jīng)在 By Product/TEST目錄下了

  3. 點(diǎn)擊檢查本條規則


    可以看到檢查結果,并能夠鏈接到模型上相應的模塊。

  4. 點(diǎn)擊修復按鈕


    能夠看到修復的結果

  5. 再次點(diǎn)擊檢查按鈕,驗證本條規則是否通過(guò)

    可以發(fā)現已經(jīng)正確修改,本條規則已經(jīng)檢查通過(guò)了。

3. 備注

編寫(xiě)的規則存在一些使用上的bug,和Matlab版本有關(guān),例如在Matlab2017a中,僅在第一次打開(kāi)matlab時(shí)才能使用sl_refresh_customizations命令進(jìn)行model advisor的規則更新,如果修改了腳本代碼,再次進(jìn)行更新則會(huì )失敗,此時(shí)需要重啟Matlab才能更新,而這個(gè)問(wèn)題在Matlab2016a中不存在。 

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
cad點(diǎn)坐標導出到excel表格再轉成經(jīng)緯度格式(附下載)
ffmpeg 中av_rescale_rnd 的含義
BigDecimal除法注意事項
Philomina the Flamingo
Excel舍入函數簡(jiǎn)介
VBA產(chǎn)生特定范圍內的隨機數 | VBA實(shí)例教程
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久