« View all new features in
Mathematica
9
◄
previous

next
►
New in
Mathematica
9
›
Enhanced Control Systems
Design a PID Room Temperature Controller
Design a PID controller that maintains room temperature near 22 °C even with fluctuations of the outside temperature, modeled as a disturbance.
Enter the models.
In[1]:=
X
{valve, burner, thermres, room} = {TransferFunctionModel[Unevaluated[{{1/(1 + 4 s)}}], s, SamplingPeriod >None, SystemsModelLabels > {{None}, {None}}], TransferFunctionModel[Unevaluated[{{5}}], s, SamplingPeriod >None, SystemsModelLabels > {{None}, {None}}], TransferFunctionModel[Unevaluated[{{0.1}}], s, SamplingPeriod >None, SystemsModelLabels > {{None}, {None}}], TransferFunctionModel[Unevaluated[{{1/(1 + 8 s)}}], s, SamplingPeriod >None, SystemsModelLabels > {{None}, {None}}]};
In[2]:=
X
hsys = SystemsModelSeriesConnect[valve, SystemsModelSeriesConnect[burner, thermres]];
In[3]:=
X
lsys = SystemsModelSeriesConnect[room, hsys];
Obtain the controller.
In[4]:=
X
pid = PIDTune[lsys, {Automatic, "AMIGO"}, "PIDData"];
The disturbance to output transfer function.
In[5]:=
X
doTFM = SystemsModelFeedbackConnect[room, SystemsModelSeriesConnect[pid["Feedback"], hsys]]
Out[5]=
Get the outside temperature history for a particular location.
In[6]:=
X
{times, values} = WeatherData["Chicago", "Temperature", {DatePlus[Date[], 1], Date[]}] // Transpose;
The temperature as a continuous function of time.
In[7]:=
X
timeSec = DateDifference[First[times], #, "Second"][[1]] & /@ times;
In[8]:=
X
d = Interpolation[Transpose[{timeSec, values}]];
Compute the regulated room temperature and sample it every minute.
In[9]:=
X
temp = OutputResponse[pid["ReferenceOutput"], 22, {t, 0, Last[timeSec]}] + OutputResponse[doTFM, d[t], {t, 0, Last[timeSec]}];
In[10]:=
X
temps = Table[temp, {t, 0, Last[timeSec], 60}] // Flatten;
Plot the room temperature and the outside temperature.
In[11]:=
X
roomTplot = DateListPlot[temps, {First[times], Last[times]}, PlotStyle > Red, Joined > True, PlotLegends > LineLegend[{"Room temperature"}]];
In[12]:=
X
outTplot = DateListPlot[Transpose[{times, values}], Joined > True, PlotLegends > LineLegend[{"Outside temperature"}]];
In[13]:=
X
Show[roomTplot, outTplot, ImageSize > Medium, FrameLabel > {"Hours", "\[Degree]C"}, PlotRange > {5, 25}]
Out[13]=