<?xml version="1.0"?>

<!-- Piper PA28 Aerodynamics -->
<!-- Copyright (c) 2022 Josh Davidson (Octal450) -->
<!-- Reworked 2020 by Benedikt Wolf (D-ECHO) with help by Jonathan Redpath (legoboyvdlp) and Niels Krenz (Knüppelrührer)-->
<!-- revision 1.2 incorporating OpenVSP results by Knüppelrührer -->
<!-- References:
	1) 	IRA H. ABBOTT, ALBERT E. VON DOENHOFF, and LOUIS S. STIVERS, Jr.: SUMMARY OF AIRFOIL DATA
			https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19930090976.pdf
			especially page 219 (217 printed) about NACA 652-415 Cl and Cd
	2)	E.G.TULAPURKARA, S.ANANTH, TEJAS M. KULKARNI: PERFORMANCE ANALYSIS OF A PISTON ENGINED AIRPLANE - PIPER CHEROKEE PA-28-180
			http://www.engbrasil.eng.br/artigos/art105.pdf
	3)	W. F. Phillips and D. F. Hunsaker: Lifting-Line Predictions for Induced Drag and Lift in Ground Effect
			https://digitalcommons.usu.edu/cgi/viewcontent.cgi?article=1086&context=mae_facpub
-->

<aerodynamics>
	<property value="0.1">tune</property>
	<function name="aero/function/kCDge">
		<description>Change in drag due to ground effect</description>
		<table>
			<independentVar lookup="row">aero/h_b-mac-ft</independentVar>
			<tableData>
				<!-- Ref 3 (Figure 3) -->
				0.00  0.320
				0.10  0.520
				0.20  0.695
				0.50  0.900
				1.00  0.990
				2.00  1.000
			  </tableData>
		</table>
	</function>
	
	<function name="aero/function/kCLge">
		<description>Change in drag due to ground effect</description>
		<table>
			<independentVar lookup="row">aero/h_b-mac-ft</independentVar>
			<tableData>
				<!-- Ref 3 (Figure 5) (Aspect ratio 5.63) -->
				0.00  1.220
				0.10  1.160
				0.20  1.080
				0.50  1.025
				1.00  1.012
				2.00  1.000
			  </tableData>
		</table>
	</function>
	
	<function name="aero/function/qbar-propwash-psf">
		<description>Q bar due to the propeller induced velocity</description>
		<product>
			<property>propulsion/engine[0]/prop-induced-velocity_fps</property>
			<property>propulsion/engine[0]/prop-induced-velocity_fps</property>
			<property>atmosphere/rho-slugs_ft3</property>
			<value>0.5</value>
		</product>
	</function>
	
	<function name="aero/alpha-wing-deg">
		<todegrees>
			<property>aero/alpha-wing-rad</property>
		</todegrees>
	</function>
	
	<axis name="LIFT">
		
		<function name="aero/coefficient/CLpiv">
			<description>Lift due to propeller induced velocity</description>
			<product>
				<property>propulsion/engine[0]/thrust-coefficient</property>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<table>
					<independentVar lookup="row">aero/alpha-rad</independentVar>
					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
					<tableData>
						       0      60
						-0.24  0.000  0.000
						 0.00  0.064  0.170
						 0.27  0.291  0.775
						 0.53  0.000  0.000
					</tableData>
				</table>
			</product>
		</function>
		
		<!--According to Ref 2, page 22 (21 printed), Clmax is 1.33 at flaps 0, 1.42 at flaps 10, 1.70 at flaps 25 and 1.86 at flaps 40 -->
		<function name="aero/coefficient/CLalpha">
			<description>Lift due to alpha</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>aero/function/kCLge</property>
				<value>0.8581</value> <!-- Factor to reach CLalpha, max = 1.33 -->
				<table>
					<independentVar>aero/alpha-deg</independentVar>
					<tableData>
						-90  0.00
						<!-- Begin diagram data, from ref. 1 -->
						-18 -0.55
						-16 -0.45
						-14 -0.70
						-13 -1.05
						-12 -1.00
						-10 -0.80
						 -8 -0.58
						 -6 -0.39
						 -4 -0.13
						 -2  0.10
						  0  0.30
						  2  0.54
						  4  0.74
						  6  0.90
						  8  1.13
						 10  1.30
						 12  1.42
						 14  1.52
						 16  1.55
						 18  1.53
						 20  1.45
						 22  1.13
						 24  1.03
						 <!-- End of diagram data -->
						 90  0.00
					</tableData>
				</table>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/CLq">
			<description>Lift due to pitch rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>velocities/q-aero-rad_sec</property>
				<property>aero/ci2vel</property>
				<value>3.2670</value>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/CLadot">
			<description>Lift due to alpha rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>aero/alphadot-rad_sec</property>
				<property>aero/ci2vel</property>
				<value>1.1348</value>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<!-- Offset to reach Clmax as described above -->
		<function name="aero/coefficient/CLflap">
			<description>Lift due to flaps</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<table>
					<independentVar>fcs/flap-pos-deg</independentVar>
					<tableData>
						0	0.00
						10	0.09
						25	0.31
						40	0.44
					</tableData>
				</table>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/CLde">
			<description>Lift due to Elevator Deflection</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<toradians><property>fcs/elevator-deg</property></toradians>
				<value>0.3201</value>
				<property>crash-stress/htail-factor</property>
			</product>
		</function>
	
	</axis>
	
	<axis name="DRAG">
		
		<!-- See Ref 2 -->
		<function name="aero/coefficient/CD0">
			<description>Minimum drag</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<table>
					<independentVar>aero/alpha-deg</independentVar>
					<tableData> <!-- From OpenVSP -->
						-18  1.5000
						 -8  0.0253
						 -4  0.0242
						  0  0.0244
						  4  0.0260
						  8  0.0283
						 12  0.0322
						 18  1.5000
					</tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/CDalpha">
			<description>Drag due to alpha</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<value>0.5387825</value> <!-- Tuning factor -->
				<table>
					<independentVar lookup="row">aero/alpha-rad</independentVar>
					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
					<tableData>
						     0       65
						-90  2.0000  2.0000
						<!-- Begin diagram data, from ref. 1-->
						-18  0.0082  0.0210
						-16  0.0077  0.0158
						-14  0.0095  0.0300 <!-- Guess for flaps extended -->
						-13  0.0130  0.0500 <!-- Guess for both -->
						-12  0.0122  0.0450 <!-- Guess for both -->
						-10  0.0105  0.0350 <!-- Guess for flaps extended -->
						 -8  0.0085  0.0280 <!-- Guess for flaps extended -->
						 -6  0.0073  0.0144
						 -4  0.0064  0.0110
						 -2  0.0048  0.0102
						  0  0.0041  0.0101
						  2  0.0042  0.0112
						  4  0.0060  0.0132
						  6  0.0090  0.0160
						  8  0.0111  0.0240 <!-- Guess for flaps extended -->
						 10  0.0140  0.0350 <!-- Guess for flaps extended -->
						 12  0.0160  0.0450 <!-- Guess for flaps extended -->
						 <!-- From here guesses -->
						 14  0.0200  0.0480
						 16  0.0300  0.0550
						 18  0.0450  0.0600
						 20  0.0300  0.0500
						 22  0.0145  0.0270
						 24  0.0128  0.0210
						 <!-- End of diagram data -->
						 90  2.0000  2.0000
					  </tableData>
				</table>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/CDi">
			<description>Induced drag</description><!-- Induced drag coefficient K according to ref 2 -->
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>aero/function/kCDge</property>
				<property>aero/cl-squared</property>
				<table>
					<independentVar>fcs/flap-pos-deg</independentVar>
					<tableData>
						 0  0.0696
						10  0.0742
						25  0.0768
						40  0.0796
					</tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/CDbeta">
			<description>Drag due to sideslip</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>aero/mag-beta-rad</property>
				<value>0.2013</value>
			</product>
		</function>
		
		<function name="aero/coefficient/CDde">
			<description>Drag due to elevator deflection</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<abs><toradians><property>fcs/elevator-deg</property></toradians></abs>
				<value>0.004292</value>
				<property>crash-stress/htail-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/CDdoor">
			<description>Drag due to main door</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<table>
					<independentVar lookup="row">extra/door-main-norm</independentVar>
					<tableData> <!-- To cancel out the slight offset from 0 due to the lag_filter -->
						0.00  0.0000
						0.01  0.0000
						1.00  0.0018
					</tableData>
				</table>
			</product>
		</function>
	
	</axis>
	
	<axis name="SIDE">
		
		<function name="aero/coefficient/CYbeta">
			<description>Side force due to beta</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<table>
					<independentVar lookup="row">aero/beta-rad</independentVar>
					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
					<tableData>
								0      40
						-0.349  0.129  0.100
						 0.000  0.000  0.000
						 0.349 -0.129 -0.100
					  </tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/CYp">
			<description>Side force due to roll rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>aero/bi2vel</property>
				<property>velocities/p-aero-rad_sec</property>
				<table>
					<independentVar lookup="row">aero/Re</independentVar>
					<tableData>
						3221764  0.2600
						3543940  0.0229
						4832646  0.0101
						6440811  0.0057
					</tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/CYr">
			<description>Side force due to yaw rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>aero/bi2vel</property>
				<property>velocities/r-aero-rad_sec</property>
				<value>0.0781</value>
			</product>
		</function>
		
		<function name="aero/coefficient/CYdr">
			<description>Side force due to rudder</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<toradians><property>fcs/rudder-deg</property></toradians>
				<value>-0.0245</value>
				<property>crash-stress/vtail-factor</property>
			</product>
		</function>
	
	</axis>
	
	<axis name="ROLL">
		
		<function name="aero/coefficient/Clbeta">
			<description>Roll moment due to beta</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<property>aero/beta-rad</property>
				<value>-0.0605</value>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Clp">
			<description>Roll moment due to roll rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<property>aero/bi2vel</property>
				<property>velocities/p-aero-rad_sec</property>
				<value>-0.411</value>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Clr">
			<description>Roll moment due to yaw rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<property>aero/bi2vel</property>
				<property>velocities/r-aero-rad_sec</property>
				<table>
					<independentVar lookup="row">fcs/flap-pos-deg</independentVar>
					<tableData>
						 0  0.00206
						40  0.00412
					</tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/Clwi">
			<description>Roll moment due to wing imbalance</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<value>-0.36877</value>
				<property>crash-stress/wing-diff-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Clda_l">
			<description>Roll moment due to left aileron</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<toradians><property>fcs/aileron-left-deg</property></toradians>
				<value>0.06943</value>
				<table>
					<independentVar lookup="row">aero/alpha-deg</independentVar>
					<independentVar lookup="column">aero/stall-hyst-norm</independentVar>
					<tableData>
						    0     1
						10  1.00  0.30
						13  0.30  0.30
						20 -0.15 -0.15
					</tableData>
				</table>
				<property>crash-stress/left-wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Clda_r">
			<description>Roll moment due to right aileron</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<toradians><property>fcs/aileron-right-deg</property></toradians>
				<value>-0.06943</value>
				<table>
					<independentVar lookup="row">aero/alpha-deg</independentVar>
					<independentVar lookup="column">aero/stall-hyst-norm</independentVar>
					<tableData>
						    0     1
						10  1.00  0.30
						13  0.30  0.30
						20 -0.15 -0.15
					</tableData>
				</table>
				<property>crash-stress/right-wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cldr">
			<description>Roll moment due to rudder</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<toradians><property>fcs/rudder-deg</property></toradians>
				<value>0.04757</value>
				<property>crash-stress/vtail-factor</property>
			</product>
		</function>
	
	</axis>
	
	<axis name="PITCH">
		
		<function name="aero/coefficient/Cm0">
			<description>Pitch moment at zero alpha</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/cbarw-ft</property>
				<value>0.025</value>
			</product>
		</function>
		
		<function name="aero/coefficient/Cmalpha">
			<description>Pitch moment due to alpha</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/cbarw-ft</property>
				<property>aero/alpha-rad</property>
				<value>-0.586376</value>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cmq">
			<description>Pitch moment due to pitch rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/cbarw-ft</property>
				<property>aero/ci2vel</property>
				<property>velocities/q-aero-rad_sec</property>
				<value>-12.63</value>
				<property>crash-stress/htail-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cmadot">
			<description>Pitch moment due to alpha rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/cbarw-ft</property>
				<property>aero/ci2vel</property>
				<property>aero/alphadot-rad_sec</property>
				<value>-5.77032</value>
				<property>crash-stress/wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cmde">
			<description>Pitch moment due to elevator</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/cbarw-ft</property>
				<toradians><property>fcs/elevator-deg</property></toradians>
				<value>-0.92485</value>
				<table>
					<independentVar lookup="row">aero/alpha-deg</independentVar>
					<independentVar lookup="column">fcs/elevator-deg</independentVar>
					<tableData>
						   -12   12
						 2  1.0  1.0
						10  0.3  0.7
						18  0.2  0.5
						22  0.1  0.3
					</tableData>
				</table>
				<property>crash-stress/htail-factor</property>
			</product>
		</function>
	
	</axis>
	
	<axis name="YAW">
		
		<function name="aero/coefficient/Cnbeta">
			<description>Yaw moment due to beta</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<table>
					<independentVar lookup="row">aero/beta-rad</independentVar>
					<tableData>
						-0.349 -0.014
						 0.000  0.000
						 0.349  0.014
					</tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/Cnr">
			<description>Yaw moment due to yaw rate</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<property>aero/bi2vel</property>
				<property>velocities/r-aero-rad_sec</property>
				<value>-0.154</value>
				<property>crash-stress/vtail-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cnspw">
			<description>Yaw moment due to spiraling propwash</description>
			<product>
				<property>aero/function/qbar-propwash-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<value>-0.04034</value>
			</product>
		</function>
		
		<function name="aero/coefficient/Cnrf">
			<description>Yaw moment due to flat spin</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<property>aero/bi2vel</property>
				<table>
					<independentVar lookup="row">velocities/r-aero-rad_sec</independentVar>
					<independentVar lookup="column">aero/alpha-rad</independentVar>
					<tableData>
						    0.29  0.41
						-5  0.00  0.00
						-3  0.00 -0.21
						-1  0.00  0.00
						 0  0.00  0.00
						 1  0.00  0.00
						 3  0.00  0.21
						 5  0.00  0.00
					</tableData>
				</table>
			</product>
		</function>
		
		<function name="aero/coefficient/Cndr">
			<description>Yaw moment due to rudder</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<toradians><property>fcs/rudder-deg</property></toradians>
				<value>0.02503</value>
				<property>crash-stress/vtail-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cnda_l">
			<description>Yaw moment due to left aileron (adverse)</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<toradians><property>fcs/aileron-left-deg</property></toradians>
				<value>-0.003156</value>
				<table>
					<independentVar lookup="row">aero/alpha-deg</independentVar>
					<independentVar lookup="column">aero/beta-deg</independentVar>
					<tableData>
						  -20     0      20
						0  0.667  1.000  0.667
						8  1.334  1.667  1.334
					</tableData>
				</table>
				<property>crash-stress/left-wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cnda_r">
			<description>Yaw moment due to right aileron (adverse)</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<toradians><property>fcs/aileron-right-deg</property></toradians>
				<value>0.003156</value>
				<table>
					<independentVar lookup="row">aero/alpha-deg</independentVar>
					<independentVar lookup="column">aero/beta-deg</independentVar>
					<tableData>
						  -20     0      20
						0  0.667  1.000  0.667
						8  1.334  1.667  1.334
					</tableData>
				</table>
				<property>crash-stress/right-wing-factor</property>
			</product>
		</function>
		
		<function name="aero/coefficient/Cndoor">
			<description>Yaw moment due to main door</description>
			<product>
				<property>aero/qbar-psf</property>
				<property>metrics/Sw-sqft</property>
				<property>metrics/bw-ft</property>
				<table>
					<independentVar lookup="row">extra/door-main-norm</independentVar>
					<tableData> <!-- To cancel out the slight offset from 0 due to the lag_filter -->
						0.00  0.00
						0.04  0.00
						1.00  0.04
					</tableData>
				</table>
			</product>
		</function>
	
	</axis>

</aerodynamics>
