Main Content

Stateflow チャートを使用した空燃比制御システム

Simulink® と Stateflow® を使用して設計された空燃比制御システムのコードを生成します。

図 1、2、3 は、プラントとコントローラーを含む閉ループ システムである sldemo_fuelsys モデルの関連部分を示しています。プラントでは、設計の初期段階でのシミュレーション時にコントローラーを検証します。この例では、関連するコントローラー サブシステム "fuel_rate_control" のコードを生成します。図 1 は、最上位のシミュレーション モデルを示しています。

コマンド rtwdemo_fuelsys を使用してモデル sldemo_fuelsys を開きます。次に、モデルをコンパイルして信号のデータ型を確認します。

rtwdemo_fuelsys
sldemo_fuelsys([],[],[],'compile');
sldemo_fuelsys([],[],[],'term');

図 1: プラントとコントローラーの最上位モデル

空燃比制御システムは Simulink® と Stateflow® で構成されます。この制御システムはコードを生成するモデルの一部分です。

open_system('sldemo_fuelsys/fuel_rate_control');

図 2: 空燃比コントローラー サブシステム

制御ロジックは、さまざまな動作モードを指定する Stateflow® チャートです。

open_system('sldemo_fuelsys/fuel_rate_control/control_logic');

図 3: 空燃比コントローラーのロジック

これらのウィンドウを閉じます。

close_system('sldemo_fuelsys/fuel_rate_control/airflow_calc');
close_system('sldemo_fuelsys/fuel_rate_control/fuel_calc');
close_system('sldemo_fuelsys/fuel_rate_control/control_logic');
hDemo.rt=sfroot;hDemo.m=hDemo.rt.find('-isa','Simulink.BlockDiagram');
hDemo.c=hDemo.m.find('-isa','Stateflow.Chart','-and','Name','control_logic');
hDemo.c.visible=false;
close_system('sldemo_fuelsys/fuel_rate_control');

Embedded Coder® によるモデルの構成とビルド

量産 ANSI® C/C++ コードをモデル用に設定してビルドするには、モデル コンフィギュレーション パラメーター [システム ターゲット ファイル]ert.tlc (組み込みリアルタイム (ERT)) に設定します。[システム ターゲット ファイル] パラメーターをプログラムにより設定できます。

rtwconfiguredemo('sldemo_fuelsys','ERT');

コードを生成して検査します。関連するコード セグメントには [前へ] ボタンと [次へ] ボタンを使用して対話形式で移動できます。チャートのコンテキスト メニュー (Stateflow® ブロックを右クリック) で、[C/C++ コード]、[C/C++ コードに移動] を選択します。プログラムで実行する場合は、rtwtrace ユーティリティを使用します。

slbuild('sldemo_fuelsys/fuel_rate_control');
rtwtrace('sldemo_fuelsys/fuel_rate_control/control_logic')
### Starting build procedure for: fuel_rate_control
### Successful completion of build procedure for: fuel_rate_control

Build Summary

Top model targets built:

Model              Action                       Rebuild Reason                                    
==================================================================================================
fuel_rate_control  Code generated and compiled  Code generation information file does not exist.  

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

ans =

    '&sid=sldemo_fuelsys:107&inputLocs={"data": [{"file": "fuel_rate_control.c", "line": ["21","168","331","435","440","443","444","445","448","449","450","453","454","455","458","461","464","467","470","473","476","479","482","485","488","491","492","493","494","495","499","500","501","502","503","504","505","506","507","508","511","512","513","519","520","522","523","524","525","526","529","530","536","537","539","540","548","549","550","551","552","553","554","555","558","559","564","565","566","567","573","574","575","576","577","578","581","582","586","592","593","594","595","596","597","598","599","602","603","608","609","610","616","617","619","620","621","622","625","626","630","636","637","638","639","640","641","642","643","646","647","653","654","655","656","659","660","661","662","664","672","673","675","676","677","678","681","682","686","692","693","696","697","701","853","855","858","859","860","861","862"]},{"file": "fuel_rate_control.h", "line": ["36","41","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","67"]}]}'

生成されたコードで空燃比制御ロジックを確認します。

rtwdemodbtype('fuel_rate_control_ert_rtw/fuel_rate_control.c',...
    '/* Function for Chart:','case IN_Warmup:',1,0);
/* Function for Chart: '<S1>/control_logic' */
static void Fueling_Mode(const int32_T *sfEvent)
{
  switch (rtDWork.bitsForTID0.is_Fueling_Mode) {
   case IN_Fuel_Disabled:
    rtDWork.fuel_mode = DISABLED;
    switch (rtDWork.bitsForTID0.is_Fuel_Disabled) {
     case IN_Overspeed:
      /* Inport: '<Root>/sensors' */
      if ((rtDWork.bitsForTID0.is_Speed == IN_normal) && (rtU.sensors.speed <
           603.0F)) {
        if (rtDWork.bitsForTID0.is_Fail != IN_Multi) {
          rtDWork.bitsForTID0.is_Fuel_Disabled = IN_NO_ACTIVE_CHILD;
          rtDWork.bitsForTID0.is_Fueling_Mode = IN_Running;

          /* The fuel is actively controlled while in this state. */
          switch (rtDWork.bitsForTID0.was_Running) {
           case IN_Low_Emissions:
            rtDWork.bitsForTID0.is_Running = IN_Low_Emissions;
            rtDWork.bitsForTID0.was_Running = IN_Low_Emissions;
            rtDWork.fuel_mode = LOW;
            switch (rtDWork.bitsForTID0.was_Low_Emissions) {
             case IN_Normal:
              rtDWork.bitsForTID0.is_Low_Emissions = IN_Normal;
              rtDWork.bitsForTID0.was_Low_Emissions = IN_Normal;

              /* All sensors are in correct operating modes, so effective closed-loop mixture control can be used. */
              break;

モデルおよびコード生成レポートを閉じます。

clear hDemo;
rtwdemoclean;
close_system('sldemo_fuelsys',0);

関連する例

sldemo_fuelsys を使用した関連する固定小数点の例については、以下を参照してください。