与某些功能仿真软件编译器,您可以注册回调期间模拟。金宝app的金宝appsimulink.compiler.setExternalInputsFcn
和金宝appsimulink.compiler.setExternalOutputsFcn
功能使您能够设置值在根尺寸块和获得的值在每根外港块模拟步骤。与金宝appsimulink.compiler.setPostStepFcn
调用函数,你可以注册一个回调,每次模拟步骤,因此用它来发布流程的输出。
下面的例子使用了金宝appsimulink.compiler.setExternalOutputsFcn
和金宝appsimulink.compiler.setPostStepFcn
提供一个持续的跟踪的仿真输出。
这个例子展示了如何开发一个应用程序,使用回调函数来模拟输入和输出视图模型的仿真模型的洛伦兹系统。金宝app然后可以部署应用程序与仿真软件®编译器™。金宝app
打开并检查项目文件
这个示例使用仿真软件项目,包含所有所需的金宝app文件运行这个例子。这个项目包含一个仿真软件®的洛伦兹模型系统和应金宝app用程序,创建模拟模型的MATLAB®应用程序设计师用不同的输入和输出值。了解更多关于如何使用应用程序创建一个应用程序设计师,看看使用应用程序创建并运行一个简单的应用程序设计师。
金宝appsimulink.compiler.example.LorenzSystem
应用细节
打开LorenzSystemApp
。mlapp
文件。您可以查看编写的代码创建这个应用程序的代码视图部分应用Sesigner。构建这个应用程序的重要组成部分的行为模拟按钮。它具有以下突出的部分:创建SimulationInput
使用模拟对象,配置部署,回调读取输出端口数据和情节在每个时间步的数据。这三个函数允许您查看现场模拟的结果在已部署的应用程序。
创建金宝appSimulink.SimulationInput
对象
在函数createSimulationInput
,定义一个空金宝appSimulink.SimulationInput
对象模型。使用这个金宝appSimulink.SimulationInput
模拟对象设置回调函数和变量的模型。
模拟使用回调函数注册回调。的金宝appsimulink.compiler.setPostStepFcn
注册一个回调函数每次调用模拟步骤。的金宝appsimulink.compiler.setExternalOuputsFcn
注册一个回调,动态过程对每一个输出端口的值在根级别的模型模拟。
使用setVariable
的方法金宝appSimulink.SimulationInput
应用程序对象提供参数值。仿真得到的值编辑字段的应用程序的UI。要部署应用程序,使用金宝appsimulink.compiler.configureForDeployment
函数。(注释行代码调用金宝appsimulink.compiler.configureForDeployment
函数更快的调试)。
函数simInp = createSimulationInput(应用)%创建一个空SimulationInput对象simInp = 金宝appSimulink.SimulationInput (“LorenzSystemModel”);%指定模拟回调simInp = 金宝appsimulink.compiler.setPostStepFcn (simInp @app.postStepFcn);simInp = 金宝appsimulink.compiler.setExternalOutputsFcn (simInp @app.processOutputs);%加载ui编辑字段的参数值simInp = simInp.setVariable (的ρ,app.rhoUIC.Value);simInp = simInp.setVariable (“β”,app.betaUIC.Value);simInp = simInp.setVariable (“σ”,app.sigmaUIC.Value);simInp = simInp.setVariable (“x0”,app.x0UIC.Value);simInp = simInp.setVariable (“y0”,app.y0UIC.Value);simInp = simInp.setVariable (“z0”,app.z0UIC.Value);%为部署配置simInp%调试提示:注释掉下面的线%更快和更容易调试runnng在MATLABsimInp = 金宝appsimulink.compiler.configureForDeployment (simInp);结束% createSimulationInput
模拟回调函数
模拟回调函数注册回调,让你读值输出端口和写值根输入端口。这些函数注册回调函数在每一个仿真时间步,它允许您查看现场模拟的结果。
的processOutputs
回调
的金宝appsimulink.compiler.setExternalOutputsFcn
线指的是函数procressOuputs
。的procressOuputs
回调函数处理值每一根输出端口块模型在模拟。的procressOuputs
函数被调用一次每端口和端口的样品时间。当procressOuputs
函数被调用时,它将读取的值每根外港块和缓存这些值。的postStepFcn
获取缓存的值更新的阴谋。
函数processOutputs(应用,opIdx ~,数据)%叫sim处理外部输出端口数据期间,%将被称为一次每端口样本。开关opIdx情况下1 app.txyzBuffer。x =数据;情况下2 app.txyzBuffer。y =数据;情况下3 app.txyzBuffer。z =数据;否则错误([“无效端口指数:num2str (opIdx)]);结束结束
的postStepFcn
回调
的postStepFcn
每一个仿真步骤后调用回调函数。的时间
参数是时间之前的模拟步骤。的postStepFcn
函数获取缓存的输出港为每一块值时间
并将这些值传递给updateTrace
函数绘制在仿真时间的缓存值。
函数postStepFcn(应用程序、时间)%在sim每次仿真时间步app.updateSimStats(时间);如果app.status = = AppStatus。开始app.switchStatus (AppStatus.Running);app.simStats。WallClockTimeAfterFirstStep =抽搐;结束如果app.stopRequested app.switchStatus (AppStatus.Stopping);stopRequestedID = [mfilename (“类”),“:StopRequested”];把(MException (stopRequestedID,“停止请求”));结束% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -app.txyzBuffer。t =时间;x = [app.txyzBuffer.x];y = [app.txyzBuffer.y];z = [app.txyzBuffer.z];app.updateTrace (x, y, z);app.updateMarker (“头”,x, y, z);% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -drawnowlimitrate;结束% postStepFcn
测试应用程序设计师
在部署应用程序之前,确保应用程序运行在应用程序设计师。点击模拟验证应用程序通过模拟模型为不同的值。
编译应用程序部署
您可以使用应用程序设计师编译和部署应用程序,您还可以使用deploytool
函数。更多信息在编译和部署应用程序设计师,看看使用应用程序开发应用程序设计师,网络应用程序和应用程序编译器。
编译应用程序在这个例子中,使用世纪挑战集团
命令之后,应用程序的名称。
mcc - m LorenzSystemApp
configureForDeployment
|金宝appSimulink.SimulationInput
|世纪挑战集团
|deploytool
|sim卡
|金宝appsimulink.compiler.setExternalInputsFcn
|金宝appsimulink.compiler.setExternalOutputsFcn
|金宝appsimulink.compiler.setPostStepFcn
|金宝appsimulink.compiler.genapp