2

What I'm trying to do

  • I'm trying to create a LQG controller to control a given system by combining a Linear Quadratic Regulator (LQR) and a Kalman Filter.

Where I'm stuck

I have found both separately, but am unsure how I combine them in MATLAB. This is the system and LQR solution:

System and LQR Solution

I am able to create both the Kalman Filter and the LQR seperately, but I can't figure out how to combine the LQR to take the Kalman Filter State Estimate as its input.

Akal = Afull;
Bkal = [B1, B2];
Ckal = Cfull;
Dkal = [0 0];
sys_kal = ss(Akal,Bkal,Ckal,Dkal);

[KEST,L,P] = kalman(sys_kal,E_d, E_n, 0)

[K,S,e] = lqr(Afull,B1,Q,r);

When I use the kalman function, here is what size(KEST) gives me:

State-space model with 11 outputs, 2 inputs, and 10 states.

I want my U to use the estimate given by the new SS system KEST. KEST provides an estimate for the output (y, dimension 1), and an estimate for all 10 states (X, dimension 10). I can write/draw out the closed loop control path that I am looking to create using the LQR and Kalman functions, but I am stuck at this point because I don't know how to implement it via MATLAB. I am unsure of the syntax as well.

I have searched for MATLAB examples but haven't found any that show me how to combine what I have found. I know that KEST is a state space model but I don't know how to use it or select a single output.

What I'm hoping to get help with

  • If I use bode(KEST), it gives me a BODE plot of all 11 outputs. I am not sure how to select just a single output of KEST.

  • I would like to have U = -K*X_est, but currently I just know the value of K. I don't know how to obtain an X_est from my KEST state space system.

Community
  • 1
  • 1
Cled1990
  • 31
  • 2

1 Answers1

0

What you are looking for is a command called lqgreg:

rlqg = lqgreg(kest,k)

Also make sure that kest outputs are the 10 states, and the y (output) is not included in the estimation.

To understand it better: LQR is a state-feedback, so the control is feeding back all of your states with an optimal k gain. The size of k is equal to the states of your system model.

Usual problem with LQR is that you rarely have all states measured. Here comes the kalman filter and helps to estimate all states from the measured outputs and known inputs. Note that kalman filter can be used for many other things, but here the only role of kalman filter is to create state estimates for state feedback, therefore it should estimate nothing else than the system states.

If you need to know you system output (for plotting or anything else) it is very easy to calculate from state estimates and the input (Cx + Du), but you can create another kalman filter just for the output estimation. This later solution is not acceptable when running in a microcontroller or other low capacity enviroment, since you are duplicate basically the same algorithm.

gaborp
  • 604
  • 5
  • 16