将生成的代码链接到要求
将生成的代码链接到模型元素要求。使用配置参数,您可以指定是否在生成的代码中包含要求描述作为注释。
打开模型
打开 rtwdemo_requirements
模型。该模型包含具有相关要求的 Simulink® 和 Stateflow® 元素。
model='rtwdemo_requirements';
open_system(model);
查看要求
您可以使用需求编辑器查看链接到模型的要求。在 Simulink 编辑器中,打开需求管理器。在需求选项卡上,点击需求编辑器。您可以通过使用对象上下文菜单来查看特定于模型对象的要求。右键点击某个元素,然后选择需求 > 打开 "出向链接" 对话框。要查看要求,请使用以下命令:
1.要查看 DiscretePulseGenerator
模块的要求,请右键点击 DiscretePulseGenerator
模块并选择需求 > 打开 "出向链接" 对话框以打开出向链接编辑器。使用出向链接编辑器,您可以创建、编辑和删除要求可追溯性链接。
clockblock='rtwdemo_requirements/clock'; clockblockh=get_param(clockblock,'handle'); rmi('edit',clockblockh);
2.要查看要求,请双击打开 Signal Editor 模块。
sigeblock='rtwdemo_requirements/Signal Editor';
open_system(sigeblock)
3.要查看对 Stateflow® 状态的要求,请打开出向链接编辑器。
state=find(sfroot,'-isa','Stateflow.State','-and','Tag','req_state'); rmi('edit',state.id);
4.要查看对 Stateflow 转换的要求,请打开出向链接编辑器。
trans=find(sfroot,'-isa','Stateflow.Transition','-and','Tag','req_trans'); rmi('edit',trans.id);
5.要查看对 Stateflow 函数的要求,请打开出向链接编辑器。
func=find(sfroot,'-isa','Stateflow.Function','-and','Tag','req_function'); rmi('edit',func.id);
关闭打开的窗口。
close_system(sigeblock);
设置配置参数
打开“配置参数”对话框的代码生成 > 注释窗格。查看配置参数设置。
model = bdroot; configSet = getActiveConfigSet(model); openDialog(configSet);
生成代码
为模型生成代码。
slbuild('rtwdemo_requirements')
### Starting build procedure for: rtwdemo_requirements ### Successful completion of build procedure for: rtwdemo_requirements Build Summary Top model targets built: Model Action Rebuild Reason ====================================================================================================== rtwdemo_requirements 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 23.677s
在生成的代码中,查看包含要求的注释。要查看所有要求,请点击带有超链接的要求注释。
rtwdemodbtype('rtwdemo_requirements_ert_rtw/rtwdemo_requirements.c',... '/* Function for Chart:','return result;',1,0);
/* Function for Chart: '<Root>/rebound_elimination' */ static real_T rebound_fcn(real_T prev_in, real_T prev_out, real_T curr_in) { real_T result; /* Graphical Function 'rebound_fcn': '<S2>:2': * 1. Result Computation */ /* Transition: '<S2>:4' */ if (prev_in == curr_in) { /* Transition: '<S2>:5' */ result = curr_in; } else { /* Transition: '<S2>:6' */ /* Transition: '<S2>:7' */ result = prev_out; }
关闭模型
rtwdemoclean;
close_system('rtwdemo_requirements',0);
相关主题
- Link Blocks and Requirements (Requirements Toolbox)