📄 nlplant.c
字号:
Cy = -.02*beta + .021*dail + .086*drud; cz(alpha,beta,el,temp); Cz = temp[0];/*################################################## /*################################################## ## Set all higher order terms of hifi that are ## ## not applicable to lofi equal to zero. ######## ##################################################*/ delta_Cx_lef = 0.0; delta_Cz_lef = 0.0; delta_Cm_lef = 0.0; delta_Cy_lef = 0.0; delta_Cn_lef = 0.0; delta_Cl_lef = 0.0; delta_Cxq_lef = 0.0; delta_Cyr_lef = 0.0; delta_Cyp_lef = 0.0; delta_Czq_lef = 0.0; delta_Clr_lef = 0.0; delta_Clp_lef = 0.0; delta_Cmq_lef = 0.0; delta_Cnr_lef = 0.0; delta_Cnp_lef = 0.0; delta_Cy_r30 = 0.0; delta_Cy_a20 = 0.0; delta_Cy_a20_lef= 0.0; delta_Cn_a20_lef= 0.0; delta_Cl_a20_lef= 0.0; delta_Cnbeta = 0.0; delta_Clbeta = 0.0; delta_Cm = 0.0; eta_el = 1.0; /* Needs to be one. See equation for Cm_tot*/ delta_Cm_ds = 0.0; /*################################################## ##################################################*/ }/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%compute Cx_tot, Cz_tot, Cm_tot, Cy_tot, Cn_tot, and Cl_tot(as on NASA report p37-40)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *//* XXXXXXXX Cx_tot XXXXXXXX */dXdQ = (cbar/(2*vt))*(Cxq + delta_Cxq_lef*dlef);Cx_tot = Cx + delta_Cx_lef*dlef + dXdQ*Q; /* ZZZZZZZZ Cz_tot ZZZZZZZZ */ dZdQ = (cbar/(2*vt))*(Czq + delta_Cz_lef*dlef);Cz_tot = Cz + delta_Cz_lef*dlef + dZdQ*Q; /* MMMMMMMM Cm_tot MMMMMMMM */ dMdQ = (cbar/(2*vt))*(Cmq + delta_Cmq_lef*dlef);Cm_tot = Cm*eta_el + Cz_tot*(xcgr-xcg) + delta_Cm_lef*dlef + dMdQ*Q + delta_Cm + delta_Cm_ds; /* YYYYYYYY Cy_tot YYYYYYYY */dYdail = delta_Cy_a20 + delta_Cy_a20_lef*dlef;dYdR = (B/(2*vt))*(Cyr + delta_Cyr_lef*dlef);dYdP = (B/(2*vt))*(Cyp + delta_Cyp_lef*dlef);Cy_tot = Cy + delta_Cy_lef*dlef + dYdail*dail + delta_Cy_r30*drud + dYdR*R + dYdP*P; /* NNNNNNNN Cn_tot NNNNNNNN */ dNdail = delta_Cn_a20 + delta_Cn_a20_lef*dlef;dNdR = (B/(2*vt))*(Cnr + delta_Cnr_lef*dlef);dNdP = (B/(2*vt))*(Cnp + delta_Cnp_lef*dlef);Cn_tot = Cn + delta_Cn_lef*dlef - Cy_tot*(xcgr-xcg)*(cbar/B) + dNdail*dail + delta_Cn_r30*drud + dNdR*R + dNdP*P + delta_Cnbeta*beta; /* LLLLLLLL Cl_tot LLLLLLLL */dLdail = delta_Cl_a20 + delta_Cl_a20_lef*dlef;dLdR = (B/(2*vt))*(Clr + delta_Clr_lef*dlef);dLdP = (B/(2*vt))*(Clp + delta_Clp_lef*dlef);Cl_tot = Cl + delta_Cl_lef*dlef + dLdail*dail + delta_Cl_r30*drud + dLdR*R + dLdP*P + delta_Clbeta*beta; /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% compute Udot,Vdot, Wdot,(as on NASA report p36) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */Udot = R*V - Q*W - g*st + qbar*S*Cx_tot/m + T/m;Vdot = P*W - R*U + g*ct*sphi + qbar*S*Cy_tot/m;Wdot = Q*U - P*V + g*ct*cphi + qbar*S*Cz_tot/m; /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% vt_dot equation (from S&L, p82) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */xdot[6] = (U*Udot + V*Vdot + W*Wdot)/vt; /* %%%%%%%%%%%%%%%%%% alpha_dot equation %%%%%%%%%%%%%%%%%% */xdot[7] = (U*Wdot - W*Udot)/(U*U + W*W); /* %%%%%%%%%%%%%%%%% beta_dot equation %%%%%%%%%%%%%%%%% */xdot[8] = (Vdot*vt - V*xdot[6])/(vt*vt*cb); /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% compute Pdot, Qdot, and Rdot (as in Stevens and Lewis p32) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */L_tot = Cl_tot*qbar*S*B; /* get moments from coefficients */M_tot = Cm_tot*qbar*S*cbar;N_tot = Cn_tot*qbar*S*B;denom = Jx*Jz - Jxz*Jxz; /* %%%%%%%%%%%%%%%%%%%%%%% Pdot %%%%%%%%%%%%%%%%%%%%%%% */xdot[9] = (Jz*L_tot + Jxz*N_tot - (Jz*(Jz-Jy)+Jxz*Jxz)*Q*R + Jxz*(Jx-Jy+Jz)*P*Q + Jxz*Q*Heng)/denom; /* %%%%%%%%%%%%%%%%%%%%%%% Qdot %%%%%%%%%%%%%%%%%%%%%%% */xdot[10] = (M_tot + (Jz-Jx)*P*R - Jxz*(P*P-R*R) - R*Heng)/Jy; /* %%%%%%%%%%%%%%%%%%%%%%% Rdot %%%%%%%%%%%%%%%%%%%%%%% */xdot[11] = (Jx*N_tot + Jxz*L_tot + (Jx*(Jx-Jy)+Jxz*Jxz)*P*Q - Jxz*(Jx-Jy+Jz)*Q*R + Jx*Q*Heng)/denom;/*########################################*//*### Create accelerations anx_cg, any_cg *//*### ans anz_cg as outputs ##############*//*########################################*/accels(xu,xdot,temp);xdot[12] = temp[0]; /* anx_cg */xdot[13] = temp[1]; /* any_cg */xdot[14] = temp[2]; /* anz_cg */xdot[15] = mach;xdot[16] = qbar;xdot[17] = ps;/*########################################*//*########################################*/free(temp);}; /*##### END of nlplant() ####*//*########################################*//*### Called Sub-Functions ##############*//*########################################*//*########################################*//* Function for mach and qbar *//*########################################*/void atmos(double alt, double vt, double *coeff ){ double rho0 = 2.377e-3; double tfac, temp, rho, mach, qbar, ps; tfac =1 - .703e-5*(alt); temp = 519.0*tfac; if (alt >= 35000.0) { temp=390; } rho=rho0*pow(tfac,4.14); mach = (vt)/sqrt(1.4*1716.3*temp); qbar = .5*rho*pow(vt,2); ps = 1715.0*rho*temp; if (ps == 0){ ps = 1715; } coeff[0] = mach; coeff[1] = qbar; coeff[2] = ps;}/*########################################*//*########################################*//*########################################*//*### Port from matlab fix() function ####*//*########################################*/int fix(double in){ int out; if (in >= 0.0){ out = (int)floor(in); } else if (in < 0.0){ out = (int)ceil(in); } return out;}/* port from matlab sign() function */int sign(double in){ int out; if (in > 0.0){ out = 1; } else if (in < 0.0){ out = -1; } else if (in == 0.0){ out = 0; } return out;}/*########################################*//*########################################*//*########################################*//*### Calculate accelerations from states *//*### and state derivatives. ############ *//*########################################*/void accels(double *state, double *xdot, double *y){#define grav 32.174 double sina, cosa, sinb, cosb ;double vel_u, vel_v, vel_w ;double u_dot, v_dot, w_dot ;double nx_cg, ny_cg, nz_cg ;sina = sin(state[7]) ;cosa = cos(state[7]) ;sinb = sin(state[8]) ;cosb = cos(state[8]) ;vel_u = state[6]*cosb*cosa ;vel_v = state[6]*sinb ;vel_w = state[6]*cosb*sina ;u_dot = cosb*cosa*xdot[6] - state[6]*sinb*cosa*xdot[8] - state[6]*cosb*sina*xdot[7] ;v_dot = sinb*xdot[6] + state[6]*cosb*xdot[8] ;w_dot = cosb*sina*xdot[6] - state[6]*sinb*sina*xdot[8] + state[6]*cosb*cosa*xdot[7] ;nx_cg = 1.0/grav*(u_dot + state[10]*vel_w - state[11]*vel_v) + sin(state[4]) ;ny_cg = 1.0/grav*(v_dot + state[11]*vel_u - state[9]*vel_w) - cos(state[4])*sin(state[3]) ;nz_cg = -1.0/grav*(w_dot + state[9]*vel_v - state[10]*vel_u) + cos(state[4])*cos(state[3]) ;y[0] = nx_cg ;y[1] = ny_cg ;y[2] = nz_cg ;} /*########################################*//*########################################*//*########################################*//*########################################*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -