コマンド ラインを使用したモデルの固定小数点への変換
この例では、コマンド ラインを使用してモデルのデータ型を調整する方法を示します。
fxpdemo_feedback
モデルを開きます。
model = 'fxpdemo_feedback';
open_system(model);
Controller サブシステムは固定小数点データ型を使用します。
sud = 'fxpdemo_feedback/Controller';
open_system(sud)
DataTypeWorkflow.Converter
オブジェクトを作成して、fxpdemo_feedback
モデルの Controller サブシステムのデータ型を調整します。
converter = DataTypeWorkflow.Converter(sud);
モデルのシミュレーションを実行し、結果を InitialRun
というタイトルの実行に保存します。
converter.CurrentRunName = 'InitialRun';
converter.simulateSystem();
実行中に発生したオーバーフローを特定します。
saturations = converter.saturationOverflows('InitialRun')
saturations = Result with properties: ResultName: 'fxpdemo_feedback/Controller/Up Cast' SpecifiedDataType: 'fixdt(1,16,14)' CompiledDataType: 'fixdt(1,16,14)' ProposedDataType: '' Wraps: [] Saturations: 23 WholeNumber: 0 SimMin: -2 SimMax: 1.9999 DerivedMin: [] DerivedMax: [] RunName: 'InitialRun' Comments: {'An output data type cannot be specified on this result. The output type is the same as the input type.'} DesignMin: [] DesignMax: []
wraps = converter.wrapOverflows('InitialRun')
wraps = []
シミュレーション中に、Controller サブシステムの Up Cast ブロックで飽和が発生します。ラップするオーバーフローはありません。飽和がないようモデルのデータ型を調整します。
ショートカットを使用してモデルを変換用に構成します。コンバーター オブジェクトの ShortcutsForSelectedSystem
プロパティにアクセスすることにより、システムで使用可能なショートカットを検索します。
shortcuts = converter.ShortcutsForSelectedSystem
shortcuts = 6x1 cell array {'Range collection using double override' } {'Range collection with specified data types' } {'Range collection using single override' } {'Disable range collection' } {'Remove overrides and disable range collection'} {'Range collection using scaled double override'}
システムの理想的な範囲を収集するにはシステムの理想的な範囲を収集するには、'Range collection using double override'
ショートカットを使用して、倍精度データ型でオーバーライドし、インストルメンテーションを有効にします。
converter.applySettingsFromShortcut(shortcuts{1});
このショートカットはまた、コンバーター オブジェクトの current run name プロパティも更新します。
baselineRun = converter.CurrentRunName
baselineRun = 'Ranges(Double)'
モデルを再度シミュレートし、理想的な範囲情報を収集します。結果は baselineRun
実行に保存されます。
converter.simulateSystem();
ProposalSettings
オブジェクトを作成してデータ型の提案設定を制御し、モデルでの信号の許容誤差を指定します。
propSettings = DataTypeWorkflow.ProposalSettings;
20% の相対許容誤差をモデルの PlantOutput
信号の出力信号に指定します。
addTolerance(propSettings, 'fxpdemo_feedback/Analog Plant', 1, 'RelTol', 2e-1);
showTolerances
メソッドを使用して、システムで指定されているすべての許容誤差を表示できます。
showTolerances(propSettings)
Path Port_Index Tolerance_Type Tolerance_Value _________________________________ __________ ______________ _______________ {'fxpdemo_feedback/Analog Plant'} 1 {'RelTol'} 0.2
propSettings
で指定された推奨設定と、baselineRun
実行に保存された範囲情報を使用してシステムにデータ型を推奨します。
converter.proposeDataTypes(baselineRun, propSettings)
モデルに対して baselineRun
実行で推奨されたデータ型を適用します。
converter.applyDataTypes(baselineRun)
新しいデータ型を使用したモデルの動作が推奨設定オブジェクト propSettings
で指定された許容誤差を満たすことを確認します。verify
メソッドはデータ型オーバーライドを削除し、更新された固定小数点データ型を使用してモデルのシミュレーションを実行します。DataTypeWorkflow.VerificationResult
オブジェクトを返します。
result = verify(converter, baselineRun, 'FixedRun')
result = VerificationResult with properties: ScenarioResults: [0x0 DataTypeWorkflow.VerificationResult] RunName: 'FixedRun' BaselineRunName: 'Ranges(Double)' Status: 'Pass' MaxDifference: 0.0351
DataTypeWorkflow.VerificationResult
オブジェクトの explore
メソッドを使用して、シミュレーション データ インスペクターを起動し、許容誤差を指定した信号を調べます。
explore(result)