⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nlplant.c

📁 一个F-16仿真程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "math.h"/*  Merging the nlplant.c (lofi) and nlplant_hifi.c to use    same equations of motion, navigation equations and use     own look-up tables decided by a flag.                   */    void atmos(double,double,double*);          /* Used by both */void accels(double*,double*,double*);       /* Used by both */#include "lofi_F16_AeroData.c"              /* LOFI Look-up header file*/#include "hifi_F16_AeroData.c"              /* HIFI Look-up header file*/void nlplant(double*,double*);/*########################################*//*### Added for mex function in matlab ###*//*########################################*/int fix(double);int sign(double);void mexFunction(int nlhs, mxArray *plhs[],                 int nrhs, const mxArray *prhs[]){#define XU prhs[0]#define XDOTY plhs[0]int i;double *xup, *xdotp;if (mxGetM(XU)==18 && mxGetN(XU)==1){       /* Calling Program */      xup = mxGetPr(XU);      XDOTY = mxCreateDoubleMatrix(18, 1, mxREAL);      xdotp = mxGetPr(XDOTY);      nlplant(xup,xdotp);      /* debug      for (i=0;i<=14;i++){        printf("xdotp(%d) = %e\n",i+1,xdotp[i]);      }      end debug */} /* End if */else{       mexErrMsgTxt("Input and/or output is wrong size.");} /* End else */} /* end mexFunction *//*########################################*//*########################################*/void nlplant(double *xu, double *xdot){  int fi_flag;  /* #include f16_constants */  double g    = 32.17;          /* gravity, ft/s^2 */  double m    = 636.94;         /* mass, slugs */  double B    = 30.0;             /* span, ft */  double S    = 300.0;            /* planform area, ft^2 */  double cbar = 11.32;          /* mean aero chord, ft */  double xcgr = 0.35;      /* reference center of gravity as a fraction of cbar */  double xcg  = 0.30;      /* center of gravity as a fraction of cbar. */  double Heng = 0.0;              /* turbine momentum along roll axis. */  double pi   = acos(-1);  double r2d;                   /* radians to degrees *//*NasaData        %translated via eq. 2.4-6 on pg 80 of Stevens and Lewis*/  double Jy  = 55814.0;           /* slug-ft^2 */   double Jxz = 982.0;             /* slug-ft^2 */       double Jz  = 63100.0;           /* slug-ft^2 */  double Jx  = 9496.0;            /* slug-ft^2 */  double *temp;  double npos, epos, alt, phi, theta, psi, vt, alpha, beta, P, Q, R;  double sa, ca, sb, cb, tb, st, ct, tt, sphi, cphi, spsi, cpsi;  double T, el, ail, rud, dail, drud, lef, dlef;  double qbar, mach, ps;  double U, V, W, Udot,Vdot,Wdot;  double L_tot, M_tot, N_tot, denom;  double Cx_tot, Cx, delta_Cx_lef, dXdQ, Cxq, delta_Cxq_lef;  double Cz_tot, Cz, delta_Cz_lef, dZdQ, Czq, delta_Czq_lef;  double Cm_tot, Cm, eta_el, delta_Cm_lef, dMdQ, Cmq, delta_Cmq_lef, delta_Cm, delta_Cm_ds;  double Cy_tot, Cy, delta_Cy_lef, dYdail, delta_Cy_r30, dYdR, dYdP;  double delta_Cy_a20, delta_Cy_a20_lef, Cyr, delta_Cyr_lef, Cyp, delta_Cyp_lef;  double Cn_tot, Cn, delta_Cn_lef, dNdail, delta_Cn_r30, dNdR, dNdP, delta_Cnbeta;  double delta_Cn_a20, delta_Cn_a20_lef, Cnr, delta_Cnr_lef, Cnp, delta_Cnp_lef;  double Cl_tot, Cl, delta_Cl_lef, dLdail, delta_Cl_r30, dLdR, dLdP, delta_Clbeta;  double delta_Cl_a20, delta_Cl_a20_lef, Clr, delta_Clr_lef, Clp, delta_Clp_lef;  temp = (double *)malloc(9*sizeof(double));  /*size of 9.1 array*/  r2d  = 180.0/pi;     /* radians to degrees */  /* %%%%%%%%%%%%%%%%%%%           States     %%%%%%%%%%%%%%%%%%% */  npos  = xu[0];   /* north position */  epos  = xu[1];   /* east position */  alt   = xu[2];   /* altitude */  phi   = xu[3];   /* orientation angles in rad. */  theta = xu[4];  psi   = xu[5];  vt    = xu[6];     /* total velocity */  alpha = xu[7]*r2d; /* angle of attack in degrees */  beta  = xu[8]*r2d; /* sideslip angle in degrees */  P     = xu[9];     /* Roll Rate --- rolling  moment is Lbar */  Q     = xu[10];    /* Pitch Rate--- pitching moment is M */  R     = xu[11];    /* Yaw Rate  --- yawing   moment is N */  sa    = sin(xu[7]); /* sin(alpha) */  ca    = cos(xu[7]); /* cos(alpha) */  sb    = sin(xu[8]); /* sin(beta)  */  cb    = cos(xu[8]); /* cos(beta)  */  tb    = tan(xu[8]); /* tan(beta)  */  st    = sin(theta);  ct    = cos(theta);  tt    = tan(theta);  sphi  = sin(phi);  cphi  = cos(phi);  spsi  = sin(psi);  cpsi  = cos(psi);  if (vt <= 0.01) {vt = 0.01;}  /* %%%%%%%%%%%%%%%%%%%     Control inputs     %%%%%%%%%%%%%%%%%%% */  T     = xu[12];   /* thrust */  el    = xu[13];   /* Elevator setting in degrees. */  ail   = xu[14];   /* Ailerons mex setting in degrees. */  rud   = xu[15];   /* Rudder setting in degrees. */  lef   = xu[16];   /* Leading edge flap setting in degrees */    fi_flag = xu[17]/1;       /* fi_flag */      /* dail  = ail/20.0;   aileron normalized against max angle */  /* The aileron was normalized using 20.0 but the NASA report and     S&L both have 21.5 deg. as maximum deflection. */  /* As a result... */  dail  = ail/21.5;  drud  = rud/30.0;  /* rudder normalized against max angle */  dlef  = (1 - lef/25.0);  /* leading edge flap normalized against max angle */  /* %%%%%%%%%%%%%%%%%%     Atmospheric effects     sets dynamic pressure and mach number     %%%%%%%%%%%%%%%%%% */atmos(alt,vt,temp);   mach = temp[0];   qbar = temp[1];   ps   = temp[2];/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Dynamics%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/  /* %%%%%%%%%%%%%%%%%%     Navigation Equations     %%%%%%%%%%%%%%%%%% */   U = vt*ca*cb;  /* directional velocities. */   V = vt*sb;   W = vt*sa*cb;/* nposdot */xdot[0] = U*(ct*cpsi) +             V*(sphi*cpsi*st - cphi*spsi) +             W*(cphi*st*cpsi + sphi*spsi);/* eposdot */  xdot[1] = U*(ct*spsi) +             V*(sphi*spsi*st + cphi*cpsi) +             W*(cphi*st*spsi - sphi*cpsi);/* altdot */xdot[2] = U*st - V*(sphi*ct) - W*(cphi*ct);  /* %%%%%%%%%%%%%%%%%%%     Kinematic equations     %%%%%%%%%%%%%%%%%%% *//* phidot */xdot[3] = P + tt*(Q*sphi + R*cphi);/* theta dot */xdot[4] = Q*cphi - R*sphi;/* psidot */xdot[5] = (Q*sphi + R*cphi)/ct;/* %%%%%%%%%%%%%%%%%%        Table lookup     %%%%%%%%%%%%%%%%%% */if (fi_flag == 1)          /* HIFI Table */{    hifi_C(alpha,beta,el,temp);        Cx = temp[0];        Cz = temp[1];        Cm = temp[2];        Cy = temp[3];        Cn = temp[4];        Cl = temp[5];    hifi_damping(alpha,temp);        Cxq = temp[0];        Cyr = temp[1];        Cyp = temp[2];        Czq = temp[3];        Clr = temp[4];        Clp = temp[5];        Cmq = temp[6];        Cnr = temp[7];        Cnp = temp[8];    hifi_C_lef(alpha,beta,temp);        delta_Cx_lef = temp[0];        delta_Cz_lef = temp[1];        delta_Cm_lef = temp[2];        delta_Cy_lef = temp[3];        delta_Cn_lef = temp[4];        delta_Cl_lef = temp[5];    hifi_damping_lef(alpha,temp);        delta_Cxq_lef = temp[0];        delta_Cyr_lef = temp[1];        delta_Cyp_lef = temp[2];        delta_Czq_lef = temp[3];        delta_Clr_lef = temp[4];        delta_Clp_lef = temp[5];        delta_Cmq_lef = temp[6];        delta_Cnr_lef = temp[7];        delta_Cnp_lef = temp[8];    hifi_rudder(alpha,beta,temp);        delta_Cy_r30 = temp[0];        delta_Cn_r30 = temp[1];        delta_Cl_r30 = temp[2];    hifi_ailerons(alpha,beta,temp);        delta_Cy_a20     = temp[0];        delta_Cy_a20_lef = temp[1];        delta_Cn_a20     = temp[2];        delta_Cn_a20_lef = temp[3];        delta_Cl_a20     = temp[4];        delta_Cl_a20_lef = temp[5];    hifi_other_coeffs(alpha,el,temp);        delta_Cnbeta = temp[0];        delta_Clbeta = temp[1];        delta_Cm     = temp[2];        eta_el       = temp[3];        delta_Cm_ds  = 0;        /* ignore deep-stall effect */    }else if (fi_flag == 0){     /* ##############################################   ##########LOFI Table Look-up #################   ##############################################*//* The lofi model does not include the   leading edge flap.  All terms multiplied   dlef have been set to zero but just to    be sure we will set it to zero. */        dlef = 0.0;         damping(alpha,temp);        Cxq = temp[0];        Cyr = temp[1];        Cyp = temp[2];        Czq = temp[3];        Clr = temp[4];        Clp = temp[5];        Cmq = temp[6];        Cnr = temp[7];        Cnp = temp[8];    dmomdcon(alpha,beta, temp);        delta_Cl_a20 = temp[0];     /* Formerly dLda in nlplant.c */        delta_Cl_r30 = temp[1];     /* Formerly dLdr in nlplant.c */        delta_Cn_a20 = temp[2];     /* Formerly dNda in nlplant.c */        delta_Cn_r30 = temp[3];     /* Formerly dNdr in nlplant.c */    clcn(alpha,beta,temp);        Cl = temp[0];        Cn = temp[1];    cxcm(alpha,el,temp);        Cx = temp[0];        Cm = temp[1];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -