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

📄 f16_dynam_complex.c

📁 基于Matlab2007的美军F16战斗机的非线性模型
💻 C
📖 第 1 页 / 共 3 页
字号:
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/*               6 DOF F-16 FIGHTER AIRCRAFT DYNAMICS                    */
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/*                                                                       */
/* Based on the F-16 model created by R. S. Russel in                    */
/* "Nonlinear F-16 simulation using Simulink and Matlab"                 */   
/* 2003 University of Minnesota and on the F-16 model                    */
/* created by Ying Huo in "Model of F-16 Fighter Aircraft"               */
/*                                                                       */
/* Aerodynamic data and the engine model have been obtained from         */
/* "NASA Technical Paper 1538" by Nguyen et al. 1979                     */   
/*                                                                       */
/* File "F16_dynam_complex.c"                                            */
/* Version 0.9 by E.R. van Oort & L. Sonneveldt                          */
/* Created with MATLAB 7.5 R2007B                                        */
/* May, 2008                                                             */
/*                                                                       */
/* Difference with F16_dynam.c:                                          */
/* - incorporated cg shifts based on AIAA paper 2007-6306                */
/*   by B.J. Bacon and I.M. Gregory of NASA Langley Research Center      */
/*                                                                       */
/* Notes:                                                                */
/* -All units are SI.                                                    */
/* -Euler rotations are used.                                            */
/* -Flag is used to select between hifi and lofi aerodynamic model.      */
/* -Hifi aerodata is obtained from "aerodata/hifi_f16_aerodata.c"        */
/* -Lofi aerodata is obtained from "aerodata/lofi_f16_aerodata.c"        */
/* -"aerodata/mexndinterp.c" is used for interpolation of the data.      */                                                                    
/* -"aerodata/engine_model.c" contains the engine model.                 */  
/* -"aerodata/ISA_atmos.c" contains the ISA atmosphere model.            */
/*                                                                       */
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/*  Used variables:														 */
/*																		 */
/*  Input variables: (port 1)   										 */
/*      dth         throttle setting (between 0 and 1)          [-]      */
/*      de          elevator deflection                         [rad]    */
/*      da          aileron deflection                          [rad]	 */
/*      dr          rudder deflection                           [rad]	 */
/*																		 */
/*  Additonal input variables: (port 2)									 */
/*      dlef        leading edge flap deflection                [rad]    */
/*																		 */
/*  Fidelity flag: (port 3)											     */
/*		fi_flag     hifi/lofi aerodynamic model selection flag  [-]      */
/*																		 */
/*  Center of gravity shift: (port 4)       						     */
/*		delta_x     x direction shift                           [m]      */
/*		delta_y     y direction shift                           [m]      */
/*		delta_z     z direction shift                           [m]      */
/*																		 */
/*  State variables:													 */
/*      Vt          total airspeed                              [m/s]	 */
/*      beta        angle of sideslip                           [rad]	 */
/*      alpha       angle of attack                             [rad]	 */
/*      phi         roll angle                                  [rad]    */
/*      theta       pitch angle                                 [rad]    */
/*      psi         yaw angle                                   [rad]    */
/*      p_body      roll angular rate                           [rad/s]	 */
/*      q_body      pitch angular rate                          [rad/s]	 */
/*      r_body      yaw angular rate                            [rad/s]	 */
/*      x_earth     x position                                  [m]		 */
/*      y_earth     y position                                  [m]		 */
/*      z_earth     z position                                  [m]		 */
/*      power       power level (0-100%)              [-]       [-]      */
/*																		 */
/*  State derivatives:													 */
/*      Vt_dot      rate of change in total airspeed            [m/s^2]	 */
/*      beta_dot    rate of change in angle of sideslip         [rad/s]	 */
/*      alpha_dot   rate of change in angle of attack           [rad/s]	 */
/*      phi_dot     rate of change in roll angle                [rad/s]  */
/*      theta_dot   rate of change in pitch angle               [rad/s]  */
/*      psi_dot     rate of change in yaw angle                 [rad/s]  */
/*      p_body_dot  rate of change in roll angular rate         [rad/s^2]*/
/*      q_body_dot  rate of change in pitch angular rate        [rad/s^2]*/
/*      r_body_dot  rate of change in yaw angular rate          [rad/s^2]*/
/*      x_earth_dot rate of change in x position                [m/s]	 */
/*      y_earth_dot rate of change in y position                [m/s]	 */
/*      z_earth_dot rate of change in z position                [m/s]    */
/*      power_dot   rate of change in power level               [1/s]    */
/*																		 */
/*  Output variables:												     */
/*      Vt          total airspeed                              [m/s]	 */
/*      beta        angle of sideslip                           [rad]	 */
/*      alpha       angle of attack                             [rad]	 */
/*      phi         roll angle                                  [rad]    */
/*      theta       pitch angle                                 [rad]    */
/*      psi         yaw angle                                   [rad]    */
/*      p_body      roll angular rate                           [rad/s]	 */
/*      q_body      pitch angular rate                          [rad/s]	 */
/*      r_body      yaw angular rate                            [rad/s]	 */
/*      x_earth     x position                                  [m]		 */
/*      y_earth     y position                                  [m]		 */
/*      z_earth     z position                                  [m]		 */
/*      power       power level (0-100%)              [-]       [-]      */
/*																		 */
/*  Real work vector: (Persistant memory)                    			 */
/*      C1          coefficients used in moment equations       [-]      */   
/*      C2                                                               */      
/*      C3                                                               */              
/*      C4                                                               */              
/*      C5                                                               */             
/*      C6                                                               */              
/*      C7                                                               */              
/*      C8                                                               */              
/*      C9                                                               */              
/*      Xbar         total force in body fixed x-axis           [N]      */   
/*      Ybar         total force in body fixed y-axis           [N]      */  
/*      Zbar         total force in body fixed z-axis           [N]      */  
/*      Lbar         total moment in body fixed x-axis          [Nm]     */  
/*      Mbar         total moment in body fixed y-axis          [Nm]     */
/*      Nbar         total moment in body fixed z-axis          [Nm]     */
/*      u_body       velocity in body fixed x-axis              [m/s]	 */
/*      v_body       velocity in body fixed y-axis              [m/s]	 */
/*      w_body       velocity in body fixed z-axis              [m/s]	 */
/*      u_body_dot   rate of change in velocity x-axis          [m/s^2]  */
/*      v_body_dot   rate of change in velocity y-axis          [m/s^2]  */
/*      w_body_dot   rate of change in velocity z-axis          [m/s^2]  */
/*      qbar         dynamic pressure                           [N/m]    */
/*      Mach         Mach number                                [-]      */
/*      Thrust       Total engine thrust                        [-]      */
/*                                                                       */
/*-----------------------------------------------------------------------*/
#define S_FUNCTION_NAME  F16_dynam_complex
#define S_FUNCTION_LEVEL 2
 
/* include files */
#include <math.h>
#include "simstruc.h"

#include "aerodata/mexndinterp.c"
#include "aerodata/hifi_f16_aerodata.c"     /* hifi lookup tables */
#include "aerodata/lofi_f16_aerodata.c"     /* lofi lookup tables */
#include "aerodata/matrix_functions.c"

#include "aerodata/ISA_atmos.c"             /* ISA atmosphere model */
#include "aerodata/engine_model.c"          /*engine model */

/* input port 1: control inputs */
#define dth             (*u[0])
#define de              (*u[1])
#define da              (*u[2])
#define dr              (*u[3])
/* input port 2: leading edge flap deflection */
#define dlef            (*u2[0])
/* input port 3: fidelity flag, 0 = lofi model, 1 = hifi model */
#define fi_flag         (*u3[0])

/* input port 4: gravity center shifts */
#define delta_x         (*u4[0])
#define delta_y         (*u4[1])
#define delta_z         (*u4[2])

/* 13 States */
#define Vt          x[0]
#define beta        x[1]
#define alpha       x[2]

#define phi          x[3]
#define theta        x[4]
#define psi          x[5]

#define p_body      x[6]
#define q_body      x[7]
#define r_body      x[8]

#define x_earth     x[9]
#define y_earth     x[10]
#define z_earth     x[11]

#define power         x[12]

/* State derivatives */
#define Vt_dot          dx[0]
#define beta_dot        dx[1]
#define alpha_dot       dx[2]

#define phi_dot         dx[3]
#define theta_dot       dx[4]
#define psi_dot         dx[5]

#define p_body_dot      dx[6]
#define q_body_dot      dx[7]
#define r_body_dot      dx[8]

#define x_earth_dot     dx[9]
#define y_earth_dot     dx[10]
#define z_earth_dot     dx[11]
#define power_dot         dx[12]

/* Work Variables */
#define C1              ssGetRWork(S)[0]
#define C2              ssGetRWork(S)[1]
#define C3              ssGetRWork(S)[2]
#define C4              ssGetRWork(S)[3]
#define C5              ssGetRWork(S)[4]
#define C6              ssGetRWork(S)[5]
#define C7              ssGetRWork(S)[6]
#define C8              ssGetRWork(S)[7]
#define C9              ssGetRWork(S)[8]
#define Xbar            ssGetRWork(S)[9]
#define Ybar            ssGetRWork(S)[10]
#define Zbar            ssGetRWork(S)[11]
#define Lbar            ssGetRWork(S)[12]
#define Mbar            ssGetRWork(S)[13]
#define Nbar            ssGetRWork(S)[14]
#define u_body          ssGetRWork(S)[15]
#define v_body          ssGetRWork(S)[16]
#define w_body          ssGetRWork(S)[17]
#define u_body_dot      ssGetRWork(S)[18]
#define v_body_dot      ssGetRWork(S)[19]
#define w_body_dot      ssGetRWork(S)[20]
#define qbar            ssGetRWork(S)[21]
#define Mach            ssGetRWork(S)[22]
#define Thrust          ssGetRWork(S)[23]

/* Aircraft Parameters */
#define mass        9295.44 /* assumed fixed */
#define Ixx         12874.8
#define Iyy         75673.6
#define Izz         85552.1
#define Ixz         1331.4
#define Ixy         0.0
#define Iyz         0.0
#define Sref        27.87
#define bref        9.144
#define cref        3.45
#define xcg         0.3
#define xcgr        0.35
#define heng        216.9 /* engine angular momentum, assumed fixed */

/* Additional parameters */
#define rtd           57.29577951
#define dtr           0.017453293
#define Pi			  3.141592654

/*=============================*/
/* Function: mdlInitalizeSizes */
/*=============================*/
static void mdlInitializeSizes(SimStruct *S)
{
    ssSetNumSFcnParams(S, 1);  /* Number of expected parameters */

    ssSetNumContStates(S, 13);
    ssSetNumDiscStates(S, 0);

    ssSetNumInputPorts(S, 4);
    ssSetInputPortWidth(S, 0, 4);
    ssSetInputPortWidth(S, 1, 1);
    ssSetInputPortWidth(S, 2, 1);
    ssSetInputPortWidth(S, 3, 3);

    /* ssSetInputPortDirectFeedThrough(S, 1, 1); */

    ssSetNumOutputPorts(S, 1);
    ssSetOutputPortWidth(S, 0, 13);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 23);
    ssSetNumIWork(S, 0);

⌨️ 快捷键说明

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