From 433fe4ca0ecedc6c10c2b84e34d7ffc3da19b939 Mon Sep 17 00:00:00 2001 From: Josh Davidson Date: Sat, 10 Oct 2020 20:23:41 -0400 Subject: [PATCH] Control: Refactor cockpit elevator trim clickspots to properly control the trim, fixes #150 --- Models/FlightDeck/a320.flightdeck.xml | 10 ++++------ Nasal/Libraries/libraries.nas | 17 +++++++++++++++++ Nasal/Libraries/property-tree-setup.nas | 5 ++++- Systems/a320-fcs.xml | 2 +- revision.txt | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Models/FlightDeck/a320.flightdeck.xml b/Models/FlightDeck/a320.flightdeck.xml index afc59808..098a32a4 100644 --- a/Models/FlightDeck/a320.flightdeck.xml +++ b/Models/FlightDeck/a320.flightdeck.xml @@ -6174,9 +6174,8 @@ true - property-adjust - controls/flight/elevator-trim - 0.01 + nasal + @@ -6184,9 +6183,8 @@ true - property-adjust - controls/flight/elevator-trim - -0.01 + nasal + diff --git a/Nasal/Libraries/libraries.nas b/Nasal/Libraries/libraries.nas index e66f8abb..b0000108 100644 --- a/Nasal/Libraries/libraries.nas +++ b/Nasal/Libraries/libraries.nas @@ -463,6 +463,23 @@ setlistener("/controls/flight/elevator-trim", func { } }, 0, 0); +# For the cockpit rotation and anywhere else you want to use it +var cmdDegCalc = 0; +var slewPitchWheel = func(d) { + cmdDegCalc = math.round(pts.Fdm.JSBsim.Hydraulics.ElevatorTrim.cmdDeg.getValue(), 0.1); + if (d > 0) { # DN + if (cmdDegCalc < 4) { + cmdDegCalc = (cmdDegCalc + 0.1) / 13.5; # Add and normalize, NOT 4! 13.5 = 1 on either polarity + pts.Controls.Flight.elevatorTrim.setValue(cmdDegCalc); + } + } else { # UP + if (cmdDegCalc > -13.5) { + cmdDegCalc = (cmdDegCalc - 0.1) / 13.5; # Subtract and normalize + pts.Controls.Flight.elevatorTrim.setValue(cmdDegCalc); + } + } +} + ########## # Lights # ########## diff --git a/Nasal/Libraries/property-tree-setup.nas b/Nasal/Libraries/property-tree-setup.nas index 5da89e37..f399a305 100644 --- a/Nasal/Libraries/property-tree-setup.nas +++ b/Nasal/Libraries/property-tree-setup.nas @@ -96,8 +96,11 @@ var Fdm = { elevator: props.globals.getNode("/fdm/jsbsim/fbw/elevator-sidestick"), }, Hydraulics: { + ElevatorTrim: { + cmdDeg: props.globals.getNode("/fdm/jsbsim/hydraulics/elevator-trim/cmd-deg"), + }, Rudder: { - trimDeg: props.globals.getNode("fdm/jsbsim/hydraulics/rudder/trim-deg"), + trimDeg: props.globals.getNode("/fdm/jsbsim/hydraulics/rudder/trim-deg"), }, }, Inertia: { diff --git a/Systems/a320-fcs.xml b/Systems/a320-fcs.xml index 7352d6aa..9b6a1386 100644 --- a/Systems/a320-fcs.xml +++ b/Systems/a320-fcs.xml @@ -317,7 +317,7 @@ /controls/flight/elevator-trim - -1.00 + -1.0 0.296296 diff --git a/revision.txt b/revision.txt index 72f523f3..86ee83a4 100644 --- a/revision.txt +++ b/revision.txt @@ -1 +1 @@ -39 \ No newline at end of file +40 \ No newline at end of file