メインコンテンツ

プロジェクトでのコードの生成とモデルのシミュレーション

R2026b

この例では、新規プロジェクト用のコード生成テンプレートの使用方法を示します。プロジェクト用のコード生成プロジェクト テンプレートには複数のモデルが含まれます。プロジェクト テンプレートは、コントローラー コードの生成とハーネス モデルのシミュレーションの実行に役立つユーティリティ (.m スクリプト) も提供します。

プロジェクトの作成

コード生成プロジェクトのテンプレートから新しいプロジェクトを作成します。

このプロジェクトを Simulink® スタート ページから作成するには、コマンド ウィンドウで以下を入力します。

simulink

スタート ページからコード生成テンプレートを選択し、exampleCodeGen プロジェクトを作成します。

コードの生成

feedback_control.slx モデルのコントローラー コードを生成します。

コントローラー コードを生成するには、[プロジェクトのショートカット] タブを選択し、コントローラー コードの生成ショートカットを選択します。

このショートカットは、プロジェクトの utilities フォルダーにある generate_controller_code.m スクリプトを実行します。このスクリプトは、プロジェクトの controller フォルダーの feedback_control.slx モデルをビルドします。

### Searching for referenced models in model 'feedback_control'.
### Unable to find Simulink cache file "feedback_control.slxc".
### Total of 1 models to build.
### Starting top model code generation target build for: feedback_control
### Build reason: "feedback_control.c" did not exist.
### Build folder for generated code: /tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw
### Invoking Target Language Compiler on feedback_control.rtw
### Using System Target File: /mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/ert/ert.tlc
### Loading TLC function libraries
.......
### Generating TLC interface API for custom data
.
### Initial pass through model to cache user defined code
### Caching model source code
.................................
### Writing header file feedback_control_types.h
### Writing header file feedback_control.h
### Writing header file rtwtypes.h
### Writing source file feedback_control.c
.
### Writing header file feedback_control_private.h
### Writing source file feedback_control_data.c
### Writing source file ert_main.c
### TLC code generation complete (took 1.926s).
.### Creating HTML report file index.html
### Saving binary information cache.
### Using toolchain: GNU gcc/g++ | gmake (64-bit Linux)
### Creating '/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw/feedback_control.mk' ...
### Building 'feedback_control': "/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/bin/glnxa64/gmake"  -j 4 -l 4 -f feedback_control.mk all
gcc -c -fwrapv -fPIC -Wno-error=incompatible-pointer-types -Wno-error=stringop-overflow -O0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DMODEL=feedback_control -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen -I/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/extern/include -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/simulink/include -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/src -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/src/ext_mode/common -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/ert -o "feedback_control.o" "/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw/feedback_control.c"
gcc -c -fwrapv -fPIC -Wno-error=incompatible-pointer-types -Wno-error=stringop-overflow -O0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DMODEL=feedback_control -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen -I/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/extern/include -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/simulink/include -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/src -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/src/ext_mode/common -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/ert -o "feedback_control_data.o" "/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw/feedback_control_data.c"
gcc -c -fwrapv -fPIC -Wno-error=incompatible-pointer-types -Wno-error=stringop-overflow -O0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DMODEL=feedback_control -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen -I/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/extern/include -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/simulink/include -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/src -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/src/ext_mode/common -I/mathworks/devel/bat/filer/batfs2566-0/Bdoc26b.3351752/build/runnable/matlab/rtw/c/ert -o "ert_main.o" "/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/codegen/feedback_control_ert_rtw/ert_main.c"
### Creating standalone executable "../feedback_control" ...
g++  -o ../feedback_control feedback_control.o feedback_control_data.o ert_main.o -Wl,--start-group   -Wl,--end-group
### Created: "../feedback_control"
### Successfully generated all binary outputs.
gmake: Nothing to be done for `all'.
### Successful completion of build procedure for: feedback_control
### Simulink cache artifacts for 'feedback_control' were created in '/tmp/Bdoc26b_3351752_2634458/tp19ba529d/simulinkcoder-ex70644236/projects/templateCodeGen/work/cache/feedback_control.slxc'.

Build Summary

Top model targets:

Model             Build Reason                                Status                        Build Duration
==========================================================================================================
feedback_control  Target (feedback_control.c) did not exist.  Code generated and compiled.  0h 0m 10.379s

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 10.936s

モデルのシミュレーション

最上位レベルのハーネス feedback_harness.slx モデルをシミュレートします。

シミュレーション用にハーネス モデルを開くには、[プロジェクトのショートカット] タブを選択し、[Feedback Harness] ショートカットを選択します。このショートカットは、プロジェクトの harnesses フォルダーの feedback_harness.slx モデルを開きます。

モデルをシミュレートするには、[実行] をクリックします。

シミュレーション出力の確認

モデル内の Scope ブロックを開き、シミュレーション出力を確認します。

スコープを開いてシミュレーションを確認するには、Simulink ウィンドウで Scope ブロックをダブルクリックします。

依存関係アナライザー ビューの使用

ファイルの依存関係を表示するには、プロジェクトの依存関係アナライザー ビューを使用します。

依存関係アナライザー ビューでは、以下を実行できます。

  • ファイルの依存関係を確認する。

  • 依存関係の矢印にカーソルを合わせて、依存関係のタイプを確認する。

  • ファイルまたはモデルをダブルクリックして開く。

詳細

関連する例