diff --git a/doc/source/commands/flight/raw.rst b/doc/source/commands/flight/raw.rst index 880646a4f..1109d10bd 100644 --- a/doc/source/commands/flight/raw.rst +++ b/doc/source/commands/flight/raw.rst @@ -131,7 +131,8 @@ These "Raw" controls allow you the direct control of flight parameters while the * - :ref:`NEUTRAL ` - :ref:`Boolean ` - - Is **kOS** Controlling? + - True if ship:control is doing nothing. + * - :ref:`NEUTRALIZE ` - :ref:`Boolean ` - Releases Control @@ -178,6 +179,11 @@ These "Raw" controls allow you the direct control of flight parameters while the trim instead is because KSP only looks at the trim when its part of the *pilot's* own control structure, not an autpilot's control structure. + *Warning*: + Setting this value can cause :ref:`:NEUTRAL ` to + return false negatives by confusing the system about where the "at + rest" point of the controls are. + .. _SHIP CONTROL PITCHTRIM: .. object:: SHIP:CONTROL:PITCHTRIM @@ -190,6 +196,11 @@ These "Raw" controls allow you the direct control of flight parameters while the trim instead is because KSP only looks at the trim when its part of the *pilot's* own control structure, not an autpilot's control structure. + *Warning*: + Setting this value can cause :ref:`NEUTRAL ` to + return false negatives by confusing the system about where the "at + rest" point of the controls are. + .. _SHIP CONTROL ROLLTRIM: .. object:: SHIP:CONTROL:ROLLTRIM @@ -202,6 +213,11 @@ These "Raw" controls allow you the direct control of flight parameters while the trim when its part of the *pilot's* own control structure, not an autpilot's control structure. + *Warning*: + Setting this value can cause :ref:`NEUTRAL ` to + return false negatives by confusing the system about where the "at + rest" point of the controls are. + .. _SHIP CONTROL FORE: .. object:: SHIP:CONTROL:FORE @@ -253,6 +269,11 @@ These "Raw" controls allow you the direct control of flight parameters while the trim when its part of the *pilot's* own control structure, not an autpilot's control structure. + *Warning*: + Setting this value can cause :ref:`NEUTRAL ` to + return false negatives by confusing the system about where the "at + rest" point of the controls are. + .. _SHIP CONTROL WHEELTHROTTLETRIM: .. object:: SHIP:CONTROL:WHEELTHROTTLETRIM @@ -265,15 +286,40 @@ These "Raw" controls allow you the direct control of flight parameters while the trim when its part of the *pilot's* own control structure, not an autpilot's control structure. + *Warning*: + Setting this value can cause :ref:`NEUTRAL ` to + return false negatives by confusing the system about where the "at + rest" point of the controls are. + .. _SHIP CONTROL NEUTRAL: +.. _SHIP CONTROL NEUTRALIZE: .. object:: SHIP:CONTROL:NEUTRAL +.. object:: SHIP:CONTROL:NEUTRALIZE - Returns true or false depending if **kOS** has any set controls. *This is not settable.* + These used to be two suffixes but they are now synonyms who's meaning + changes depending on if you set or get them. -.. _SHIP CONTROL NEUTRALIZE: -.. object:: SHIP:CONTROL:NEUTRALIZE + *Getting*: + + ``if (SHIP:CONTROL:NEUTRAL)`` is true when the raw controls are at rest. + + *Setting*: + + ``set SHIP:CONTROL:NEUTRALIZE TO TRUE.`` causes the raw controls to let go. + Setting it to false has no effect. + + *Warnings*: + + Although it has no effect, setting a raw control TRIM value CAN cause + ``NEUTRAL`` to return false when the control is at rest. For example, + if you do ``SET SHIP:CONTROL:YAWTRIM to 0.1.` then when the controls + are at rest, ``SHIP:CONTROL:NEUTRAL`` will return false because the yaw + position of 0 is differing from its trim position of 0.1. - This causes manual control to let go. When set to true, **kOS** lets go of the controls and allows the player to manually control them again. *This is not gettable.* + The two terms ``NEUTRAL`` and ``NEUTRALIZE`` are synonyms. (They used to + be two separate suffixes, one for getting and one for setting, but + that made no sense so they were combined but both spellings were + retained for backward compantiblity with old scripts.) Unlocking controls diff --git a/src/kOS/Suffixed/FlightControl.cs b/src/kOS/Suffixed/FlightControl.cs index f5ca234d6..f2d9b9520 100644 --- a/src/kOS/Suffixed/FlightControl.cs +++ b/src/kOS/Suffixed/FlightControl.cs @@ -4,6 +4,7 @@ using kOS.AddOns.RemoteTech; using kOS.Safe.Encapsulation; using kOS.Safe.Encapsulation.Suffixes; +using kOS.Safe.Exceptions; using kOS.Safe.Utilities; using kOS.Utilities; using Math = System.Math; @@ -31,18 +32,14 @@ public class FlightControl : Structure , IDisposable, IFlightControlParameter private float wheelThrottle; private float wheelThrottleTrim; private float mainThrottle; - private readonly Flushable neutral; - private readonly Flushable killRotation; - private readonly Flushable resetTrim; private bool bound; + private Flushable neutral; private readonly List floatSuffixes; private readonly List vectorSuffixes; public FlightControl(Vessel vessel) { neutral = new Flushable(); - killRotation = new Flushable(); - resetTrim = new Flushable(); bound = false; Vessel = vessel; @@ -59,21 +56,6 @@ public override bool SetSuffix(string suffixName, object value, bool failOkay = float floatValue = 0; Vector vectorValue = null; - if (CheckNeutral(suffixName, value)) - { - return true; - } - - if (CheckKillRotation(suffixName, value)) - { - return true; - } - - if (CheckResetTrim(suffixName, value)) - { - return true; - } - if (floatSuffixes.Contains(suffixName)) { if (!ValueToFloat(value, ref floatValue)) return true; @@ -174,8 +156,7 @@ private void InitializeSuffixes() //OTHER AddSuffix(new[] { "BOUND" }, new SetSuffix(() => bound, value => bound = value)); - AddSuffix(new[] { "NEUTRAL" }, new Suffix(() => neutral.Value)); - + AddSuffix(new[] { "NEUTRAL", "NEUTRALIZE" }, new SetSuffix(IsNeutral, v => {if (v) Neutralize();})); } private Vector GetPilotTranslation() @@ -270,49 +251,36 @@ private static bool ValueToFloat(object value, ref float doubleValue) return true; } - private bool CheckKillRotation(string suffixName, object value) + private void Neutralize() { - if (suffixName.Equals("KILLROTATION", StringComparison.OrdinalIgnoreCase)) - { - killRotation.Value = bool.Parse(value.ToString()); - return true; - } - killRotation.Value = false; - return false; - } - private bool CheckResetTrim(string suffixName, object value) - { - if (suffixName.Equals("RESETTRIM", StringComparison.OrdinalIgnoreCase)) - { - resetTrim.Value = bool.Parse(value.ToString()); - return true; - } - resetTrim.Value = false; - return false; - } - - private bool CheckNeutral(string suffixName, object value) - { - if (suffixName.Equals("NEUTRALIZE", StringComparison.OrdinalIgnoreCase)) - { - ResetControls(); - neutral.Value = bool.Parse(value.ToString()); - return true; - } - neutral.Value = false; - return false; + ResetControls(); } private void ResetControls() { yaw = default(float); + yawTrim = default(float); pitch = default(float); + pitchTrim = default(float); roll = default(float); + rollTrim = default(float); fore = default(float); starboard = default(float); top = default(float); wheelSteer = default(float); + wheelSteerTrim = default(float); wheelThrottle = default(float); + wheelThrottleTrim = default(float); + neutral.Value = true; + neutral.SetStale(); + } + + private BooleanValue IsNeutral() + { + return (yaw == yawTrim && pitch == pitchTrim && roll == rollTrim && + fore == 0 && starboard == 0 && top == 0 && + wheelSteer == wheelSteerTrim && wheelThrottle == wheelSteerTrim); + } private void OnFlyByWire(FlightCtrlState st) @@ -322,14 +290,7 @@ private void OnFlyByWire(FlightCtrlState st) if (neutral.FlushValue) { st.Neutralize(); - } - } - - if (resetTrim.IsStale) - { - if (resetTrim.FlushValue) - { - st.ResetTrim(); + neutral.Value = false; } } @@ -363,7 +324,7 @@ bool IFlightControlParameter.Enabled { get { - return !neutral.Value; + return !IsNeutral(); } } @@ -417,14 +378,12 @@ void IFlightControlParameter.EnableControl(SharedObjects shared) void IFlightControlParameter.DisableControl(SharedObjects shared) { - // We'll just neutralize here - neutral.Value = true; + Neutralize(); } void IFlightControlParameter.DisableControl() { - // We'll just neutralize here - neutral.Value = true; + Neutralize(); } void IFlightControlParameter.CopyFrom(IFlightControlParameter origin)