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

Define a nonlinear state-space model from nonlinear differential equations:
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]
Linearize the model:
Run
In[]:=
linearModel=StateSpaceModel[nonlinearModel]
Specify the state-space model directly from state-space matrices:
Run
In[]:=
StateSpaceModel
0
3
3
-1
,
-1
0
,(
1
0
)
Convert to a transfer function model:
Run
In[]:=
TransferFunctionModel[linearModel,s]
Discretize a continuous-time model:
Run
In[]:=
ToDiscreteTimeModel[linearModel,0.5,Method->"ZeroOrderHold"]

Design a Proportional-Integral-Differential (PID) Controller

Define a transfer function model:
Run
In[]:=
dcMotor=TransferFunctionModel[{{{.01}},.0001+(.1+.01s)(1+.5s)},s]
Create a Nyquist plot for the system:
Run
In[]:=
NyquistPlot[dcMotor]
Compute a PID controller for the model:
Run
In[]:=
pid=PIDTune[dcMotor,"PID","Data"]
Compute the response to a unit step input:
Run
In[]:=
motorResponse=OutputResponse[pid["ReferenceOutput"],UnitStep[t],{t,0,5}]
Plot the response:
Run
In[]:=
Plot[motorResponse,{t,0,5},PlotRange->All]

Model Systems with Time Delays

Specify a system with a time delay:
Run
In[]:=
delayEqn=mx''[t]+cx'[t]+kx[t]-α(f[t]+x[t]-x[t-τ])/.τ->
2π
ω
Construct a symbolic state-space model:
Run
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:
Run
In[]:=
latheParams={m0.75,ω3,α->10,k0.1,c5,τ3};numericModel=latheModel/.latheParams
Create an approximate model without the delay:
Run
In[]:=
approximateModel=SystemsModelDelayApproximate[numericModel,0]
Visualize the frequency response of the systems:
Run
In[]:=
BodePlot[{numericModel,approximateModel},PlotLegends->{"Delay","Delay-Free"}]
Compare the output response of the two models to the same input:
Run
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

Define an affine state-space model and desired equilibrium point
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]
Specify the feedback input:
Run
In[]:=
feedbackModel="InputModel"->AffineStateSpaceModel[electromagnetModel,Automatic,Automatic,Automatic,None],"FeedbackInputs"->1
Compute the regulator controller:
Run
In[]:=
controllerData=LQRegulatorGains[feedbackModel,{DiagonalMatrix[{.1,.1,.1}],{{5}}},"Data"]
Obtain the closed-loop system:
Run
In[]:=
closedSystem=controllerData["ClosedLoopSystem"]//Simplify
Compute the state resopnse of the closed-loop system:
Run
In[]:=
emResponses=StateResponse[{closedSystem,{0.8,0,0}},0,{t,0,2}]
Visualize the response approaching the desired equilibrium:
Run
In[]:=
Plot{emResponses[[1]],
x
0
/.pars},{t,0,2},
Obtain the controller model:
Run
In[]:=
emController=controllerData["ControllerModel"]
Plot the controller effort:
Run
In[]:=
effort=OutputResponse[emController,Join[{0},emResponses],{t,0,2}];Plot[effort,{t,0,2},PlotRange->All]

Design a Model Predictive Controller

Compute a model predictive controller from a specified cost function and weights:
Run
In[]:=
cost="Norm"->,"Horizon"3,"StateWeight"{{5,0},{0,2}},"InputWeight"{{1}};constraints=-2
x
1
2&&-2
x
2
2&&-1u1;mpc=ModelPredictiveController
0.1
0
0
1
-0.1
1
1
0
0
1
,cost,constraints
Compute the closed-loop system:
Run
In[]:=
csys=ModelPredictiveController
0.1
0
0
1
-0.1
1
1
0
0
1
,cost,constraints,"ClosedLoopSystem"
Plot the response to a set of nonzero initial conditions:
Run
In[]:=
ListStepPlot[OutputResponse[{csys,<|1->{1,-1}|>},PadRight[{0,0.8},10]],PlotRange->All]

Model Biochemical Systems and More

Download the Bio Chem library from the System Modeler Modelica Library Store. Then, follow any of these examples:
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.