Design a Full State Feedback Controller

Now, we have developed a mathematical model for the system--the linear time invariant state space model. Next, we are going to design a full state feedback controller in MATLAB. Insert A, B, C, D matrices, and make a state space model using command "ss". Then, assign value to the 4*4 matrix Q and scalar R. Then use command "lqr" (linear quadratic regulator--LQR) to calculate the feedback gains.

Note that we need to manually tune the gains: LQR only gives us gains according to Q and R value which were assigned by us, but we don't know what value for Q and R are the best. Therefore, tens of trial-and-error experiments are often unavoidable. The first try we should assign "Q = diag([1 1 1 1])", R = 1. Implement the gains in Arduino, look at the performance of the inverted pendulum, then adjust Q and R values. In Q matrix, each diagonal element relates to one state, the bigger value assigned, the greater effect on minimizing variation of that associated state. And the larger value of R, the greater effect on minimizing control input.

Attention: after we got the feedback gains, we could close MATLAB. Then, using the gains we calculated from MATLAB, write a program using Arduino programming software, and compile it onto Arduino board. So, in the end, the Arduino board controls the pneumatic inverted pendulum off line--no computer needed, no MATLAB needed.

The MATLAB file is available in the DOWNLOAD section.