I am a bit confused about choosing reference signal in order to control state space models.
I have read(however without deep math explanation) that one has to scale his reference signal for to make system to be able to track input signal. Also there is a function which gives a scaling coefficient Nbar
, so I have to multiply my reference signal by it:
s = size(A,1);
Z = [zeros([1,s]) 1];
N = inv([A,B;C,D])*Z';
Nx = N(1:s);
Nu = N(1+s);
Nbar=Nu + K*Nx;
In my particular case there is the model of a pendulum on a one dimensional cart with arbitrary chosen poles. My state variables are ${\vec{\textbf{x}}} = [x\ \dot{x}\ \theta\ \dot{\theta}]^{T}$.
Below is matlab code:
clear all;
M = 1;
m = 1;
l = 1.5;
g = 9.8;
I = m*l^2;
b = 0.05;
denom = M*(m*l^2) + I*(m + m);
a22 = -(b*I + b*m*l^2)/denom;
a23 = (g*(l^2)*(m^2))/denom;
a42 = -(b*l*m)/denom;
a43 = (g*(M+m)*l*m)/denom;
b21 = (I + m*l^2) / denom;
b41 = l*m / denom;
A = [0 1 0 0; 0 a22 a23 0; 0 0 0 1; 0 a42 a43 0];
B = [0; b21; 0; b41];
C = [1 0 0 0];
D = 0;
% Check for controllability
co = ctrb(A, B);
fprintf("%f\r\n", rank(co));
% POLES
P = [-1.5 -0.9 -2.5 -3.5];
% Placing poles
K = place(A, B, P);
% Reference signal rescaling
sys = ss(A, B, C, D);
N = rscale(sys, K);
Everything works like a charm. However I totally miss the intuition behind that.
Imagine standard PID control, in this case if I would like to control position I would set the error to ´current_position - desired_position´ and apply standard PID formula to that error. From the above it is intuitively clear why position is controlled and if I want to control, for example, velocity I will just set error to velocity divergence.
However in a state space I have some coefficient which arises after calculating dot product between my state and gain matrix. And for some reason after subtracting it from a scaled version of u I get controlled position. Why is a big secret for me. And how would one control any other state variable in this case, like velocity for example?