www.pudn.com > SHIPCONTROL.rar > PIDshipcoursecontrol.m, change:2014-01-06,size:5687b


function PIDshipcoursecontrol 
clear all;clc; 
global m L D delta B midu CB ZG H T  Dp np  tp b1 b2  P hR  te epxlong hs; 
m=55000*10^3; 
L=280; 
D=9.45; 
B=35.5; 
midu=1000; 
CB=0.597; 
ZG=14; 
H=2.9; 
T=0.058*D; 
Dp=4.3; 
np=3; 
tp=0.167; 
b1=6.5; 
b2=4.6; 
P=3.7; 
hR=7.2; 
epxlong=0.9; 
hs=6.9; 
te=2.5; 
%delta=1.5708; 
% t0=0; 
% tf=2000; 
% tspan=[t0,tf]; 
buchang=1; 
n=2000; 
ssdr=0; 
% for hii=1:1000 
%Kp=0.9; 
Kp=2.1; 
Td=0.9; 
Ti=0.01; 
delta0=0.5; 
delta=1; 
deltae=pi/20; 
x00=zeros(1,n); 
y00=zeros(1,n); 
bosai0=zeros(1,n); 
sdd=-1; 
 
Y0=[0 0 0 0 9.2 0 0 0]; 
for i=2:2:n 
tspan=[(i-1)*buchang,i*buchang,(i+1)*buchang]; 
%delta=deltae-(deltae-delta0)*exp(-buchang/te); 
 
%plot(delta);pause(0.001) 
hold on 
[time,ee]=ode45(@DYDT,tspan,Y0,[],deltae,delta0); 
Y0=ee(end,:); 
YY(i:i+1,:)=ee(2:3,:); 
 
%delta=YY(i,9); 
if i>2 
x00(i)=2*(YY(i,5)*cos(YY(i,3))-YY(i,6)*cos(YY(i,4))*sin(YY(i,3)))+x00(i-2); 
 
y00(i)=2*(YY(i,5)*sin(YY(i,3))+YY(i,6)*cos(YY(i,4))*cos(YY(i,3)))+y00(i-2); 
bosai0(i)=(YY(i,7)*cos(YY(i,4)))*2+bosai0(i-2); 
end 
 
%YY01(i)=YY(i,3);                     %atan2(y00(i),x00(i)); 
% y09=YY(i,9); 
% plot(y09); pause(0.001); 
% hold on 
plot(x00(i),y00(i)); pause(0.001); 
hold on 
plot(i,bosai0(i));pause(0.001); 
hold  on 
%hold on 
%plot(YY(i,9));pause(0.001); 
% 
% bosai0=YY(:,3); 
% FAI0=YY(:,4); 
% u=YY(i,5); 
% v=YY(:,6); 
% r=YY(:,7); 
% p=YY(:,8); 
if i>2 
% deltae=deltae+Kp*(1+buchang/Ti+Td/buchang)*(sdd-YY(i,3))-Kp*(1+2*Td/buchang)*(sdd-YY(i-1,3))+Kp*(Td/buchang)*(sdd-YY(i-2,3)); 
deltae=deltae-((Kp+Ti/2+Td)*(sdd-bosai0(i))+(Ti/2-Kp-2*Td)*(sdd-bosai0(i-1))+Td*(sdd-bosai0(i-2))); 
%dj=dj+(Kp+Ti/2+Td)*(sdd-YY01(i))+(Ti/2-Kp-2*Td)*(sdd-YY01(i-1))+Td*(sdd-YY01(i-2)); 
%dj=dj+Kp*(1+2/Ti+Td/2)*(YY01(i)-sdd)-Kp*(1+2*Td/2)*(YY01(i-1)-sdd)+Kp*(Td/2)*(YY01(i-2)-sdd); 
%deltae=um*tanh(dj/um); 
end  
delta0=delta 
%max(abs(YY(i,3))) 
% if (i>1000)&&(abs(YY(i,3))<0.15) 
%     Kp 
%     ssdr=1; 
%     break 
% end 
end 
 
% if ssdr==1 
%     break 
% end 
% end 
 
% [hang,lie]=size(x); 
% x0=zeros(1,hang); 
% y0=zeros(1,hang); 
% bosai0=zeros(1,hang); 
% FAI0=zeros(1,hang); 
% for i=2:hang-1 
%     x0(i+1)=(u(i)*cos(bosai(i))-v(i)*cos(FAI(i))*sin(bosai(i)))*(time(i)-time(i-1))+x0(i); 
%     y0(i+1)=(u(i)*sin(bosai(i))+v(i)*cos(FAI(i))*cos(bosai(i)))*(time(i)-time(i-1))+y0(i); 
%     bosai0(i+1)=(r(i)*cos(FAI(i)))*(time(i)-time(i-1))+bosai0(i); 
%     FAI0(i+1)=p(i)*(time(i)-time(i-1))+FAI0(i); 
% end 
 
function  dy=DYDT(t,y,deltae,delta0) 
% 船型参数 螺旋桨参数  舵参数 
global m L D B midu CB ZG H T  Dp np  tp b1 b2  P hR  epxlong hs delta te;%deltae  delta0 
 
dy=zeros(8,1); 
FAI=y(4); 
u=y(5); 
v=y(6); 
r=y(7); 
p=y(8); 
%delta=y(9); 
V=sqrt(u^2+v^2); 
RP=r*L/V; 
Beita=atan(-v/u); 
 
% 各纬度惯性矩及附加质量的计算 
IZ=m* (0.245*L)^2;   %(1+CB^4.5)+(L^2+B^2.4)/24; 
m11=m*(1/100)*(0.398+11.98*CB*(1+3.73*(D/B))-(2.89*CB*(L/B))*(1+1.13*(D/B))+0.175*CB*(L/B)^2*(1+0.541*(D/B))-1.107*(L/B)*(D/B)); 
m22=m*(0.882-0.54*CB*(1-1.6*(D/B))-0.156*(1-0.673*CB)*(L/B)+0.826*(D/B)*(L/B)*(1-0.678*(D/B))-0.638*(L/B)*(D/B)*(1-0.669*(D/B))); 
m66=m*(L*0.01*(33-76.85*CB*(1-0.784*CB)+3.43*(L/B)*(1-0.63*CB)))^2; 
%m26=0.5*pi*MIDU*(L*D)^2*(0.67*(B/L)-0.0033*(B/D)^2); 
 
 
%纵向水动力的计算 
Xu=59.12*u^4-462.8*u^3+8775*u^2+28940*u+67640; 
XVR=(1.6757*CB-0.5054-1)*m22; 
XH=XVR*v*r-Xu; 
 
 
%横向水动力的计算 
K=2*D/L;TP=T/D; 
Yv=-0.5*midu*L*D*V*(pi*K/2+1.4*CB*(B/L))*(1+0.67*TP); 
Yr=0.5*midu*L^2*D*V*(pi*K/4)*(1+0.8*TP); 
Yvv=0.5*midu*L*D*(0.048265-6.293*(1-CB)*(D/B)); 
Yvr=0.5*midu*L^2*D*(-0.3791+1.28*(1-CB)*(D/B)); 
Yrr=0.5*midu*L^3*D*(0.0045-0.445*(1-CB)*(D/B)); 
YH=Yv*v+Yr*r+Yvv*v*abs(v)+Yvr*r*abs(v)+Yrr*r*abs(r); 
 
 
 
%首摇力矩的计算 
Lv=K/(0.5*pi*K+1.4*CB*(B/L)); 
Nv=-0.5*midu*L^2*D*V*K*(1-0.27*TP/Lv); 
Nr=-0.5*midu*L^3*D*V*(0.54*K-K^2)*(1+0.3*TP); 
Nvvr=0.5*midu*L^3*D*(-6.0856+137.4735*CB*(B/L)-1029.514*(CB*(B/L))^2+2480.6082*(CB*(B/L))^3); 
Nvrr=0.5*midu*L^4*D*(-0.0635+0.044145*CB*(D/B)); 
Nrr=0.5*midu*L^4*D*(-0.0805+8.6092*(CB*(B/L))^2-36.9816*(CB*(B/L))^3); 
Nvfai=0.5*midu*L^2*D*V*(-1.72*K); 
Nrfai=0.5*midu*L^3*D*V*(2.6*(0.54*K-K^2)); 
Nfai=0.5*midu*L^2*D*V^2*(-0.008); 
 
NH=Nv*v+Nr*r+Nvvr*v^2*r+Nrr*r*abs(r)+Nvrr*v*r^2+Nfai*FAI+Nvfai*v*abs(FAI)+Nrfai*r*abs(FAI); 
 
%横倾力矩的计算 
 
Np=0.12*sqrt((m*(B^2+4*ZG^2)/(12))*H*m*9.8); 
GZFAI=H*sin(FAI); 
ZH=ZG-(4-B/D+0.02*(B/D-5.35)^3)*D; 
 
KH=-Np*p-m*9.8*GZFAI-YH*ZH; 
 
 
%螺旋桨纵向推进力计算 
wp0=0.5*CB-0.05; 
 
Beitap=Beita-0.5*RP; 
wp=wp0*exp(-4*Beitap^2); 
Jp=u*(1-wp)/(Dp*np); 
Kt=0.25035*Jp^3-0.58638*Jp^2-0.067363*Jp+0.42379; 
 
XP=(1-tp)*midu*np^2*Dp^4*Kt; 
 
%舵力的计算  
delta=deltae-(deltae-delta0)*exp(-t/te); 
S=1-u*(1-wp)/(np*P); 
te=2.5; 
lamuda=2*hR/(b1+b2); 
fa=6.13*lamuda/(2.25+lamuda); 
sita=Dp/hR; 
gs=sita*(0.6/epxlong)*S*(2-(2-(0.6/epxlong))*S)/(1-S)^2; 
 
if delta>0 
    c1=1.065; 
else 
    c1=0.935; 
end 
 
uR=u*(1-wp)*sqrt(1+c1*gs); 
vR=(1.163314-1.982836*CB+1.390152*CB^2)*(v-L*r); 
UR=sqrt(uR^2+vR^2); 
% S0=1-u*(1-wp0)/np*P; 
% delta0=-(2*S0+0.6); 
alfaR=delta-atan(vR/uR);  %-delta0 
 
tR=1-(0.7382-0.0539*CB+0.1755*CB^2); 
aH=0.6784-1.3374*CB+1.8891*CB^2; 
xR=-0.5*L; 
xH=-(0.4+0.1*CB)*L; 
zR=ZG-D+hs; 
 
FN=0.5*midu*0.5*(b1+b2)*hR*fa*UR^2*sin(alfaR); 
 
 
XR=-(1-tR)*FN*sin(delta); 
YR=(1+aH)*FN*cos(delta); 
NR=(xR+aH*xH)*FN*cos(delta); 
KR=(1+aH)*zR*FN*cos(delta); 
 
% dy(1)=y(5); 
% dy(2)=y(6); 
% dy(3)=y(7); 
% dy(4)=y(8); 
 
dy(1)=y(5); 
dy(2)=y(6); 
dy(3)=y(7); 
dy(4)=y(8); 
dy(5)=(XH+XP+XR+(m+m22)*y(6)*y(7))/(m+m11); 
dy(6)=(YH+YR-(m+m11)*y(5)*y(7))/(m+m22); 
dy(7)=(NH+NR)/(IZ+m66); 
dy(8)=(KH+KR)/(m*(B^2+4*ZG^2)/12); 
%dy(9)=(deltae-y(9))/te; 
 
 
 
 
 
 
% figure 
% plot(bosai0); 
% figure 
% plot(FAI0);