% Error Distribution Method and Analysis of Observability Degree Based on the Covariances in Kalman Filter. % Copyright(c) 2009-2021, by Gongmin Yan, All rights reserved. % Northwestern Polytechnical University, Xi An, P.R.China % 2/03/2018, 16/05/2021 glvs avp0 = avpset([0;0;0], [30;108;380]); % init AVP ts = 0.1; T = 600; %% twopos = 2; % =1 for single-position; =2 for two-position alignment if twopos==1 imu = imustatic(avp0, ts, T); elseif twopos==2 xxx = []; seg = trjsegment(xxx, 'init', 0); seg = trjsegment(seg, 'uniform', T/2-10); seg = trjsegment(seg, 'turnleft', 20, 9); seg = trjsegment(seg, 'uniform', T/2-10); trj = trjsimu(avp0, seg.wat, ts, 1); imu = trj.imu; end %% phi = [.1;.1;1]*glv.deg; imuerr = imuerrset(0.03, 100, 0.001, 10); wvn = [0.01;0.01;0.01]; [att0v, attkv, xkpk, kfs] = alignvn_kfs(imuadderr(imu,imuerr), qaddphi(a2qua(avp0(1:3)),phi), avp0(7:9), phi, imuerr, wvn); myfig; % Observability plot spk = sqrt(xkpk(:,13:end-1)); t = xkpk(:,end); for k=1:12, spk(:,k)=spk(1,k)./spk(:,k); end subplot(221), semilogy(t, spk(:,1:3),'linewidth',2); title('( a )'); xygo('Observibility'); legend('\phi_E', '\phi_N', '\phi_U') subplot(222), semilogy(t, spk(:,4:6),'linewidth',2); title('( b )'); xygo('Observibility'); legend('\deltav^n_E', '\deltav^n_N', '\deltav^n_U') subplot(223), semilogy(t, spk(:,7:9),'linewidth',2); title('( c )'); xygo('Observibility'); legend('\epsilon^b_x', '\epsilon^b_y', '\epsilon^b_z') subplot(224), semilogy(t, spk(:,10:12),'linewidth',2); title('( d )'); xygo('Observibility'); legend('\nabla^b_x', '\nabla^b_y', '\nabla^b_z')帮我注释代码
时间: 2023-12-27 07:04:13 浏览: 297
这段代码展示了一个基于卡尔曼滤波器的姿态对准方法,并通过观测度分析评估系统的可观测性。下面是代码的解释:
1. 初始化一个位置和速度:
```matlab
avp0 = avpset([0;0;0], [30;108;380]); % 初始位置和速度
```
2. 设定时间步长和时间:
```matlab
ts = 0.1; % 时间步长
T = 600; % 时间长度
```
3. 选择单位置或双位置对准方法:
```matlab
twopos = 2; % =1 for single-position; =2 for two-position alignment
if twopos==1
imu = imustatic(avp0, ts, T);
elseif twopos==2
xxx = [];
seg = trjsegment(xxx, 'init', 0);
seg = trjsegment(seg, 'uniform', T/2-10);
seg = trjsegment(seg, 'turnleft', 20, 9);
seg = trjsegment(seg, 'uniform', T/2-10);
trj = trjsimu(avp0, seg.wat, ts, 1);
imu = trj.imu;
end
```
4. 设定IMU误差参数和陀螺仪漂移参数:
```matlab
phi = [.1;.1;1]*glv.deg; % 陀螺仪漂移
imuerr = imuerrset(0.03, 100, 0.001, 10); % IMU误差
wvn = [0.01;0.01;0.01]; % 观测噪声
```
5. 使用卡尔曼滤波器进行姿态对准:
```matlab
[att0v, attkv, xkpk, kfs] = alignvn_kfs(imuadderr(imu,imuerr), qaddphi(a2qua(avp0(1:3)),phi), avp0(7:9), phi, imuerr, wvn);
```
6. 绘制可观测度图:
```matlab
myfig; % 创建新的绘图窗口
spk = sqrt(xkpk(:,13:end-1)); % 提取状态协方差矩阵
t = xkpk(:,end); % 提取时间向量
for k=1:12, spk(:,k)=spk(1,k)./spk(:,k); end % 计算可观测度
subplot(221), semilogy(t, spk(:,1:3),'linewidth',2); title('( a )'); xygo('Observibility'); legend('\phi_E', '\phi_N', '\phi_U')
subplot(222), semilogy(t, spk(:,4:6),'linewidth',2); title('( b )'); xygo('Observibility'); legend('\deltav^n_E', '\deltav^n_N', '\deltav^n_U')
subplot(223), semilogy(t, spk(:,7:9),'linewidth',2); title('( c )'); xygo('Observibility'); legend('\epsilon^b_x', '\epsilon^b_y', '\epsilon^b_z')
subplot(224), semilogy(t, spk(:,10:12),'linewidth',2); title('( d )'); xygo('Observibility'); legend('\nabla^b_x', '\nabla^b_y', '\nabla^b_z')
```
这段代码的作用是评估系统在不同状态下的可观测性,即系统是否能够根据观测值准确地估计状态变量。最终,代码绘制了四个子图,分别表示系统的姿态、速度、陀螺仪漂移和加速度计误差在不同时间点的可观测度。
阅读全文