From 1e4ae2ed997cd4c8b59e2f48fb64a74e29bb7d3f Mon Sep 17 00:00:00 2001
From: Josh Davidson <joshdavidson2000@outlook.com>
Date: Fri, 5 Aug 2022 14:51:49 -0400
Subject: [PATCH] Control: Add high/low speed stability to alternate law

---
 Systems/a320-fbw.xml  | 65 +++++++++++++++++++++++++++++++++++++++++--
 Systems/a320-fmgc.xml |  2 +-
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/Systems/a320-fbw.xml b/Systems/a320-fbw.xml
index 706d70cd..892a2019 100644
--- a/Systems/a320-fbw.xml
+++ b/Systems/a320-fbw.xml
@@ -226,6 +226,15 @@
 			</test>
 		</switch>
 		
+		<switch name="fbw/protections/hi-low-stab-en">
+			<default value="1"/>
+			<test logic="OR" value="0">
+				position/wow eq 1
+				/it-fbw/law ne 1
+				position/gear-agl-ft le 100
+			</test>
+		</switch>
+		
 		<fcs_function name="fbw/roll/p-gain">
 			<function>
 				<table>
@@ -1459,11 +1468,21 @@
 			<c1>20</c1>
 		</lag_filter>
 		
-		<summer name="fbw/pitch/vmo-mmo-error">
+		<summer name="fbw/pitch/vmo-mmo-pred-error">
 			<input>fbw/pitch/ias-predict</input>
 			<input>-/FMGC/internal/vmo-mmo</input>
 		</summer>
 		
+		<summer name="fbw/pitch/vmo-mmo-error">
+			<input>/instrumentation/airspeed-indicator/indicated-speed-kt</input>
+			<input>-/FMGC/internal/vmo-mmo</input>
+		</summer>
+		
+		<summer name="fbw/pitch/vsw-error">
+			<input>/instrumentation/airspeed-indicator/indicated-speed-kt</input>
+			<input>-/FMGC/internal/vsw</input>
+		</summer>
+		
 		<fcs_function name="fbw/pitch/e-i-n">
 			<function>
 				<sum>
@@ -1486,7 +1505,7 @@
 				<table>
 					<independentVar lookup="row">fbw/sidestick/pitch-input</independentVar>
 					<independentVar lookup="column">fbw/pitch/vc-kts-rate</independentVar>
-					<independentVar lookup="table">fbw/pitch/vmo-mmo-error</independentVar>
+					<independentVar lookup="table">fbw/pitch/vmo-mmo-pred-error</independentVar>
 					<tableData breakPoint="6"> <!-- Engage point, reduced forwards authority -->
 						   -1    1    3
 						-1 -1.0 -1.0 -1.0
@@ -1692,6 +1711,46 @@
 			</function>
 		</fcs_function>
 		
+		<fcs_function name="fbw/pitch/e-i-hs">
+			<function>
+				<table>
+					<independentVar lookup="row">fbw/pitch/vmo-mmo-error</independentVar>
+					<independentVar lookup="column">fbw/protections/hi-low-stab-en</independentVar>
+					<tableData>
+						   0    1
+						0  0.0  0.00
+						5  0.0 -0.20
+						8  0.0 -0.25
+					</tableData>
+				</table>
+			</function>
+		</fcs_function>
+		
+		<fcs_function name="fbw/pitch/e-i-ls">
+			<function>
+				<table>
+					<independentVar lookup="row">fbw/pitch/vsw-error</independentVar>
+					<independentVar lookup="column">fbw/protections/hi-low-stab-en</independentVar>
+					<independentVar lookup="table">fcs/flap-pos-deg</independentVar>
+					<tableData breakPoint="0">
+						    0     1
+						-8  0.00  0.25
+						-5  0.00  0.20
+						 0  0.00  0.10
+						 5  0.00  0.05
+						10  0.00  0.00
+					</tableData>
+					<tableData breakPoint="10">
+						    0     1
+						-8  0.00  0.25
+						-5  0.00  0.20
+						 0  0.00  0.10
+						 5  0.00  0.00
+					</tableData>
+				</table>
+			</function>
+		</fcs_function>
+		
 		<fcs_function name="fbw/pitch/over-max">
 			<function>
 				<table>
@@ -1721,6 +1780,8 @@
 		<summer name="fbw/pitch/e-i-sum">
 			<input>fbw/pitch/e-i-cmd</input>
 			<input>fbw/pitch/e-i-fl</input>
+			<input>fbw/pitch/e-i-hs</input>
+			<input>fbw/pitch/e-i-ls</input>
 			<input>fbw/pitch/over-max</input>
 			<input>fbw/pitch/over-min</input>
 			<clipto>
diff --git a/Systems/a320-fmgc.xml b/Systems/a320-fmgc.xml
index 9ec07a0b..01ee6b07 100644
--- a/Systems/a320-fmgc.xml
+++ b/Systems/a320-fmgc.xml
@@ -552,7 +552,7 @@
 				<sum>
 					<product>
 						<property>/FMGC/internal/vs1g</property>
-						<value>1.03</value>
+						<value>1.10</value>
 					</product>
 					<product>
 						<difference>