1 // -*- mode: c; mode: fold -*- 2 /* 3 * CRRCsim - the Charles River Radio Control Club Flight Simulator Project 4 * Copyright (C) 2005 - 2009 - Jens Wilhelm Wulf (original author) 5 * Copyright (C) 2006, 2008 - Jan Reucker 6 * Copyright (C) 2006 - Todd Templeton 7 * 8 * This file is partially based on work by 9 * Jan Kansky 10 * Bruce Jackson 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License version 2 14 * as published by the Free Software Foundation. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, 24 * Boston, MA 02111-1307, USA. 25 * 26 */ 27 // 28 #ifndef FDM_LARCSIM_H 29 # define FDM_LARCSIM_H 30 31 # include <stdexcept> 32 # include <vector> 33 # include "../ls_types.h" 34 # include "../eom01/eom01.h" 35 # include "../../mod_math/vector3.h" 36 # include "../../mod_math/matrix33.h" 37 # include "../power/power.h" 38 # include "../gear01/gear.h" 39 40 /** 41 * physical model for a fixed wing airplane 42 * 43 * Jens Wilhelm Wulf, September 2005: attempt to (re)structure and simplify LaRCSim code. 44 * 45 * References originally given by Bruce Jackson: 46 * 47 * [ 1] McFarland, Richard E.: "A Standard Kinematic Model 48 * for Flight Simulation at NASA-Ames", NASA CR-2497, 49 * January 1975 50 * [ 2] ANSI/AIAA R-004-1992 "Recommended Practice: Atmos- 51 * pheric and Space Flight Vehicle Coordinate Systems", 52 * February 1992 53 * [ 3] Beyer, William H., editor: "CRC Standard Mathematical 54 * Tables, 28th edition", CRC Press, Boca Raton, FL, 1987, 55 * ISBN 0-8493-0628-0 56 * [ 4] Dowdy, M. C.; Jackson, E. B.; and Nichols, J. H.: 57 * "Controls Analysis and Simulation Test Loop Environ- 58 * ment (CASTLE) Programmer's Guide, Version 1.3", 59 * NATC TM 89-11, 30 March 1989. 60 * [ 5] Halliday, David; and Resnick, Robert: "Fundamentals 61 * of Physics, Revised Printing", Wiley and Sons, 1974. 62 * ISBN 0-471-34431-1 63 * [ 6] Anon: "U. S. Standard Atmosphere, 1962" 64 * [ 7] Anon: "Aeronautical Vest Pocket Handbook, 17th edition", 65 * Pratt & Whitney Aircraft Group, Dec. 1977 66 * [ 8] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft 67 * Control and Simulation", Wiley and Sons, 1992. 68 * ISBN 0-471-61397-5 69 * 70 * @author Bruce Jackson 71 * @author Jens Wilhelm Wulf 72 */ 73 class CRRC_AirplaneSim_Larcsim : public EOM01 74 { 75 friend class ModFDMInterface; 76 friend class CRRC_AirplaneSim_DisplayMode; 77 78 public: 79 isStalling()80 virtual bool isStalling() { return(stalling != 0); }; 81 82 /** 83 * Returns total CL. 84 */ getFlightCL()85 virtual double getFlightCL() { return(flight_CL); }; 86 87 /** 88 * Used for sound calculation. It returns the prop's number of revolutions 89 * per second [1/s]. 90 */ 91 virtual double getPropFreq(); 92 93 /** 94 * Returns relative battery capacity/fuel left (0..1). 95 */ getBatCapLeft()96 virtual double getBatCapLeft() { return(power->getBatteryMin()); }; 97 98 /** 99 * computed velocity for trimmed flight in dead air [ft/s] 100 */ getTrimmedFlightVelocity()101 virtual double getTrimmedFlightVelocity() {return(trimmedFlightVelocity); }; 102 103 /** 104 * Wingspan of the aircraft in feet 105 */ getWingspan()106 virtual double getWingspan() { return(B_ref); }; 107 108 /** 109 * returns Z coordinate of lowest point 110 */ getZLow()111 double getZLow() { return(wheels.getZLow()); }; 112 113 /** 114 * This only tries to reload airplane parameters, but does not change states. 115 */ 116 virtual int ReloadParams(SimpleXMLTransfer* xml, 117 SimpleXMLTransfer* cfg); 118 private: 119 120 void LoadFromXML(SimpleXMLTransfer* xml, int nVerbosity); 121 122 void update(TSimInputs* inputs, 123 double dt, 124 int multiloop); 125 126 virtual void initAirplaneState(double dRelVel, 127 double dPhi, 128 double dTheta, 129 double dPsi, 130 double X, 131 double Y, 132 double Z, 133 double R_X, 134 double R_Y, 135 double R_Z); 136 137 /** 138 * read from file 139 */ 140 CRRC_AirplaneSim_Larcsim(const char* filename, FDMEnviroment* myEnv, SimpleXMLTransfer* cfg); 141 142 /** 143 * read from xml description 144 */ 145 CRRC_AirplaneSim_Larcsim(SimpleXMLTransfer* xml, FDMEnviroment* myEnv, SimpleXMLTransfer* cfg); 146 147 virtual ~CRRC_AirplaneSim_Larcsim(); 148 149 private: 150 151 /// @name Aerodynamic data 152 //@{ 153 SCALAR C_ref; // reference chord (ft) 154 SCALAR B_ref; // reference span (ft) 155 SCALAR S_ref; // reference area (ft^2) 156 SCALAR U_ref; // reference speed for Re-scaling of CD_prof (ft/s) 157 158 SCALAR Alpha_0; // baseline alpha (rad) 159 160 SCALAR Cm_0 ; // baseline Cm at Alpha_0 161 SCALAR CL_0 ; // baseline CL at Alpha_0 162 SCALAR CL_max ; // positive stall limit 163 SCALAR CL_min ; // negative stall limit 164 SCALAR CD_prof; // profile CD at U_ref 165 166 SCALAR Uexp_CD; // for Re-scaling of CD_prof ~ (U/U_ref)^Uexp_CD 167 168 SCALAR CL_a; // lift-force / alpha ~ 2 pi / (1 + 2/AR) 169 SCALAR Cm_a; // pitch-moment / alpha (pitch stability) 170 SCALAR CY_b; // side-force / sideslip 171 SCALAR Cl_b; // roll-moment / sideslip (crucial for rudder-only turns) 172 SCALAR Cn_b; // yaw-moment / sideslip (yaw stability) 173 174 SCALAR CL_q; // lift-force / pitch-rate 175 SCALAR Cm_q; // pitch-moment / pitch-rate (pitch damping) 176 SCALAR CY_p; // side-force / roll-rate 177 SCALAR Cl_p; // roll-moment / roll-rate (roll damping) 178 SCALAR Cn_p; // yaw-moment / roll-rate (yaw-roll coupling) 179 SCALAR CY_r; // side-force / yaw-rate 180 SCALAR Cl_r; // roll-moment / yaw-rate 181 SCALAR Cn_r; // yaw-moment / yaw-rate (yaw damping) 182 183 SCALAR CL_de; // lift-force / elevator 184 SCALAR Cm_de; // pitch-moment / elevator 185 SCALAR CY_dr; // side-force / rudder 186 SCALAR Cl_dr; // roll-moment / rudder 187 SCALAR Cn_dr; // yaw-moment / rudder 188 SCALAR CY_da; // side-force / aileron 189 SCALAR Cl_da; // roll-moment / aileron 190 SCALAR Cn_da; // yaw-moment / aileron 191 192 SCALAR eta_loc; 193 SCALAR CG_arm; 194 SCALAR CL_drop; 195 SCALAR CD_stall; 196 197 SCALAR span_eff; // span efficiency: Effective span 0.95 for most planes, 0.85 flying wing 198 SCALAR CL_CD0; // CL at minimum profile CD: 0.30 for 7037, 0.15 MH32, 0.0 RG15, AGxx, power 199 SCALAR CD_CLsq; // d(CD)/d(CL^2), curvature of parabolic profile polar: 0.01 composites, 0.015 saggy ships, 0.02 beat up ship 200 SCALAR CD_AIsq; // d(CD)/d(aileron^2) , curvature of ail. CD influence: 0.01/(max_aileron)^2 201 SCALAR CD_ELsq; // d(CD)/d(elevator^2), curvature of ele. CD influence: 0.01/(max_elevator)^2 for Zagi otherwise 0 202 203 SCALAR flap_drag; 204 SCALAR flap_lift; 205 SCALAR flap_moment; 206 SCALAR flap_eff_ratio; // flap effectiveness at full deflection reduces by this ratio to account for non linearity at large 207 // deflection angles. Suggested value: 1.0 for travel < 10�, down to 0.5-0.0 for 30�-60� travel 208 SCALAR spoiler_drag; 209 SCALAR spoiler_lift; 210 SCALAR spoiler_moment; 211 SCALAR retract_drag; 212 SCALAR retract_lift; 213 //@} 214 215 /// @name Gear and ground interaction 216 //@{ 217 218 /** 219 * Vector containing all hard points/wheels 220 */ 221 WheelSystem wheels; 222 223 //@} 224 225 /// @name Propeller and wing/fuselage/tail interaction 226 //@{ 227 228 /** 229 * Only this fraction of shaft torque is applied to the airframe 230 */ 231 double effectivePropellerTorqueFactor; 232 //@} 233 234 private: 235 236 void gear(TSimInputs* inputs, CRRCMath::Vector3& v_F, CRRCMath::Vector3& v_M); 237 void aero(TSimInputs* inputs, 238 CRRCMath::Matrix33 m_V_atmo_rwy, 239 CRRCMath::Vector3 v_R_omega_gust_body, 240 CRRCMath::Vector3& v_F, CRRCMath::Vector3& v_M); 241 void engine( SCALAR dt, TSimInputs* inputs, CRRCMath::Vector3& v_F, CRRCMath::Vector3& v_M); 242 virtual void ls_step_init(); 243 244 private: 245 246 /// @name written by constructor 247 //@{ 248 249 /** 250 * Propulsion system: batteries, shafts, engines, propellers. 251 */ 252 Power::Power* power; 253 254 /** 255 * Velocity in trimmed flight; dead air [ft/s]. 256 */ 257 float trimmedFlightVelocity; 258 259 //@} 260 261 /// @name written by aero 262 //@{ 263 int stalling; 264 265 double flight_CL; 266 //@} 267 268 }; 269 270 #endif 271