標籤:

如何優雅地搭建Simulink模型?

Simuilnk里的模型代碼總覺得會挺不美觀,想請教有沒有更好的優化模型的方法,或是讓自己的模型看起來更加簡潔而非各種信號線亂飛。。主要是用在基於模型設計里的自動代碼生成部分


2017/1/9 更新

新版本的JMAAB對於模型架構的規定更加詳細,建議閱讀。

==============================================================

先看看MAAB建模規範,對於模型的層次劃分、信號與模塊的使用方式均有說明,對於MAAB的介紹可見Industry Standards,裡面有下載鏈接。有興趣的可以自己下下來看,總共136頁。這個文檔我列印了好幾次,總是迷之遺失,然後我再打一份放在手頭備用。(另一個類似的文檔是SAE J670:汽車動力學術語)

dSPACE也有一份規範叫dSPACE Modeling Guidelines 3.0,如果要用TargetLink,還是應該參考一下。

==============================================================

以下簡單的說明MAAB建議相關企業強制使用的模型架構:

  1. 依據是否存在觸發層,將模型架構分為TypeA和TypeB兩類,主要包括頂層、觸發層、結構層和數據流層

  2. 頂層規定模型總體的輸入輸出(相當於模型的對外介面,也是在自動代碼生成後與底層軟體聚集成的借口),建議通過注釋對實現的功能進行描述

  3. 觸發層通過觸發子系統或函數調用子系統說明調用時序

  4. 結構層說明子模塊之間的關係,注意,這一層中的子模塊必須是原子子系統

  5. 數據流層:這一層才是具體的計算,包括加減乘除之類的。

    ==============================================================

其他與模型可讀性相關的一些規範

7.1.3. db_0042: Port block in Simulink models

In a Simulink model, the ports comply with the following rules:

? Inports should be placed on the left side of the diagram, but they can be

moved in to prevent signal crossings.

? Outports should be placed on the right side, but they can be moved in to

prevent signal crossings.

? Duplicate Inports can be used at the subsystem level if required, but should

be avoided, if possible.

o Do not use duplicate Inports at the root level.

Notes on the incorrect model

? Inport 2 should be moved in so it does not cross the feed back loop lines.

? Outport 1 should be moved to the right hand side of the diagram.

7.1.12. db_0141: Signal flow in Simulink models

? Signal flow in a model is from left to right.

? Exception: Feedback loops

? Sequential blocks or subsystems are arranged from left to right.

? Exception: Feedback loops

? Parallel blocks or subsystems are arranged from top to bottom.

7.1.13. jc_0171: Maintaining signal flow when using Goto and From blocks

Visual depiction of signal flow must be maintained between subsystems.

? Use of Goto and From blocks is allowed if:

? At least one signal line is used between connected subsystems.

? Subsystems connected in a feed-forward and feedback loop have at

least one signal line for each direction.

? Using Goto and From blocks to create buses or connect inputs to merge blocks

are exceptions to this rule.

==============================================================

懶得粘了,Mathworks公司又不給我發工資,再加幾個圖示意一下就完事了

if-else架構

Switch架構:

模型初始化

子系統的方向

Incorrect

if-else flow實現

for loop flow實現


.

模型建不好,妹紙追不到。

題主,我覺得有必要教給你一點人生的經驗。

1、要有清晰的架構

一個模型通常由多個職責分工不同的子模塊組成,如果說一個子模塊是一片葉子,那麼架構混亂的模型就如一堆落葉,讓人無從下手。

所以模型一定要有清晰的架構;子模塊內部也要遵循「親密性」原則,讓彼此相關的項互相靠近,以幫助其他閱讀模型的人組織信息、理解模型。

2、對齊

對齊之前↓↓

對齊之後↓↓

3、盡量避免Line轉彎和交叉

普通青年↓↓

優雅的題主↓↓

要有避免轉彎和交叉的意識。

很多人在能力上沒什麼問題,但是缺乏這種意識,導致實現了需求就OK,對轉彎和交叉視而不見。4、不要有三種以上顏色

下圖丑爆了

建模是一種藝術。

尤其是單身的模型開發攻城獅們,如果長期提交混亂且丑爆了的模型,小心你心儀的測試媛背後談起你時說「那個2B啊,我知道,看到他的模型就頭大,他的測試我們真的不能拒收嗎?」

.


直接用S函數或者matlab function模塊寫;多用from和goto接線;多劃分子模塊


這玩意算是個藝術,現在回頭看我剛學習建模的時候,搭的是個鎚子!丑爆了。

模塊對齊、布局合理、線儘可能的不交叉、主路徑儘可能保持在一條線上,定義好每一層的顏色(類似觸發層、數據流層),大的模型多用form goto

也是間接培養自己的強迫症


推薦閱讀:

汽車電子運用目的,如何學習simulink?
怎樣實現不同控制演算法的切換?
用 simulink 模擬電機,電機的原理已經了解,但是之前沒用過 simulink 有什麼好的推薦快速上手 simulink 的?
使用simulink代碼生成,硬體底層函數自己寫更好,還是應該直接生成到目標晶元中?
怎樣提高simulink建模能力?

TAG:MATLAB | simulink |