Wolfram Control Systems | Things to Try
Wolfram Control Systems | Things to Try
Make edits and run any piece of code by clicking inside the code and pressing .
+
Model, Design, Deploy. Model the environment. Design a controller. Deploy to the real world. All in a highly integrated workflow, developed for learners and professionals.
Specify and Convert Models
Specify and Convert Models
Define a nonlinear state-space model from nonlinear differential equations: |
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
Linearize the model: |
In[]:=
linearModel=StateSpaceModel[nonlinearModel]
Specify the state-space model directly from state-space matrices: |
In[]:=
StateSpaceModel
,
,(
)
0 | 3 |
3 | -1 |
-1 |
0 |
1 | 0 |
Convert to a transfer function model: |
In[]:=
TransferFunctionModel[linearModel,s]
Discretize a continuous-time model: |
In[]:=
ToDiscreteTimeModel[linearModel,0.5,Method->"ZeroOrderHold"]
Design a Proportional-Integral-Differential (PID) Controller
Design a Proportional-Integral-Differential (PID) Controller
Define a transfer function model: |
In[]:=
dcMotor=TransferFunctionModel[{{{.01}},.0001+(.1+.01s)(1+.5s)},s]
Create a Nyquist plot for the system: |
In[]:=
NyquistPlot[dcMotor]
Compute a PID controller for the model: |
In[]:=
pid=PIDTune[dcMotor,"PID","Data"]
Compute the response to a unit step input: |
In[]:=
motorResponse=OutputResponse[pid["ReferenceOutput"],UnitStep[t],{t,0,5}]
Plot the response: |
In[]:=
Plot[motorResponse,{t,0,5},PlotRange->All]
Model Systems with Time Delays
Model Systems with Time Delays
Specify a system with a time delay: |
In[]:=
delayEqn=mx''[t]+cx'[t]+kx[t]-α(f[t]+x[t]-x[t-τ])/.τ->
2π
ω
Construct a symbolic state-space model: |
In[]:=
latheModel=StateSpaceModel[delayEqn,{x[t],x'[t]},f[t],x[t],t,SystemsModelLabels{"f","x",{"x","x'"}}]
Specify numerical parameters and a numerical model: |
In[]:=
latheParams={m0.75,ω3,α->10,k0.1,c5,τ3};numericModel=latheModel/.latheParams
Create an approximate model without the delay: |
In[]:=
approximateModel=SystemsModelDelayApproximate[numericModel,0]
Visualize the frequency response of the systems: |
In[]:=
BodePlot[{numericModel,approximateModel},PlotLegends->{"Delay","Delay-Free"}]
Compare the output response of the two models to the same input: |
In[]:=
responses=Table[OutputResponse[system,UnitStep[t],{t,0,30}],{system,{numericModel,approximateModel}}];Plot[responses,{t,0,30},PlotRangeAll,PlotLegends{"Delay","Delay-Free"}]
Design a Regulator Controller
Design a Regulator Controller
Define an affine state-space model and desired equilibrium point 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
Specify the feedback input: |
In[]:=
feedbackModel="InputModel"->AffineStateSpaceModel[electromagnetModel,Automatic,Automatic,Automatic,None],"FeedbackInputs"->1
Compute the regulator controller: |
In[]:=
controllerData=LQRegulatorGains[feedbackModel,{DiagonalMatrix[{.1,.1,.1}],{{5}}},"Data"]
Obtain the closed-loop system: |
In[]:=
closedSystem=controllerData["ClosedLoopSystem"]//Simplify
Compute the state resopnse of the closed-loop system: |
In[]:=
emResponses=StateResponse[{closedSystem,{0.8,0,0}},0,{t,0,2}]
Visualize the response approaching the desired equilibrium: |
In[]:=
Plot{emResponses[[1]],/.pars},{t,0,2},
x
0
Obtain the controller model: |
In[]:=
emController=controllerData["ControllerModel"]
Plot the controller effort: |
In[]:=
effort=OutputResponse[emController,Join[{0},emResponses],{t,0,2}];Plot[effort,{t,0,2},PlotRange->All]
Design a Model Predictive Controller
Design a Model Predictive Controller
Compute a model predictive controller from a specified cost function and weights: |
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
Compute the closed-loop system: |
In[]:=
csys=ModelPredictiveController
,cost,constraints,"ClosedLoopSystem"
0.1 | 0 | 0 |
1 | -0.1 | 1 |
1 | 0 | 0 |
1
Plot the response to a set of nonzero initial conditions: |
In[]:=
ListStepPlot[OutputResponse[{csys,<|1->{1,-1}|>},PadRight[{0,0.8},10]],PlotRange->All]
Model Biochemical Systems and More
Model Biochemical Systems and More
Download the Bio Chem library from the System Modeler Modelica Library Store. Then, follow any of these examples: