I have to implement a controller for a rotary inverted pendulum. I managed to get it to a point where it stays upright for a while but then then simulation "breaks down". I think the encoder doesn't rotate fast enough and slowly loses controll over the bar.
I have attached the slx and the workspace where I calculate the LQR gains. I can't upload the parasolid files for the simscape model. Here is the relevant figures
PLANT
CONTROLLER
Tau OUTPUT
Bar angled relative to Top dead center = 0 and The bottom = 3.14..
I have tried chaning both the Q and R values of the LQR controller quite a bit but there is basically no change in the ouput.
Finally this is the bar angle graph when I constrain the encoder to have hard stops at 180 and -180 degrees
The scope is wrapped so those peaks just means the bar has spun past the lowest point
J_T = (J_p + 0.25*M_p*L_p^2) * (J_r + M_p*L_r^2) - (0.5*M_p*L_p*L_r)^2;
A32 = 0.25*(M_p^2)*(L_p)*(L_r)*(G);
A33 = -(J_p+(0.25)*(M_p)*(L_p^2))*(B_r);
A34 = -((0.5)*(M_p)*(L_p)*(L_r)*(B_p));
A42 = (0.5)*(M_p)*(L_p)*(G)*(J_r+(M_p)*(L_r^2));
A43 = -((0.5)*(M_p)*(L_p)*(L_r)*(B_p));
A44 = -(J_r + (M_p)*(L_r^2))*(B_p);
B31 = J_p+0.25*(M_p)*(L_p^2);
B41 = 0.5*(M_p)*(L_r)*(L_r);
A = [A11 A12 A13 A14; A21 A22 A23 A24; A31 A32 A33 A34; A41 A42 A43 A44];
B = [B11; B21; B31; B41];
C = [C11 C12 C13 C14; C21 C22 C23 C24 ];
Q = diag([10, 1, 100, 1]);