% Ballistic missile trajectory & SINS/GPS simulation glvs ts = 0.01; %% trajectory simulation % stage 1: 1/4 circle T = 60; t = (0:ts:T)'; afadot2 = 2*pi/2/T^2; afa = 1/2*afadot2*t.^2; r = 60000; y = r-r*cos(afa); z = r*sin(afa); pitch = pi/2-afa; tt = t; % stage 2: leveling constant acceleration v = (y(end)-y(end-1))/ts; T = 120; t = (ts:ts:T)'; a = -2; y = [y; y(end)+v*t+1/2*a*t.^2]; z = [z; z(end)+t*0]; pitch = [pitch; t*0]; tt = [tt; tt(end)+t]; % stage 3: leveling constant velocity v = (y(end)-y(end-1))/ts; T = 120; t = (ts:ts:T)'; a = -0; y = [y; y(end)+v*t+1/2*a*t.^2]; z = [z; z(end)+t*0]; pitch = [pitch; t*0]; tt = [tt; tt(end)+t]; myfig, plot(y, z, '-'); xygo('front/m','up/m'); %% imu,avp,gps dxyz = [y*0,y,z,tt]; dxyz(:,1:3) = ar1filt(dxyz(:,1:3), 100); pos = dxyz2pos(dxyz); ap = [pitch, zeros(length(pos),2), pos]; [imu, avp0, avp] = ap2imu(ap); imuplot(imu); gps = gpssimu(avp(1:100:end, :), 0.1, 10, 1,0,0, 0); %% sins/gps imuerr = imuerrset(0.15, 100, 0.001, 10); davp = avperrset([1;1;3]*3, [1;1;1], [1;1;3]*100); imu1 = imuadderr(imu,imuerr); ins = insinit(avpadderr(avp0,davp), ts); ins.nts=ts; avp1 = sinsgps(imu1, gps, ins, davp, imuerr); avpcmpplot(avp, avp1(:,[1:9,end]), 'phi');帮我解读这串代码
时间: 2024-04-05 17:35:26 浏览: 164
这段代码实现了一个弹道导弹的轨迹模拟和惯性导航系统的仿真。代码分为三个主要部分:
1. 轨迹模拟:根据一定的飞行轨迹,计算导弹在空间中的位置和姿态角。这里采用了三个阶段的模拟,第一阶段为1/4圆形轨迹,第二阶段为匀加速直线运动,第三阶段为匀速直线运动。
2. 惯性导航系统仿真:使用模拟得到的位置和姿态角数据作为输入,在惯性导航系统中进行姿态解算和位置解算。同时,利用GPS数据对惯性导航系统进行校正。
3. 数据可视化:通过绘制图表的方式将模拟得到的数据可视化展示出来,包括导弹的轨迹、IMU、AVP和GPS的数据。
总体来说,这段代码实现了一个比较完整的弹道导弹的仿真系统,并且提供了可视化的结果展示。
相关问题
% Ballistic missile trajectory & SINS/GPS simulation glvs ts = 0.01; %% trajectory simulation % stage 1: 1/4 circle T = 60; t = (0:ts:T)'; afadot2 = 2*pi/2/T^2; afa = 1/2*afadot2*t.^2; r = 60000; y = r-r*cos(afa); z = r*sin(afa); pitch = pi/2-afa; tt = t; % stage 2: leveling constant acceleration v = (y(end)-y(end-1))/ts; T = 120; t = (ts:ts:T)'; a = -2; y = [y; y(end)+v*t+1/2*a*t.^2]; z = [z; z(end)+t*0]; pitch = [pitch; t*0]; tt = [tt; tt(end)+t]; % stage 3: leveling constant velocity v = (y(end)-y(end-1))/ts; T = 120; t = (ts:ts:T)'; a = -0; y = [y; y(end)+v*t+1/2*a*t.^2]; z = [z; z(end)+t*0]; pitch = [pitch; t*0]; tt = [tt; tt(end)+t]; myfig, plot(y, z, '-'); xygo('front/m','up/m'); %% imu,avp,gps dxyz = [y*0,y,z,tt]; dxyz(:,1:3) = ar1filt(dxyz(:,1:3), 100); pos = dxyz2pos(dxyz); ap = [pitch, zeros(length(pos),2), pos]; [imu, avp0, avp] = ap2imu(ap); imuplot(imu); gps = gpssimu(avp(1:100:end, :), 0.1, 10, 1,0,0, 0); %% sins/gps imuerr = imuerrset(0.15, 100, 0.001, 10); davp = avperrset([1;1;3]*3, [1;1;1], [1;1;3]*100); imu1 = imuadderr(imu,imuerr); ins = insinit(avpadderr(avp0,davp), ts); ins.nts=ts; avp1 = sinsgps(imu1, gps, ins, davp, imuerr); avpcmpplot(avp, avp1(:,[1:9,end]), 'phi');帮我注释代码
以下是对代码的注释:
```matlab
% Ballistic missile trajectory & SINS/GPS simulation
glvs ts = 0.01; % 设置时间步长
%% 轨迹模拟
% 阶段1:1/4圆形轨迹
T = 60; % 转弯时间
t = (0:ts:T)'; % 时间向量
afadot2 = 2*pi/2/T^2; % 角速度
afa = 1/2*afadot2*t.^2; % 角度
r = 60000; % 距离
y = r-r*cos(afa); % y坐标
z = r*sin(afa); % z坐标
pitch = pi/2-afa; % pitch角
tt = t;
% 阶段2:匀加速直线运动
v = (y(end)-y(end-1))/ts; % 初始速度
T = 120; % 时间
t = (ts:ts:T)'; % 时间向量
a = -2; % 加速度
y = [y; y(end)+v*t+1/2*a*t.^2]; % y坐标
z = [z; z(end)+t*0]; % z坐标
pitch = [pitch; t*0]; % pitch角
tt = [tt; tt(end)+t];
% 阶段3:匀速直线运动
v = (y(end)-y(end-1))/ts; % 初始速度
T = 120; % 时间
t = (ts:ts:T)'; % 时间向量
a = -0; % 加速度
y = [y; y(end)+v*t+1/2*a*t.^2]; % y坐标
z = [z; z(end)+t*0]; % z坐标
pitch = [pitch; t*0]; % pitch角
tt = [tt; tt(end)+t];
% 绘制轨迹图
myfig, plot(y, z, '-');
xygo('front/m','up/m');
%% IMU、AVP和GPS
% 计算位置
dxyz = [y*0,y,z,tt];
dxyz(:,1:3) = ar1filt(dxyz(:,1:3), 100);
pos = dxyz2pos(dxyz);
% 计算姿态
ap = [pitch, zeros(length(pos),2), pos];
[imu, avp0, avp] = ap2imu(ap);
% 绘制IMU图
imuplot(imu);
% 生成GPS数据
gps = gpssimu(avp(1:100:end, :), 0.1, 10, 1,0,0, 0);
%% SINS/GPS
% 设置IMU误差和姿态误差
imuerr = imuerrset(0.15, 100, 0.001, 10);
davp = avperrset([1;1;3]*3, [1;1;1], [1;1;3]*100);
% 添加IMU误差
imu1 = imuadderr(imu,imuerr);
% 初始化INS
ins = insinit(avpadderr(avp0,davp), ts);
ins.nts=ts;
% 进行SINS/GPS解算
avp1 = sinsgps(imu1, gps, ins, davp, imuerr);
% 绘制姿态角度对比曲线
avpcmpplot(avp, avp1(:,[1:9,end]), 'phi');
```
阅读全文