バックナンバーはこちら
https://www.simulationroom999.com/blog/model-based-of-minimum-backnumber/
はじめに
前回でCANoeにてネットワークシミュレーションができ状態になった。
今回はCANoe内で定義されているシグナルをSimulinkモデルから更新するための準備となる。
登場人物
博識フクロウのフクさん
![](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
イラストACにて公開の「kino_k」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=iKciwKA9&area=1
エンジニア歴8年の太郎くん
![](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者01アップ.png)
イラストACにて公開の「しのみ」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=uCKphAW2&area=1
前提条件
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/お休みフクロウ.png)
今回はSimulinkモデルをいじることにあるのだが。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」08アップ.png)
待ってました!
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
その前に、これをやるための前提条件がある。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」13アップ.png)
え?!
なに?
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
まず、SimulinkCoderが必要。
そして、CANoeをインストールする時に
「MATLABコンポーネント」を追加インストールしている状態であること。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」20アップ.png)
SimulinkCoderは大丈夫だけど、
CANoeの「MATLABコンポーネント」はどっかで見たような・・・。
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/お休みフクロウ.png)
入れて無かったら、先に入れておいて。
~10分後~
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
良し。
「MATLABコンポーネント」はちゃんとインストールできたよ。
ライブラリブラウザでVector CANoeブロックの確認
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
MATLABを起動して、Simulinkライブラリブラウザを見てみよう。
下の方にVector CANoeって項目はある?
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
うん。あったよ。
その中に「CANoe I/O」と「Communication Objects」ってのがあるみたいだけど。
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/お休みフクロウ.png)
今回は「CANoe I/O」の方を使用する。
![Simulinkライブラリブラウザ―でCANoe I/Oを選択](https://www.simulationroom999.com/blog/wp-content/uploads/2020/06/02_CANoeIO-1024x757.png)
PIDコントローラへCANoeブロック接続
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
では、PIDコントローラに対して、
入力側にSignal Inputのブロック、
出力側にSignal Outputのブロックを接続する。
自動モードの切り替えやドライバからの操作は今回は固定値にしておこう。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
こんな感じで良い?
![CAN I/OのSignal InputとSignal OutputをSimulinkモデルinput、putputに接続](https://www.simulationroom999.com/blog/wp-content/uploads/2020/06/03_PIDにSignal接続.png)
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
良いね。
そして、各Signal inputをダブルクリックして、
開いたウィンドウの下の方に「Select signal」というのがある。
これを押すとCANoe側で定義されているシグナルが選択できる状態になる。
![CANoe側で定義しているシグナルにCAN I/Oを紐づけることができる。](https://www.simulationroom999.com/blog/wp-content/uploads/2020/06/04_SignalInputBlockWindow-1024x453.png)
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
あー。
これで適切なシグナルを選択していくんだね。
できたよ。
プラントへCANoeブロック接続
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
次はプラントの方だけど、
やり方はコントローラの時と一緒だよ。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
うん。同じようにやってみる。
![プラントモデルにCANoe I/Oを接続](https://www.simulationroom999.com/blog/wp-content/uploads/2020/06/05_プラントにSignal接続.png)
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
これでOKかな?
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/まるフクロウ.png)
OKだね。
SimulinkDLLの作成
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/お休みフクロウ.png)
次にCANoeに組み込むためのDLLを作成する。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」13アップ.png)
どうやって?
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
特に複雑な手順は無いよ。
まずは「モデルコンフィグレーションパラメータ」を開く。
右側のツリーな中のコード生成を選択。
ターゲット選択の中からcn.tlcを選択する。
そして右下の方のビルドを押す。
![Simulinkのコンフィグレーションパラメータからコード生成。システムターゲットファイルはn.tlcを選ぶことでCANoe向けのSimulink.DLLが生成される。](https://www.simulationroom999.com/blog/wp-content/uploads/2020/06/06_コード生成-1024x549.png)
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
押したよ。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」13アップ.png)
押したよ。
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
うん。コンパイルされてDLLが完成したはずだよ。
モデルファイルが置いてあるディレクトリから見て、
<モデル名>_CANoe_cn_rtw\release
に、DLLが出来上がってるはず。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者03アップ.png)
あ!あった。
これがSimulinkDLL?
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/お休みフクロウ.png)
そう。
CANoeのノードに割り付けができるよ。
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
割り付けの前にプラント側も同じ作業をやっておこう。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者a」05アップ.png)
了解。
~5分後~
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者01アップ.png)
プラント側のDLLもできたよ。
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
よし、
次はCANoeにそのDLLを組み込む。
CANoeへSimulinkDLLを組み込む
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
まず、CANoeのシミュレ―ション設定の中のノードを右クリックすると
「設定」ってのが出てくると思う。
これを選択すると「ノード設定」というウィンドウが出て、
その中のタブの「Simulink」を選ぶ。
そして、以下のPathを設定する。
- Simulinkモデル(slx)
- モデルビューア情報(ini)
- RTWモデル(DLL)
![CANoeのネットワークノードにSimulinkDLLを割り当てる](https://www.simulationroom999.com/blog/wp-content/uploads/2020/06/07_ノード設定.png)
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」13アップ.png)
DLLは分かるけど他の情報は何?
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/考え中フクロウ.png)
私も正確なことは分からないが、
slxはDLLよりもslxの方が更新されていることを検知するため、
iniはCANoe上でSimulinkモデル及び各種データを参照する際の位置情報を保持するため、
のものと思ってる。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/技術者02アップ.png)
まぁ、とりあえず設定しておけば良いね。
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/お休みフクロウ.png)
そろそろ、しゃべり疲れてきたんで、
動作させるのは次回かな。
![太郎くん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/「技術者a」20アップ.png)
えー!
これから面白くなりそうなのに。
まとめ
![フクさん](https://www.simulationroom999.com/blog/wp-content/uploads/2020/05/指差しフクロウ.png)
まとめだよ。
- CANoeに組み込むSimulinkDLLを作成するにはSimulinkCoderとCANoeのMATLABコンポーネントが必要。
- Simulinkモデルの入出力にCANoe IOのSingnal Input/Outputを接続してSignalを読んだり更新したりできる。
- SimulinkDLLはCANoeの各ノード毎に設定できる。
バックナンバーはこちら
コメント