clear all;
clc;
g0=9.78049;
rad_deg=0.01745329;
wie=7.27220417e-5;
Re=6378393.0;
e=3.3670e-3;
Hn=0.01;
Kg=[0.001 0 0
0 0.001 0
0 0 0.001];
Ka=[0.0001 0 0
0 0.0001 0
0 0 0.0001];
G_Drift=[0.01*rad_deg/3600
0.01*rad_deg/3600
0.01*rad_deg/3600];
A_Bias=[1e-4*g0
1e-4*g0
1e-4*g0];
Kg=eye(3)+Kg;
Ka=eye(3)+Ka;
%%%%%%
T_p=8;
T_r=10;
T_y=6;
%%%%%%
pitchm=0*rad_deg;
rollm=0*rad_deg;
yawm=0*rad_deg;
%%%%初始角%%
pitchk=1*rad_deg;
rollk=1*rad_deg;
yawk=30*rad_deg;
%%%%initial phase angle
p_pitch=30*rad_deg;
p_roll=30*rad_deg;
p_yaw=30*rad_deg;
%%%初始误差角%%
pitch_error=0.1*rad_deg;
roll_error=0.1*rad_deg;
yaw_error=0.1*rad_deg;
%%
time=100;
%%% n对应主惯导
lati=45.7796*rad_deg;
longi=126.6705*rad_deg;
wien=[0
wie*cos(lati)
wie*sin(lati)];
%%%p对子惯导
phi=45.7796*rad_deg;
lamda=126.6705*rad_deg;
wiep=[0
wie*cos(phi)
wie*sin(phi)];
g1=g0+0.051799*(sin(phi))^2;
%%%%%% 初始姿态角%%%%
pitch0=pitchm*sin(p_pitch)+pitchk;
roll0=rollm*sin(p_roll)+rollk;
yaw0=yawm*sin(p_yaw)+yawk;
%%%%%
sea_mile=1.852e3/3600;
a0=0;%0.1*g0*sea_mile/time;
aold=[a0*sin(yaw0);a0*cos(yaw0);0];
% aold=[a0;0;0];
v0=[0.0*sea_mile*sin(yaw0);0.0*sea_mile*cos(yaw0);0.0];
v=v0;
a=aold;
Rxp=Re*(1+e*(sin(phi))^2);
Ryp=Re*(1-2*e+3*e*(sin(phi))^2);
wepp=[-v(2)/Ryp
v(1)/Rxp
v(1)*tan(phi)/Rxp];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q=[0 0 0 0]';
%%%%%%建立 初始 捷 联阵
%%%%%%%%%
pitch00=pitch0;
roll00=roll0;
yaw00=yaw0;
Tbn=[cos(roll00)*cos(yaw00) + sin(roll00)*sin(pitch00)*sin(yaw00) cos(pitch00)*sin(yaw00) sin(roll00)*cos(yaw00) - cos(roll00)*sin(pitch00)*sin(yaw00)
-cos(roll00)*sin(yaw00) + sin(roll00)*sin(pitch00)*cos(yaw00) cos(pitch00)*cos(yaw00) -sin(roll00)*sin(yaw00) - cos(roll00)*sin(pitch00)*cos(yaw00)
-sin(roll00)*cos(pitch00) sin(pitch00) cos(roll00)*cos(pitch00)];
T(1,1) = cos(roll0+roll_error)*cos(yaw0+yaw_error) + sin(roll0+roll_error)*sin(pitch0+pitch_error)*sin(yaw0+yaw_error);
T(1,2) = cos(pitch0+pitch_error)*sin(yaw0+yaw_error);
T(1,3) = sin(roll0+roll_error)*cos(yaw0+yaw_error) - cos(roll0+roll_error)*sin(pitch0+pitch_error)*sin(yaw0+yaw_error);
T(2,1) = -cos(roll0+roll_error)*sin(yaw0+yaw_error) + sin(roll0+roll_error)*sin(pitch0+pitch_error)*cos(yaw0+yaw_error);
T(2,2) = cos(pitch0+pitch_error)*cos(yaw0+yaw_error);
T(2,3) = -sin(roll0+roll_error)*sin(yaw0+yaw_error) - cos(roll0+roll_error)*sin(pitch0+pitch_error)*cos(yaw0+yaw_error);
T(3,1) = -sin(roll0+roll_error)*cos(pitch0+pitch_error);
T(3,2) = sin(pitch0+pitch_error);
T(3,3) = cos(roll0+roll_error)*cos(pitch0+pitch_error);
% TT=[1 yaw_error -roll_error
% -yaw_error 1 pitch_error
% roll_error -pitch_error 1 ];
TT=T*inv(Tbn)
T=TT*Tbn;
dp=TT(2,3)/rad_deg*60
dr=TT(3,1)/rad_deg*60
dy=TT(1,2)/rad_deg*60
q(1) = sqrt(1+T(1,1)+T(2,2)+T(3,3))/2.0;
q(2) = (T(3,2)-T(2,3))/(4*q(1));
q(3) = (T(1,3)-T(3,1))/(4*q(1));
q(4) = (T(2,1)-T(1,2))/(4*q(1));
Tn=time/Hn;
X=[0;
0;
0;
0;
0];
H=[1 0 0 0 0 ;
0 1 0 0 0 ];
P = zeros(5);
P(1,1) = 0.1^2;
P(2,2) = 0.1^2;
P(3,3) = power(1*rad_deg,2);
P(4,4) = power(1*rad_deg,2);
P(5,5) = power(1*rad_deg,2);
Q=zeros(5);
Q(1,1) = power(0.5*A_Bias(1),2);
Q(2,2) = power(0.5*A_Bias(2),2);
Q(3,3) = power(0.5*G_Drift(1),2);
Q(4,4) = power(0.5*G_Drift(2),2);
Q(5,5) = power(0.5*G_Drift(3),2);
R=zeros(2);
R(1,1) = power(0.001,2);
R(2,2) = power(0.001,2);
C=zeros(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:Tn
for i=1:3
pitchT(i) = pitchm*sin(2*pi*(k-(3-i)/2)*Hn/T_p+p_pitch)+pitchk;
rollT(i) = rollm*sin(2*pi*(k-(3-i)/2)*Hn/T_r+p_roll)+rollk;
yawT(i) = yawm*sin(2*pi*(k-(3-i)/2)*Hn/T_y+p_yaw)+yawk;
wpT(i) = 2*pi/T_p*pitchm*cos(2*pi*(k-(3-i)/2)*Hn/T_p+p_pitch);
wrT(i) = 2*pi/T_r*rollm*cos(2*pi*(k-(3-i)/2)*Hn/T_r+p_roll);
wyT(i) = 2*pi/T_y*yawm*cos(2*pi*(k-(3-i)/2)*Hn/T_y+p_yaw);
end
Tbn=[cos(rollT(3))*cos(yawT(3)) + sin(rollT(3))*sin(pitchT(3))*sin(yawT(3)) cos(pitchT(3))*sin(yawT(3)) sin(rollT(3))*cos(yawT(3)) - cos(rollT(3))*sin(pitchT(3))*sin(yawT(3))
-cos(rollT(3))*sin(yawT(3)) + sin(rollT(3))*sin(pitchT(3))*cos(yawT(3)) cos(pitchT(3))*cos(yawT(3)) -sin(rollT(3))*sin(yawT(3)) - cos(rollT(3))*sin(pitchT(3))*cos(yawT(3))
-sin(rollT(3))*cos(pitchT(3)) sin(pitchT(3)) cos(rollT(3))*cos(pitchT(3))];
for i=1:3
wnbb(1,i) = sin(rollT(i))*cos(pitchT(i))*wyT(i) + cos(rollT(i))*wpT(i);
wnbb(2,i) = -sin(pitchT(i))*wyT(i) + wrT(i);
wnbb(3,i) = -cos(rollT(i))*cos(pitchT(i))*wyT(i) + sin(rollT(i))*wpT(i);
end
wnbb1=[wnbb(1,1)
wnbb(2,1)
wnbb(3,1)];
wnbb2=[wnbb(1,2)
wnbb(2,2)
wnbb(3,2)];
wnbb3=[wnbb(1,3)
wnbb(2,3)
wnbb(3,3)];
%%%%%%%%%%%%%%%%%%%%%
Rxt = Re*(1+e*sin(lati)*sin(lati));
Ryt = Re*(1-2*e+3*e*sin(lati)*sin(lati));
%%%%%%%%%%%%%%%%%%%
v00=v0;
v0(1) = v0(1)+a(1)*Hn;
v0(2) = v0(2)+a(2)*Hn;
wenn(1,1) = -v0(2)/Ryt;
wenn(2,1) = v0(1)/Rxt;
wenn(3,1) = v0(1)*tan(lati)/Rxt;
%%%%%%%%%%%%
longi= longi+(v00(1)+v0(1))/2*Hn/(Rxt*cos(lati));
lati = lati+(v00(2)+v0(2))/2*Hn/Ryt;
wien=[0;
wie*cos(lati);
wie*sin(lati)];
winn=wien+wenn;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
for i=1:3
Tnb11(i) = cos(rollT(i))*cos(yawT(i)) + sin(rollT(i))*sin(pitchT(i))*sin(yawT(i));
Tnb12(i) = -cos(rollT(i))*sin(yawT(i)) + sin(rollT(i))*sin(pitchT(i))*cos(yawT(i));
Tnb13(i) = -sin(rollT(i))*cos(pitchT(i));
Tnb21(i) = cos(pitchT(i))*sin(yawT(i));
Tnb22(i) = cos(pitchT(i))*cos(yawT(i));
Tnb23(i) = sin(pitchT(i));
Tnb31(i) = sin(rollT(i))*cos(yawT(i)) - cos(rollT(i))*sin(pitchT(i))*sin(yawT(i));
Tnb32(i) = -sin(rollT(i))*sin(yawT(i)) - cos(rollT(i))*sin(pitchT(i))*cos(yawT(i));
Tnb33(i) = cos(rollT(i))*cos(pitchT(i));
end
%%%%%导航 坐标系到 载体坐标
Tnb1=[Tnb11(1) Tnb12(1) Tnb13(1)
Tnb21(1) Tnb22(1) Tnb23(1)
Tnb31(1) Tnb32(1) Tnb33(1)];
Tnb2=[Tnb11(2) Tnb12(2) Tnb13(2)
Tnb21(2) Tnb22(2) Tnb23(2)
Tnb31(2) Tnb32(2) Tnb33(2)];
Tnb3=[Tnb11(3) Tnb12(3) Tnb13(3)
Tnb21(3) Tnb22(3) Tnb23(3)
Tnb31(3) Tnb32(3) Tnb33(3)];
winb1=Tnb1*winn;
winb2=Tnb2*winn;
winb3=Tnb3*winn;
wibb1=winb1+wnbb1;
wibb2=winb2+wnbb2;
wibb3=winb3+wnbb3;
%%%%%%%%%%%%%%%%%%%%%%
fn(1,1) = a(1) - (2*wien(3)+wenn(3))*v0(2)+(2*wien(2)+wenn(2))*v0(1);
fn(2,1) = a(2) + (2*wien(3)+wenn(3))*v0(1)+wien(1)*v0(1);
fn(3,1) = a(3) + wien(1)*v0(2) - (2*wien(2)+wenn(2))*v0(1) + g1;
%%%%%%%%%%%%%%%%
fbb1=Tnb1*fn;
fbb2=Tnb2*fn;
fbb3=Tnb3*fn;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
noisewe=0.1*G_Drift*randn(1);
noisewn=0.1*G_Drift*randn(1);
noisewd=0.1*G_Drift*randn(1);
noisefe=0.1*G_Drift*randn(1);
noisefn=0.1*G_Drift*randn(1);
noisefd=0.1*G_Drift*randn(1);
wib1=Kg*wibb1+G_Drift+noisewe;
wib2=Kg*wibb2+G_Drift+noisewn;
wib3=Kg*wibb3+G_Drift+noisewd;
fb1=Ka*fbb1+A_Bias+noisefe;
fb2=Ka*fbb2+A_Bias+noisefn;
fb3=Ka*fbb3+A_Bias+noisefd;
% Q(1,1) = power(noisefe(1,1),2);
% Q(2,2) = power(noisefn(1,1),2);
% Q(3,3) = power(noisewe(1,1),2);
% Q(4,4) = power(noisewn(1,1),2);
% Q(5,5) = power(noisewd(1,1),2);
%%%%%%%%%%%%%%
q0 = q;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wpbb1=wib1-inv(T)*(wepp+wiep);
wpbb2=wib2-inv(T)*(wepp+wiep);
wpbb3=wib3-inv(T)*(wepp+wiep);
omiga1=[0 -wpbb1(1) -wpbb1(2) -wpbb1(3);
wpbb1(1) 0 wpbb1(3) -wpbb1(2);
wpbb1(2) -wpbb1(3) 0 wpbb1(1);
wpbb1(3) wpbb1(2) -wpbb1(1) 0 ];
omiga2=[0 -wpbb2(1) -wpbb2(2) -wpbb2(3)
wpbb2(1) 0 wpbb2(3) -wpbb2(2)
wpbb2(2) -wpbb2(3) 0 wpbb2(1)
wpbb2(3) wpbb2(2) -wpbb2(1) 0 ];
omiga3=[0 -wpbb3(1) -wpbb3(2) -wpbb3(3)
wpbb3(1) 0 wpbb3(3) -wpbb3(2)
wpbb3(2) -wpbb3(3) 0 wpbb3(1)
wpbb3(3) wpbb3(2) -wpbb3(1) 0 ];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
k1 = 1/2*omiga1*q;
q=q0+k1*Hn/2;
k2=1/2*omiga2*q;
q=q0+k2*Hn/2;
k3=1/2*omiga2*q;
q=q0+k3*Hn;
k4=1/2*omiga3*q;
q=q0+(k1+2*k2+2*k3+k4)/6*Hn;
q=q/sqrt(q(1)^2+q(2)^2+q(3)^2+q(4)^2);
T=[q(1)^2+q(2)^2-q(3)^2-q(4)^2 2*(q(2)*q(3)-q(1)*q(4)) 2*(q(2)*q(4)+q(1)*q(3))
2*(q(2)*q(3)+q(1)*q(4)) q(1)^2-q(2)^2+q(3)^2-q(4)^2 2*(q(3)*q(4)-q(1)*q(2))
2*(q(2)*q(4)-q(1)*q(3)) 2*(q(3)*q(4)+q(1)*q(2)) q(1)^2-q(2)^2-q(3)^2+q(4)^2];
fp=T*fb3;
f_vx = fp(1) + (2*wiep(3)+wepp(3))*v(2);
f_vy = fp(2) - (2*wiep(3)+wepp(3))*v(1);
v(1) = v(1) + f_vx*Hn;
v(2) = v(2) + f_vy*Hn;
wepp = [-v(2)/Ryp;
v(1)/Rxp;
v(1)*tan(phi)/Rxp];
phi = phi+v(2)*Hn/Ryp;
lamda= lamda+v(1)*Hn/(Rxp*cos(phi));
wiep = [0; wie*cos(phi); wie*sin(phi)];
g1 = g0+0.051799*sin(phi)*sin(phi);
z=v-v0-0.001*randn(3,1);
Z=[z(1)
z(2)];
r=3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A1 =[0 2*wiep(3)+wepp(3) 0 -fp(3) fp(2)
% -(2*wiep(3)+wepp(3)) 0 fp(3) 0 -fp(1)
% 0 -1/Ryp 0 wiep(3)+v(1)*tan(phi)/Rxp -(wiep(2)+wepp(2))
% 1/Rxp 0 -(wiep(3)+wepp(3)) 0 wepp(1)
% 1*tan(phi)/Rxp 0 wiep(2)+wepp(2) v(2)/Ryp 0 ];
% G1=[ 1 0 0 0 0
% 0 1 0 0 0
% 0 0 1 0 0
% 0 0 0 1 0
% 0 0 0 0 1];
% C1=zeros(5,5);
% C1(1,1)=1;
% C1(2,2)=1;
% L1=eye(5);
% A=A1;
% B1=L1;
% B2=C1;
% C=G1;
% B=[B1,B2];
% m1=size(B1,2)
% m2=size(B2,2);
% R=[-r^2*eye(m1) zeros(m1,m2) ;zeros(m2,m1) eye(m2)];
% P=care(A,B,C'*C,R)
% ans=A'*P+P*A-P*B*inv(R)*[B1';B2']*P+C1'*C1
% KK=P*C1';
% step=0.1;
% PP=A1-KK*C1;
% QQ=KK*y;
% [FF,GG]=c2d(PP,KK,step);
% X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rad_deg*60;
end
j=1:length(datx1);
figure(1)
subplot(3,1,1)
plot(j/10,(datx1(j)-dp(1)))
subplot(3,1,2)
plot(j/10,(datx2(j)-dr(1)))
subplot(3,1,3)
plot(j/10,(datx3(j)-dy(1)))
j=1:length(datx1);
figure(2)
subplot(3,1,1)
plot(j/10,(datx1(j)))
subplot(3,1,2)
plot(j/10,(datx2(j)))
subplot(3,1,3)
plot(j/10,(datx3(j)))
|