Wolfram 控制系统 | 应用示例

在代码中点击并按下
+
,即可编辑并运行任何代码。
建模、设计、部署。环境建模、控制器设计、实际部署——全部集成在统一的工作流程中,为学习者和专业人士量身打造。

指定并转换模型

从非线性微分方程定义非线性状态空间模型:
Run
In[]:=
nonlinearEqns={
′
x
1
[t]-u[t]+3
x
2
[t]-(2
x
1
[t])
x
2
[t],
′
x
2
[t]3
x
1
[t]-
x
2
[t]};​​nonlinearModel=NonlinearStateSpaceModel[nonlinearEqns,{
x
1
[t],
x
2
[t]},{u[t]},{
x
1
[t]},t]
线性化模型:
Run
In[]:=
linearModel=StateSpaceModel[nonlinearModel]
直接从状态空间矩阵指定状态空间模型:
Run
In[]:=
StateSpaceModel
0
3
3
-1
,
-1
0
,(
1
0
)
转换为传递函数模型:
Run
In[]:=
TransferFunctionModel[linearModel,s]
将连续时间模型离散化:
Run
In[]:=
ToDiscreteTimeModel[linearModel,0.5,Method->"ZeroOrderHold"]

设计比例-积分-微分(PID)控制器

定义传递函数模型:
Run
In[]:=
dcMotor=TransferFunctionModel[{{{.01}},.0001+(.1+.01s)(1+.5s)},s]
创建系统的奈奎斯特图:
Run
In[]:=
NyquistPlot[dcMotor]
计算模型的 PID 控制器:
Run
In[]:=
pid=PIDTune[dcMotor,"PID","Data"]
计算单位阶跃输入的响应:
Run
In[]:=
motorResponse=OutputResponse[pid["ReferenceOutput"],UnitStep[t],{t,0,5}]
绘制响应曲线:
Run
In[]:=
Plot[motorResponse,{t,0,5},PlotRange->All]

时滞系统建模Model Systems with Time Delays

指定一个时滞系统:
Run
In[]:=
delayEqn=mx''[t]+cx'[t]+kx[t]-α(f[t]+x[t]-x[t-τ])/.τ->
2π
ω
构建符号状态空间模型:
Run
In[]:=
latheModel=StateSpaceModel[delayEqn,{x[t],x'[t]},f[t],x[t],t,SystemsModelLabels{"f","x",{"x","x'"}}]
指定数值参数及数值模型:
Run
In[]:=
latheParams={m0.75,ω3,α->10,k0.1,c5,τ3};​​numericModel=latheModel/.latheParams
创建无时滞的近似模型:
Run
In[]:=
approximateModel=SystemsModelDelayApproximate[numericModel,0]
可视化系统的频率响应:
Run
In[]:=
BodePlot[{numericModel,approximateModel},PlotLegends->{"Delay","Delay-Free"}]
比较两模型对相同输入的输出响应:
Run
In[]:=
responses=Table[OutputResponse[system,UnitStep[t],{t,0,30}],{system,{numericModel,approximateModel}}];​​Plot[responses,{t,0,30},PlotRangeAll,PlotLegends{"Delay","Delay-Free"}]

设计调节器控制器

定义仿射状态空间模型和期望平衡点
x
0
:
Run
In[]:=
eqns=m
′′
x
[t]gm-
k
2
i[t]
2
x[t]
,v[t]ri[t]+l
′
i
[t];​​pars={r->10,m->0.05,k->1,l->0.05,g->9.8,
x
0
->0.5};​​
i
0
=
x
0
mg
k
,
v
0
=r
x
0
mg
k
/.pars;​​electromagnetModel=AffineStateSpaceModel[eqns,{{x[t],
x
0
},x'[t],{i[t],
i
0
}},{{v[t],
v
0
}},x[t],t]/.pars
In[]:=
AffineStateSpaceModel[eqns,{{x[t],
x
0
},x'[t],{i[t],
i
0
}},{{v[t],
v
0
}},x[t],t]
指定反馈输入:
Run
In[]:=
feedbackModel="InputModel"->AffineStateSpaceModel[electromagnetModel,Automatic,Automatic,Automatic,None],"FeedbackInputs"->1
计算调节器控制器:
Run
In[]:=
controllerData=LQRegulatorGains[feedbackModel,{DiagonalMatrix[{.1,.1,.1}],{{5}}},"Data"]
获取闭环系统:
Run
In[]:=
closedSystem=controllerData["ClosedLoopSystem"]//Simplify
计算闭环系统的状态响应:
Run
In[]:=
emResponses=StateResponse[{closedSystem,{0.8,0,0}},0,{t,0,2}]
可视化响应趋近期望平衡点的过程:
Run
In[]:=
Plot{emResponses[[1]],
x
0
/.pars},{t,0,2},

获取控制器模型:
Run
In[]:=
emController=controllerData["ControllerModel"]
绘制控制器作用图:
Run
In[]:=
effort=OutputResponse[emController,Join[{0},emResponses],{t,0,2}];​​Plot[effort,{t,0,2},PlotRange->All]

设计模型预测控制器

根据指定的代价函数和权重计算模型预测控制器:
Run
In[]:=
cost="Norm"->∞,"Horizon"3,"StateWeight"{{5,0},{0,2}},"InputWeight"{{1}};​​constraints=-2≤
x
1
≤2&&-2≤
x
2
≤2&&-1≤u≤1;​​mpc=ModelPredictiveController
0.1
0
0
1
-0.1
1
1
0
0
1
,cost,constraints
计算闭环系统:
Run
In[]:=
csys=ModelPredictiveController
0.1
0
0
1
-0.1
1
1
0
0
1
,cost,constraints,"ClosedLoopSystem"
绘制对一组非零初始条件的响应:
Run
In[]:=
ListStepPlot[OutputResponse[{csys,<|1->{1,-1}|>},PadRight[{0,0.8},10]],PlotRange->All]

生化系统建模及更多

从 System Modeler Modelica Library Store 下载 Bio Chem 库。然后,可参考以下示例:
◼
  • Dose Selection for Drug Trials
  • ◼
  • Estimating Liver Function
  • ◼
  • Phosphorylation of Insulin Receptors