LQR Controller for Nonlinear System Tracking with Time-Varying Linearization
Hello everyone,
I’m trying to implement an LQR controller for a nonlinear system to track a reference trajectory. I need to linearize around each point of the trajectory and compute time-varying LQR gains.
My current problem is how to implement the following:
From a nonlinear system: xdot = f(x, u)
I need to linearize around each reference point (x_ref(t), u_ref(t)) to get A(t) and B(t)
Compute LQR gains K(t) at each time step
Apply the control input
My MATLAB code is as follows:
matlab
Q = zeros(size(A));
R = eye(size(B,2));
[K, S, e] = lqr(A, B, Q, R);
A_cl = A – B*K;
B_cl = zeros(size(B));
C_cl = C;
D_cl = D;
sys_cl = ss(A_cl, B_cl, C_cl, D_cl);
[y_cl_dev, t_sim, x_cl_dev] = initial(sys_cl, delta_x0, t);
x_cl_phys = x_cl_dev + repmat(X_op.’, length(t_sim), 1);
y_cl_phys = y_cl_dev + repmat((C*X_op).’, length(t_sim), 1);
My Question:
How can I use ODE45 to, at each point, linearize the system to get A and B, compute K, apply the control input, and then obtain xdot and y?
How convert the
initial
function to a loop-based simulation.
thanks.Hello everyone,
I’m trying to implement an LQR controller for a nonlinear system to track a reference trajectory. I need to linearize around each point of the trajectory and compute time-varying LQR gains.
My current problem is how to implement the following:
From a nonlinear system: xdot = f(x, u)
I need to linearize around each reference point (x_ref(t), u_ref(t)) to get A(t) and B(t)
Compute LQR gains K(t) at each time step
Apply the control input
My MATLAB code is as follows:
matlab
Q = zeros(size(A));
R = eye(size(B,2));
[K, S, e] = lqr(A, B, Q, R);
A_cl = A – B*K;
B_cl = zeros(size(B));
C_cl = C;
D_cl = D;
sys_cl = ss(A_cl, B_cl, C_cl, D_cl);
[y_cl_dev, t_sim, x_cl_dev] = initial(sys_cl, delta_x0, t);
x_cl_phys = x_cl_dev + repmat(X_op.’, length(t_sim), 1);
y_cl_phys = y_cl_dev + repmat((C*X_op).’, length(t_sim), 1);
My Question:
How can I use ODE45 to, at each point, linearize the system to get A and B, compute K, apply the control input, and then obtain xdot and y?
How convert the
initial
function to a loop-based simulation.
thanks. Hello everyone,
I’m trying to implement an LQR controller for a nonlinear system to track a reference trajectory. I need to linearize around each point of the trajectory and compute time-varying LQR gains.
My current problem is how to implement the following:
From a nonlinear system: xdot = f(x, u)
I need to linearize around each reference point (x_ref(t), u_ref(t)) to get A(t) and B(t)
Compute LQR gains K(t) at each time step
Apply the control input
My MATLAB code is as follows:
matlab
Q = zeros(size(A));
R = eye(size(B,2));
[K, S, e] = lqr(A, B, Q, R);
A_cl = A – B*K;
B_cl = zeros(size(B));
C_cl = C;
D_cl = D;
sys_cl = ss(A_cl, B_cl, C_cl, D_cl);
[y_cl_dev, t_sim, x_cl_dev] = initial(sys_cl, delta_x0, t);
x_cl_phys = x_cl_dev + repmat(X_op.’, length(t_sim), 1);
y_cl_phys = y_cl_dev + repmat((C*X_op).’, length(t_sim), 1);
My Question:
How can I use ODE45 to, at each point, linearize the system to get A and B, compute K, apply the control input, and then obtain xdot and y?
How convert the
initial
function to a loop-based simulation.
thanks. lqr, mpc, control, pid MATLAB Answers — New Questions









