PID室温制御器を設計する
外気温に変動があってもそれを外乱としてモデル化して,室温を22°C近くに保つPID制御器を設計する.
{valve, burner, thermres, room} = {TransferFunctionModel[Unevaluated[{{(1/(1 + 4s))}}], 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 + 8s))}}], s, SamplingPeriod -> None, SystemsModelLabels -> {{None}, {None}}]};hsys = SystemsModelSeriesConnect[valve, SystemsModelSeriesConnect[burner, thermres]];lsys = SystemsModelSeriesConnect[room, hsys];pid = PIDTune[lsys, {Automatic, "AMIGO"}, "PIDData"];doTFM = SystemsModelFeedbackConnect[room, SystemsModelSeriesConnect[pid["Feedback"], hsys]]{times, values} = WeatherData["Chicago", "Temperature", {DatePlus[Date[], -1], Date[]}]["Path"]//Transpose;values = QuantityMagnitude /@ values;timeSec = QuantityMagnitude[DateDifference[First[times], #, "Second"]]& /@ times;d = Interpolation[Transpose[{timeSec, values}]];temp = OutputResponse[pid["ReferenceOutput"], 22, {t, 0, Last[timeSec]}] + OutputResponse[doTFM, d[t], {t, 0, Last[timeSec]}];temps = Table[temp, {t, 0, Last[timeSec], 60}]//Flatten;roomTplot = DateListPlot[temps, {First[times], Last[times]}, PlotStyle -> Red, Joined -> True, PlotLegends -> LineLegend[{"室温"}]];outTplot = DateListPlot[Transpose[{times, values}], Joined -> True, PlotLegends -> LineLegend[{"外気温"}]];Show[roomTplot, outTplot, ImageSize -> Medium, FrameLabel -> {"時間", "°C"}, PlotRange -> {-5, 25}]