From d3a7e4604d6a8e9e445dc268f9917eaad2602e7f Mon Sep 17 00:00:00 2001
From: Josh Davidson <joshdavidson2000@outlook.com>
Date: Sun, 8 May 2022 16:16:11 -0400
Subject: [PATCH] Aero: Update CLflap, FMGC: rework alpha prot/max speeds

---
 Systems/a320-aerodynamics.xml           |  8 +--
 Systems/a320-cfm56-5b4-engine-fadec.xml |  6 +-
 Systems/a320-fbw.xml                    | 34 ++++++++++-
 Systems/a320-fmgc.xml                   | 79 +++++++++++++++++--------
 Systems/a320-v2527-a5-engine-fadec.xml  |  6 +-
 5 files changed, 98 insertions(+), 35 deletions(-)

diff --git a/Systems/a320-aerodynamics.xml b/Systems/a320-aerodynamics.xml
index 52d51104..7e6d0a0f 100644
--- a/Systems/a320-aerodynamics.xml
+++ b/Systems/a320-aerodynamics.xml
@@ -118,10 +118,10 @@
 					<independentVar lookup="row">fcs/flap-pos-deg</independentVar>
 					<tableData>
 						 0  0.0000
-						10  0.1334
-						15  0.2314
-						20  0.3044
-						40  0.3766
+						10  0.1387
+						15  0.2377
+						20  0.3127
+						40  0.3894
 					</tableData>
 				</table>
 			</product>
diff --git a/Systems/a320-cfm56-5b4-engine-fadec.xml b/Systems/a320-cfm56-5b4-engine-fadec.xml
index dad7a6c1..b69189a4 100644
--- a/Systems/a320-cfm56-5b4-engine-fadec.xml
+++ b/Systems/a320-cfm56-5b4-engine-fadec.xml
@@ -11,6 +11,7 @@
 	<property value="18.9">fadec/limit/min-n1</property>
 	<property value="104">fadec/limit/max-n1</property>
 	<property value="0">fadec/athr/cmd</property>
+	<property value="0">fadec/inhibit-alpha-floor</property>
 	<property value="1">fadec/limit/active-epr</property> <!-- Unused in this engine -->
 	<property value="0">fadec/control-1/n1-mode</property> <!-- Unused in this engine -->
 	<property value="0">fadec/control-2/n1-mode</property> <!-- Unused in this engine -->
@@ -1009,7 +1010,7 @@
 		
 		<!-- Alpha Floor and Toga Lk -->
 		<switch name="fadec/alpha-floor-engage">
-			<default value="14.5"/>
+			<default value="13"/>
 			<test logic="OR" value="15">
 				/controls/flight/flaps-pos eq 1
 				/controls/flight/flaps-pos eq 2
@@ -1024,7 +1025,7 @@
 		</switch>
 		
 		<switch name="fadec/alpha-floor-disengage">
-			<default value="8"/>
+			<default value="11"/>
 			<test logic="OR" value="13">
 				/controls/flight/flaps-pos eq 1
 				/controls/flight/flaps-pos eq 2
@@ -1043,6 +1044,7 @@
 			<test logic="OR" value="0"> <!-- Reset -->
 				position/wow eq 1
 				/it-fbw/law ne 0
+				fadec/inhibit-alpha-floor eq 1
 				/FMGC/FCU-working eq 0
 				position/gear-agl-ft lt 100
 			</test>
diff --git a/Systems/a320-fbw.xml b/Systems/a320-fbw.xml
index a01f016a..2bd5f318 100644
--- a/Systems/a320-fbw.xml
+++ b/Systems/a320-fbw.xml
@@ -70,7 +70,7 @@
 			</test>
 		</switch>
 		
-		<fcs_function name="fbw/stall-alpha-deg">
+		<fcs_function name="fbw/alpha-stall-deg">
 			<function>
 				<table>
 					<independentVar lookup="row">atmosphere/density-altitude</independentVar>
@@ -82,13 +82,41 @@
 			</function>
 		</fcs_function>
 		
+		<fcs_function name="fbw/alpha-prot-deg">
+			<function>
+				<table>
+					<independentVar lookup="row">atmosphere/density-altitude</independentVar>
+					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
+					<tableData>
+						       0    15
+						    0  9.5  10.5
+						43000  6.5   6.8
+					</tableData>
+				</table>
+			</function>
+		</fcs_function>
+		
+		<fcs_function name="fbw/alpha-max-deg">
+			<function>
+				<table>
+					<independentVar lookup="row">atmosphere/density-altitude</independentVar>
+					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
+					<tableData>
+						       0     15
+						    0  13.5  14.5
+						43000   7.5   7.7
+					</tableData>
+				</table>
+			</function>
+		</fcs_function>
+		
 		<switch name="fbw/protections/overspeed">
 			<default value="fbw/protections/overspeed"/>
 			<test logic="OR" value="0">
 				position/wow eq 1
 				/it-fbw/law ne 0
 				/instrumentation/airspeed-indicator/indicated-speed-kt le /FMGC/internal/vmo-mmo
-				aero/alpha-deg-damped ge fbw/stall-alpha-deg
+				aero/alpha-deg-damped ge fbw/alpha-stall-deg
 			</test>
 			<test value="1">
 				/instrumentation/airspeed-indicator/indicated-speed-kt ge /FMGC/internal/vmo-mmo-plus-6
@@ -1476,7 +1504,7 @@
 		
 		<summer name="fbw/pitch/stall-alpha-error">
 			<input>aero/alpha-deg-fixed</input>
-			<input>-fbw/stall-alpha-deg</input>
+			<input>-fbw/alpha-stall-deg</input>
 		</summer>
 		
 		<fcs_function name="fbw/pitch/e-i-min">
diff --git a/Systems/a320-fmgc.xml b/Systems/a320-fmgc.xml
index a5a9cbbe..6a18f58d 100644
--- a/Systems/a320-fmgc.xml
+++ b/Systems/a320-fmgc.xml
@@ -191,32 +191,64 @@
 		</fcs_function>
 		
 		<!-- V alpha prot/max -->
-		<lag_filter name="/FMGC/internal/valphadot-lag">
-			<input>aero/alphadot-rad_sec</input>
-			<c1>0.75</c1>
+		<lag_filter name="/FMGC/internal/valpha-lag">
+			<input>aero/alpha-deg-fixed</input>
+			<c1>0.3</c1>
 		</lag_filter>
 		
-		<pure_gain name="/FMGC/internal/valphadot-offset">
-			<input>/FMGC/internal/valphadot-lag</input>
-			<gain>125</gain>
-		</pure_gain>
-		
-		<fcs_function name="/FMGC/internal/valpha-prot">
+		<fcs_function name="/FMGC/internal/valpha-prot-input">
 			<function>
-				<sum>
-					<product>
-						<property>/FMGC/internal/vs1g-kts</property>
-						<value>1.09</value>
-					</product>
-					<property>/FMGC/internal/valphadot-offset</property>
-				</sum>
+				<sqrt>
+					<quotient>
+						<property>/FMGC/internal/valpha-lag</property>
+						<property>fbw/alpha-prot-deg</property>
+					</quotient>
+				</sqrt>
 			</function>
 		</fcs_function>
 		
-		<summer name="/FMGC/internal/valpha-max">
-			<input>/FMGC/internal/vs1g-kts</input>
-			<input>/FMGC/internal/valphadot-offset</input>
-		</summer>
+		<fcs_function name="/FMGC/internal/valpha-max-input">
+			<function>
+				<sqrt>
+					<quotient>
+						<property>/FMGC/internal/valpha-lag</property>
+						<property>fbw/alpha-max-deg</property>
+					</quotient>
+				</sqrt>
+			</function>
+		</fcs_function>
+		
+		<fcs_function name="/FMGC/internal/valpha-prot">
+			<function>
+				<product>
+					<property>velocities/vc-kts</property>
+					<table>
+						<independentVar lookup="row">/FMGC/internal/valpha-prot-input</independentVar>
+						<tableData>
+							0  0.3
+							1  1.0
+							2  1.6
+						</tableData>
+					</table>
+				</product>
+			</function>
+		</fcs_function>
+		
+		<fcs_function name="/FMGC/internal/valpha-max">
+			<function>
+				<product>
+					<property>velocities/vc-kts</property>
+					<table>
+						<independentVar lookup="row">/FMGC/internal/valpha-max-input</independentVar>
+						<tableData>
+							0  0.3
+							1  1.0
+							2  1.6
+						</tableData>
+					</table>
+				</product>
+			</function>
+		</fcs_function>
 		
 		<!-- Extra VS1g tables for predictions etc -->
 		<fcs_function name="/FMGC/internal/vs1g-conf-0">
@@ -588,13 +620,10 @@
 		</switch>
 		
 		<switch name="/FMGC/internal/vls-factor-cmd">
-			<default value="1.28"/> <!-- 1.28 VS1g -->
+			<default value="1.23"/>
 			<test value="1.13"> <!-- 1.13 VS1g -->
 				/FMGC/internal/takeoff-latch eq 1
 			</test>
-			<test value="1.23"> <!-- 1.23 VS1g -->
-				fcs/flap-pos-deg ge 0.1
-			</test>
 		</switch>
 		
 		<switch name="/FMGC/internal/vls-factor-rate">
@@ -625,7 +654,9 @@
 							</table>
 						</sum>
 					</product>
+					<!-- Never drop below either of the following -->
 					<value>113</value>
+					<property>/FMGC/internal/valpha-prot</property>
 				</max>
 			</function>
 			<clipto>
diff --git a/Systems/a320-v2527-a5-engine-fadec.xml b/Systems/a320-v2527-a5-engine-fadec.xml
index 26216e69..9f621320 100644
--- a/Systems/a320-v2527-a5-engine-fadec.xml
+++ b/Systems/a320-v2527-a5-engine-fadec.xml
@@ -13,6 +13,7 @@
 	<property value="22.4">fadec/limit/min-n1</property>
 	<property value="100">fadec/limit/max-n1</property>
 	<property value="0">fadec/athr/cmd</property>
+	<property value="0">fadec/inhibit-alpha-floor</property>
 	
 	<channel name="Thrust Limits">
 		
@@ -1468,7 +1469,7 @@
 		
 		<!-- Alpha Floor and Toga Lk -->
 		<switch name="fadec/alpha-floor-engage">
-			<default value="14.5"/>
+			<default value="13"/>
 			<test logic="OR" value="15">
 				/controls/flight/flaps-pos eq 1
 				/controls/flight/flaps-pos eq 2
@@ -1483,7 +1484,7 @@
 		</switch>
 		
 		<switch name="fadec/alpha-floor-disengage">
-			<default value="8"/>
+			<default value="11"/>
 			<test logic="OR" value="13">
 				/controls/flight/flaps-pos eq 1
 				/controls/flight/flaps-pos eq 2
@@ -1502,6 +1503,7 @@
 			<test logic="OR" value="0"> <!-- Reset -->
 				position/wow eq 1
 				/it-fbw/law ne 0
+				fadec/inhibit-alpha-floor eq 1
 				/FMGC/FCU-working eq 0
 				position/gear-agl-ft lt 100
 				fadec/control-1/n1-mode eq 1