Simulink Desktop Real-Timeの​​エクスターナルモー​ドを使用する際、外部 C/C++ コードを挿入する方法(外部として関数を宣言、S Function、C Caller、C Function)の違いを知りたい。

2 views (last 30 days)
IMUセンサから読み取ったデータをSimulink Desktop Real-Timeエクスターナルモードを使いリアルタイム計測・アクチュエータを使った制御を行いたいです。
IMUセンサにはC++で書かれたサンプルコードファイル(.h,.cppファイルが20個程度の規模)があり、これをsimulinkに組み込むことを考えています。
調べた限りでは以下の3つの方法があるようですが、Simulink Desktop Real-Timeのエクスターナルモードで使用可能かどうかと、使い方の違い・メリットを教えていただきたいです。
・外部コードからmexファイル( MEX 関数)を作成し、MATLAB Functionの中で「外部として関数を宣言」して実行
 https://jp.mathworks.com/help/simulink/slref/coder.extrinsic.html
・外部コードからS Functionブロックを作成し実行
https://jp.mathworks.com/help/simulink/slref/legacy_code.html
・C Caller、C FunctionからSimulink で C コードを統合(Simulink Desktop Real-Timeで使えるか未確認)  
 https://jp.mathworks.com/help/simulink/integrate-external-c-algorithms-using-c-function-block.html
 https://jp.mathworks.com/help/simulink/slref/ccaller.html

Accepted Answer

Toshinobu Shintai
Toshinobu Shintai on 29 Jun 2022
こちらで説明されているものが、Simulink Desktop Real-Time のエクスターナルモードの説明資料になります。エクスターナルモードは、モデルを Simulink Coder でコード生成し、コンパイラでビルドしてカーネルモードプロセスで実行します。
この時、例えばWindowsであれば、MinGW か Microsoft Visual C++ のコンパイラを使ってビルドを行うと思います。これらのコンパイラでビルドできるCコードであれば、S-Function、C Caller、C FunctionにてC言語のコードを呼び出すモデルをエクスターナルモードで実行することができます。
  4 Comments
Toshinobu Shintai
Toshinobu Shintai on 29 Jun 2022
Edited: Toshinobu Shintai on 29 Jun 2022
外部として関数を宣言「coder.extrinsic」はコード生成に対応していませんので、おそらく無理かと思います。
S-Function、C Caller、C Function は大丈夫です。
健吾 織田
健吾 織田 on 29 Jun 2022
ご回答ありがとうございます。
承知しました。
S-Function、C Caller、C Functionを利用するようにします。

Sign in to comment.

More Answers (0)

Categories

Find more on コード生成 in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!