Wolfram 控制系统 | 应用示例
Wolfram 控制系统 | 应用示例
在代码中点击并按下 ,即可编辑并运行任何代码。
+
建模、设计、部署。环境建模、控制器设计、实际部署——全部集成在统一的工作流程中,为学习者和专业人士量身打造。
指定并转换模型
指定并转换模型
从非线性微分方程定义非线性状态空间模型: |
In[]:=
nonlinearEqns={[t]-u[t]+3[t]-(2[t])[t],[t]3[t]-[t]};nonlinearModel=NonlinearStateSpaceModel[nonlinearEqns,{[t],[t]},{u[t]},{[t]},t]
′
x
1
x
2
x
1
x
2
′
x
2
x
1
x
2
x
1
x
2
x
1
线性化模型: |
In[]:=
linearModel=StateSpaceModel[nonlinearModel]
直接从状态空间矩阵指定状态空间模型: |
In[]:=
StateSpaceModel
,
,(
)
0 | 3 |
3 | -1 |
-1 |
0 |
1 | 0 |
转换为传递函数模型: |
In[]:=
TransferFunctionModel[linearModel,s]
将连续时间模型离散化: |
In[]:=
ToDiscreteTimeModel[linearModel,0.5,Method->"ZeroOrderHold"]
设计比例-积分-微分(PID)控制器
设计比例-积分-微分(PID)控制器
定义传递函数模型: |
In[]:=
dcMotor=TransferFunctionModel[{{{.01}},.0001+(.1+.01s)(1+.5s)},s]
创建系统的奈奎斯特图: |
In[]:=
NyquistPlot[dcMotor]
计算模型的 PID 控制器: |
In[]:=
pid=PIDTune[dcMotor,"PID","Data"]
计算单位阶跃输入的响应: |
In[]:=
motorResponse=OutputResponse[pid["ReferenceOutput"],UnitStep[t],{t,0,5}]
绘制响应曲线: |
In[]:=
Plot[motorResponse,{t,0,5},PlotRange->All]
时滞系统建模Model Systems with Time Delays
时滞系统建模Model Systems with Time Delays
指定一个时滞系统: |
In[]:=
delayEqn=mx''[t]+cx'[t]+kx[t]-α(f[t]+x[t]-x[t-τ])/.τ->
2π
ω
构建符号状态空间模型: |
In[]:=
latheModel=StateSpaceModel[delayEqn,{x[t],x'[t]},f[t],x[t],t,SystemsModelLabels{"f","x",{"x","x'"}}]
指定数值参数及数值模型: |
In[]:=
latheParams={m0.75,ω3,α->10,k0.1,c5,τ3};numericModel=latheModel/.latheParams
创建无时滞的近似模型: |
In[]:=
approximateModel=SystemsModelDelayApproximate[numericModel,0]
可视化系统的频率响应: |
In[]:=
BodePlot[{numericModel,approximateModel},PlotLegends->{"Delay","Delay-Free"}]
比较两模型对相同输入的输出响应: |
In[]:=
responses=Table[OutputResponse[system,UnitStep[t],{t,0,30}],{system,{numericModel,approximateModel}}];Plot[responses,{t,0,30},PlotRangeAll,PlotLegends{"Delay","Delay-Free"}]
设计调节器控制器
设计调节器控制器
定义仿射状态空间模型和期望平衡点 x 0 |
In[]:=
eqns=m[t]gm-,v[t]ri[t]+l[t];pars={r->10,m->0.05,k->1,l->0.05,g->9.8,->0.5};=,=r/.pars;electromagnetModel=AffineStateSpaceModel[eqns,{{x[t],},x'[t],{i[t],}},{{v[t],}},x[t],t]/.pars
′′
x
k
2
i[t]
2
x[t]
′
i
x
0
i
0
x
0
mg
k
v
0
x
0
mg
k
x
0
i
0
v
0
In[]:=
AffineStateSpaceModel[eqns,{{x[t],},x'[t],{i[t],}},{{v[t],}},x[t],t]
x
0
i
0
v
0
指定反馈输入: |
In[]:=
feedbackModel="InputModel"->AffineStateSpaceModel[electromagnetModel,Automatic,Automatic,Automatic,None],"FeedbackInputs"->1
计算调节器控制器: |
In[]:=
controllerData=LQRegulatorGains[feedbackModel,{DiagonalMatrix[{.1,.1,.1}],{{5}}},"Data"]
获取闭环系统: |
In[]:=
closedSystem=controllerData["ClosedLoopSystem"]//Simplify
计算闭环系统的状态响应: |
In[]:=
emResponses=StateResponse[{closedSystem,{0.8,0,0}},0,{t,0,2}]
可视化响应趋近期望平衡点的过程: |
In[]:=
Plot{emResponses[[1]],/.pars},{t,0,2},
x
0
获取控制器模型: |
In[]:=
emController=controllerData["ControllerModel"]
绘制控制器作用图: |
In[]:=
effort=OutputResponse[emController,Join[{0},emResponses],{t,0,2}];Plot[effort,{t,0,2},PlotRange->All]
设计模型预测控制器
设计模型预测控制器
根据指定的代价函数和权重计算模型预测控制器: |
In[]:=
cost="Norm"->∞,"Horizon"3,"StateWeight"{{5,0},{0,2}},"InputWeight"{{1}};constraints=-2≤≤2&&-2≤≤2&&-1≤u≤1;mpc=ModelPredictiveController
,cost,constraints
x
1
x
2
0.1 | 0 | 0 |
1 | -0.1 | 1 |
1 | 0 | 0 |
1
计算闭环系统: |
In[]:=
csys=ModelPredictiveController
,cost,constraints,"ClosedLoopSystem"
0.1 | 0 | 0 |
1 | -0.1 | 1 |
1 | 0 | 0 |
1
绘制对一组非零初始条件的响应: |
In[]:=
ListStepPlot[OutputResponse[{csys,<|1->{1,-1}|>},PadRight[{0,0.8},10]],PlotRange->All]
生化系统建模及更多
生化系统建模及更多