Wolfram 制御系 | 試してみよう

コードはどれも,コード内をクリックしてから,編集したり,
+
を押して実行したりできます.
モデリング,設計,配備 環境をモデル化し,コントローラを設計して現実世界に配備するまでのすべての過程を,学生やプロフェッショナルのための高度に統合されたワークフローで行うことができます.

モデルの指定と変換

非線形微分方程式から非線形状態空間モデルを定義する:
実行
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]
モデルを線形化する:
実行
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)制御器を設計する

伝達関数モデルを定義する:
実行
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]

むだ時間系をモデル化する

むだ時間系を指定する:
実行
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={m0.75,ω3,α->10,k0.1,c5,τ3};​​numericModel=latheModel/.latheParams
遅延のない近似モデルを作成する:
実行
In[]:=
approximateModel=SystemsModelDelayApproximate[numericModel,0]
系の周波数応答を可視化する:
実行
In[]:=
BodePlot[{numericModel,approximateModel},PlotLegends->{"Delay","Delay-Free"}]
同じ入力に対する2つのモデルの出力応答を比較する:
実行
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
を定義する:
実行
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]
フィードバック入力を指定する:
実行
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]],
x
0
/.pars},{t,0,2},

コントローラのモデルを得る:
実行
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≤
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
閉ループ系を計算する:
実行
In[]:=
csys=ModelPredictiveController
0.1
0
0
1
-0.1
1
1
0
0
1
,cost,constraints,"ClosedLoopSystem"
非零の初期条件集合に対する応答をプロットする:
実行
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