# Output Regulation

Regulate the height of the liquid in the lower tank whose net flow rate is subject to an exogenous disturbance. The control input is the flow into the upper tank.

Use Bernoulli's law and mass balance to derive the resulting differential equations.

 In[1]:= Xeqs = {Subscript[\[ScriptCapitalA], 1] Subscript[\[ScriptH], 1]'[t] == \[ScriptCapitalQ][ t] - \[ScriptC] Subscript[\[ScriptA], 1] Sqrt[ 2 \[ScriptG] Subscript[\[ScriptH], 1][t]], Subscript[\[ScriptCapitalA], 2] Subscript[\[ScriptH], 2]'[t] == \[ScriptC] Subscript[\[ScriptA], 1] Sqrt[ 2 \[ScriptG] Subscript[\[ScriptH], 1][ t]] - \[ScriptC] Subscript[\[ScriptA], 2] Sqrt[ 2 \[ScriptG] Subscript[\[ScriptH], 2][ t]] - \[ScriptCapitalQ]\[ScriptD][ t], \[ScriptCapitalQ]\[ScriptD]'[t] == 0};

 In[2]:= Xop = {Subscript[\[ScriptH], 1][t] -> \[ScriptQ]^2/( 2 \[ScriptC]^2 \[ScriptG] \!\(\*SubsuperscriptBox[\(\[ScriptA]\), \(1\), \(2\)]\)), Subscript[\[ScriptH], 2][ t] -> (\[ScriptQ] - \[ScriptQ]\[ScriptD])^2/( 2 \[ScriptC]^2 \[ScriptG] \!\(\*SubsuperscriptBox[\(\[ScriptA]\), \(2\), \(2\)]\)), \ \[ScriptCapitalQ]\[ScriptD][ t] -> \[ScriptQ]\[ScriptD], \[ScriptCapitalQ][t] -> \[ScriptQ]}; PowerExpand[eqs /. op]
 Out[2]=

Define the corresponding nonlinear system with input and output .

 In[3]:= Xpars = {\[ScriptC] -> 0.7, \[ScriptG] -> 9.8, Subscript[\[ScriptCapitalA], 1] -> \[Pi] 4^2, Subscript[\[ScriptA], 1] -> \[Pi] 0.25^2, Subscript[\[ScriptCapitalA], 2] -> \[Pi] 3^2, Subscript[\[ScriptA], 2] -> \[Pi] 0.25^2, \[ScriptQ] -> 1, Subscript[\[ScriptCapitalH], ref] -> 3};
 In[4]:= Xdtank = NonlinearStateSpaceModel[eqs, op[[1 ;; 3]], op[[-1]], {Subscript[\[ScriptH], 2][t] - Subscript[\[ScriptCapitalH], ref]}, t] /. pars
 Out[4]=

The feedback law.

 In[5]:= X\[ScriptK] = FullInformationOutputRegulator[dtank, {-0.5, -1}] // Simplify
 Out[5]=

The closed-loop system.

 In[6]:= Xcsys = SystemsModelStateFeedbackConnect[dtank, \[ScriptK]] // Simplify
 Out[6]=

A polynomial disturbance is approximated as a piecewise constant function.

 In[7]:= X\[ScriptD] = -0.003 + 0.0013 x + 0.00016 x^2 - 1.613 10^-6 x^3 + 4.069 10^-9 x^4; Subscript[\[ScriptD], \[ScriptA]] = Piecewise[Table[{\[ScriptD], x <= t < x + 1}, {x, 0, 200, 1}], 0.2634];
 In[8]:= XPlot[Subscript[\[ScriptD], \[ScriptA]], {t, 0, 250}, Exclusions -> None]
 Out[8]=

Assemble the simulation model and simulate the state responses.

 In[9]:= Xcsys1 = NonlinearStateSpaceModel[csys, Join[op[[1 ;; 2]], {{\[ScriptCapitalQ]\[ScriptD][t], 0}}] /. pars /. \[ScriptQ]\[ScriptD] -> 0] /. \[ScriptQ]\[ScriptD] -> Subscript[\[ScriptD], \[ScriptA]];
 In[10]:= Xsr = StateResponse[csys1, 0, {t, 0, 50}];

The plot shows that the desired regulation has been achieved.

 In[11]:= XPlot[Evaluate@sr[[{1, 2}]], {t, 0, 30}, PlotLegends -> {"\!\(\*SubscriptBox[\(\[ScriptH]\), \(1\)]\)", "\!\(\*SubscriptBox[\(\[ScriptH]\), \(2\)]\)"}]
 Out[11]=

## Mathematica

Questions? Comments? Contact a Wolfram expert »