I have a mathematica notebook to build the state-space model of a system from its differential equations, calculate LQR gains and simulate the system response.
ss = StateSpaceModel[
{eq1, eq2},
{{xc'[t], 0}, {xc[t], 0}, {\[Theta]'[t], 0}, {\[Theta][t], 0}},
{{F[t], 0}},
{xc[t], \[Theta][t]},
t
]
ssValues = With[{g = 9.8, mc = 0.5, mp = 2, mf = 0.5, lp = 0.3}, Evaluate[ss]]
So far, the system is unstable. Adding LQR:
ssValuesTracked = <|"InputModel" -> ssValues, "TrackedOutputs" -> {1, 2}|>
Q = ...
R = ...
ssValuesTrackedCL = LQRegulatorGains[ssValues, {Q, R}, "Data"]
Which makes the system stable when tracking an input.
r = {1, 0}
Plot[
Evaluate[
OutputResponse[{ssValuesTrackedCL, {0, 0.5, 0, 0.2}}, r, {t, 0, 10}]
],
{t, 0, 10},
Frame -> True, PlotRange -> All, ImageSize -> 300, GridLines -> Automatic, PlotLegends -> Automatic
]
Which show the response of xc and theta.
The questions is, how do I plot the values of the input u of the closed loop system in the figure below?