?? f16_dynam.c
字號:
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/* 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.c" */
/* Version 1.0 by E.R. van Oort & L. Sonneveldt */
/* Created with MATLAB 7.0 R14 */
/* May, 2006 */
/* */
/* 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 [-] */
/* */
/* 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] */
/* pow 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] */
/* pow_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] */
/* pow 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
#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/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])
/* 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 pow 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 pow_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 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, 3);
ssSetInputPortWidth(S, 0, 4);
ssSetInputPortWidth(S, 1, 1);
ssSetInputPortWidth(S, 2, 1);
/* ssSetInputPortDirectFeedThrough(S, 1, 1); */
ssSetNumOutputPorts(S, 1);
ssSetOutputPortWidth(S, 0, 13);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 23);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, 0);
}
/*===================================*/
/* Function: mdlInitalizeSampleTimes */
/*===================================*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
/*==================================*/
/* Function: mdlInitalizeConditions */
/*==================================*/
#define MDL_INITIALIZE_CONDITIONS
#if defined(MDL_INITIALIZE_CONDITIONS)
static void mdlInitializeConditions(SimStruct *S)
{
}
#endif
/*====================*/
/* Function: mdlStart */
/*====================*/
#define MDL_START
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
real_T *x = ssGetContStates(S);
int i;
/* Initialize the state vector */
for (i = 0; i < ssGetNumContStates(S); i++)
{
x[i] = mxGetPr(ssGetSFcnParam(S, 0))[i];
}
}
#endif
/*======================*/
/* Function: mdlOutputs */
/*======================*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *x = ssGetContStates(S);
real_T *y = ssGetOutputPortRealSignal(S, 0);
int i;
for (i = 0; i < ssGetNumContStates(S); i++)
{
y[i] = x[i]; /* outputs are the states */
}
}
/*=====================*/
/* Function: mdlUpdate */
/*=====================*/
#undef MDL_UPDATE
#if defined(MDL_UPDATE)
static void mdlUpdate(SimStruct *S, int_T tid)
{
}
#endif
/*==========================*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -