《基于 LQR 的两轮机器人的平衡控制》
m文件与仿真
% 二阶被控系统,一个输入量
clc;clear;close all
A=[0 1 0 0; 0 0 -23.7097 0; 0 0 0 1; 0 0 83.7742 0];
B=[0 ; 3.6663; 0; -9.9595];
C=[1 0 0 0; 0 0 1 0];
D=0;
Q=[700 0 0 0;0 10 0 0; 0 0 900 0; 0 0 0 30];
R=1;
K=lqr(A,B,Q,R);
sys=ss(A-B*K,B,C,D);%经过状态量反馈后的新状态矩阵
t=0:0.01:4;
x0=[0;0;0.2618;0];
[y,t,x]=initial(sys,x0,t);
plot(t,x(:,1),LineWidth=1.5);hold on
plot(t,x(:,2),LineWidth=1.5);grid on
plot(t,x(:,3),LineWidth=1.5);grid on
plot(t,x(:,4),LineWidth=1.5);grid on
xlabel('t');
ylabel(x);
legend('x1','x2','x3','x4')
simulink模型与仿真