## How to use LQR for setpoint tracking?

Initially I was using LQR to regulate the error dynamics, i.e., I computed the gains for de = (A – BK)e, but this basically results in a PI controller since the control law (with integral action) is u = -K*e + ki*z. I have seen many sources teaching how to do it by augmenting the state vector with the integral of the error, expanding the matrices to A = [A 0; C 0], etc. but I still can’t understand how that works. I am working on a first order cruise control problem. From my observations the integral action is doing all the tracking and the -Kx term is only getting in the way, trying to regulate the state x to zero. Here is my code:

% Parameters

X_u = 0;

X_uu = 22.7841;

m = 5037.7;

% Equilibrium point x0

x0 = 20*1.852/3.6; % Longitudinal linear velocity in m/s

u0 = X_u*x0 + X_uu*x0^2 % Thrust in N

% Linearize system around x0

A = -(X_u/m + 2*X_uu/m*x0);

B = 1/m;

C = 1;

D = 0;

% System order

n = size(A,1);

% Open loop system

sys_ol = ss(A,B,C,D);

openloopPoles = eig(A)

% Augmented system with the integral of the error

A_hat = [A zeros(n,1);…

-C 0 ];

B_hat = [B; 0];

Br = [zeros(n,1); 1];

C_hat = [1 zeros(1,n)];

D_hat = 0;

% Q R matrices

Q = 1000*(C’*C);

R = 0.5e-3;

% Feedback gain

K_hat = lqr(A_hat, B_hat,Q,R)

K = K_hat(1)

ki = -K_hat(2)

% Scaling matrix

%Nbar = rscale(sys_ol,K)

% Closed loop system

AA = [A – B*K B*ki;-C 0];

BB = Br;

CC = [C 0];

DD = 0;

sys_cl = ss(AA, BB, CC, DD);

% Time vector

t = 0:0.1:30;

% Control input

u = u0*ones(size(t));

% Reference setpoint

r = 25*1.852/3.6*ones(size(t));

% Initial states

x0_hat = [x0,0]

% Simulate the response of the system

[y,t,x_hat] = lsim(sys_cl,r,t,x0_hat);

figure

plot(t, y*3.6/1.852, ‘k’, ‘LineWidth’, 1.5,’Color’,’k’)

xlabel(‘Time (seconds)’)

ylabel(‘Speed (knots)’)

title(‘Closed loop response with integrator’)

grid on

% Control effort (Thrust)

u_effort = -K*x_hat(:,1) + ki*x_hat(:,2);

figure

plot(t, u_effort,’Color’,’k’)

xlabel(‘Time (s)’)

ylabel(‘Thrust (N)’)

title(‘Control effort’)Initially I was using LQR to regulate the error dynamics, i.e., I computed the gains for de = (A – BK)e, but this basically results in a PI controller since the control law (with integral action) is u = -K*e + ki*z. I have seen many sources teaching how to do it by augmenting the state vector with the integral of the error, expanding the matrices to A = [A 0; C 0], etc. but I still can’t understand how that works. I am working on a first order cruise control problem. From my observations the integral action is doing all the tracking and the -Kx term is only getting in the way, trying to regulate the state x to zero. Here is my code:

% Parameters

X_u = 0;

X_uu = 22.7841;

m = 5037.7;

% Equilibrium point x0

x0 = 20*1.852/3.6; % Longitudinal linear velocity in m/s

u0 = X_u*x0 + X_uu*x0^2 % Thrust in N

% Linearize system around x0

A = -(X_u/m + 2*X_uu/m*x0);

B = 1/m;

C = 1;

D = 0;

% System order

n = size(A,1);

% Open loop system

sys_ol = ss(A,B,C,D);

openloopPoles = eig(A)

% Augmented system with the integral of the error

A_hat = [A zeros(n,1);…

-C 0 ];

B_hat = [B; 0];

Br = [zeros(n,1); 1];

C_hat = [1 zeros(1,n)];

D_hat = 0;

% Q R matrices

Q = 1000*(C’*C);

R = 0.5e-3;

% Feedback gain

K_hat = lqr(A_hat, B_hat,Q,R)

K = K_hat(1)

ki = -K_hat(2)

% Scaling matrix

%Nbar = rscale(sys_ol,K)

% Closed loop system

AA = [A – B*K B*ki;-C 0];

BB = Br;

CC = [C 0];

DD = 0;

sys_cl = ss(AA, BB, CC, DD);

% Time vector

t = 0:0.1:30;

% Control input

u = u0*ones(size(t));

% Reference setpoint

r = 25*1.852/3.6*ones(size(t));

% Initial states

x0_hat = [x0,0]

% Simulate the response of the system

[y,t,x_hat] = lsim(sys_cl,r,t,x0_hat);

figure

plot(t, y*3.6/1.852, ‘k’, ‘LineWidth’, 1.5,’Color’,’k’)

xlabel(‘Time (seconds)’)

ylabel(‘Speed (knots)’)

title(‘Closed loop response with integrator’)

grid on

% Control effort (Thrust)

u_effort = -K*x_hat(:,1) + ki*x_hat(:,2);

figure

plot(t, u_effort,’Color’,’k’)

xlabel(‘Time (s)’)

ylabel(‘Thrust (N)’)

title(‘Control effort’) Initially I was using LQR to regulate the error dynamics, i.e., I computed the gains for de = (A – BK)e, but this basically results in a PI controller since the control law (with integral action) is u = -K*e + ki*z. I have seen many sources teaching how to do it by augmenting the state vector with the integral of the error, expanding the matrices to A = [A 0; C 0], etc. but I still can’t understand how that works. I am working on a first order cruise control problem. From my observations the integral action is doing all the tracking and the -Kx term is only getting in the way, trying to regulate the state x to zero. Here is my code:

% Parameters

X_u = 0;

X_uu = 22.7841;

m = 5037.7;

% Equilibrium point x0

x0 = 20*1.852/3.6; % Longitudinal linear velocity in m/s

u0 = X_u*x0 + X_uu*x0^2 % Thrust in N

% Linearize system around x0

A = -(X_u/m + 2*X_uu/m*x0);

B = 1/m;

C = 1;

D = 0;

% System order

n = size(A,1);

% Open loop system

sys_ol = ss(A,B,C,D);

openloopPoles = eig(A)

% Augmented system with the integral of the error

A_hat = [A zeros(n,1);…

-C 0 ];

B_hat = [B; 0];

Br = [zeros(n,1); 1];

C_hat = [1 zeros(1,n)];

D_hat = 0;

% Q R matrices

Q = 1000*(C’*C);

R = 0.5e-3;

% Feedback gain

K_hat = lqr(A_hat, B_hat,Q,R)

K = K_hat(1)

ki = -K_hat(2)

% Scaling matrix

%Nbar = rscale(sys_ol,K)

% Closed loop system

AA = [A – B*K B*ki;-C 0];

BB = Br;

CC = [C 0];

DD = 0;

sys_cl = ss(AA, BB, CC, DD);

% Time vector

t = 0:0.1:30;

% Control input

u = u0*ones(size(t));

% Reference setpoint

r = 25*1.852/3.6*ones(size(t));

% Initial states

x0_hat = [x0,0]

% Simulate the response of the system

[y,t,x_hat] = lsim(sys_cl,r,t,x0_hat);

figure

plot(t, y*3.6/1.852, ‘k’, ‘LineWidth’, 1.5,’Color’,’k’)

xlabel(‘Time (seconds)’)

ylabel(‘Speed (knots)’)

title(‘Closed loop response with integrator’)

grid on

% Control effort (Thrust)

u_effort = -K*x_hat(:,1) + ki*x_hat(:,2);

figure

plot(t, u_effort,’Color’,’k’)

xlabel(‘Time (s)’)

ylabel(‘Thrust (N)’)

title(‘Control effort’) lqi, lqr, setpoint tracking MATLAB Answers — New Questions