Exemplo n.º 1
0
        // newMode is the mode the user is currently requesting, may be same as current mode
        // active is true if we should be controlling pitch at all
        // implicitSet means that we should set the target based on the current flight state
        // it is true when the user just changes the mode or enables the vert AP, it is false when they actually
        // press the "change current target" button.
        private void vertModeChanged(VertMode newMode, bool active, bool implicitSet = true)
        {
            // So what is the logic here?
            // So if they are disabling, pretty clear (though must we invalidate the PID ctrls or not?)
            // Can be turned on via the generic "enable vert AP" button, presumably there is a mode selected
            // but either it has been used before or not. But the "target" is visible to the user.
            // Can be turned on by selecting a "target" value with a given mode. In this case it is clear
            // what to do: change the proper set point to that target.
            // Also the mode could get changed with us active. In that case the "target" for that mode
            // is actually not controlled by user initially and we must come up with a reasonable target.
            //
            // So specifically: if new mode is pitch and active is true and implicit set is true
            //  -> elev set point is current pitch
            // If implicit set is false
            //  -> elev set point should already be valid

            vertSpeedCtrl.skipDerivative = true;
            elevCtrl.skipDerivative = true;
            altCtrl.skipDerivative = true;

            // If it is going inactive, the "newMode" is not really applicable--it is just the last mode that was used.
            // But if we are inactive and the user simply changes the mode (leaving us inactive) the new mode will be
            // different.
            if (!active)
            {
                // allow the player to control the vertical axis again
                InputLockManager.RemoveControlLock(pitchLockID);
                pitchLockEngaged = false;

                // should we clear these?
                altCtrl.Clear();
                vertSpeedCtrl.Clear();
                elevCtrl.Clear();

                // could use state.pitchTrim here if we wanted to leave craft with most recent pitch as trim
                CurrentVertMode = newMode;
                VertActive = false;

                return;
            }

            // we are active

            // lock the player out of pitch axis controls
            if (!pitchLockEngaged)
            {
                InputLockManager.SetControlLock(ControlTypes.PITCH, pitchLockID);
                pitchLockEngaged = true;
            }

            // used to call PDI.Preset() on all the controllers
            // this sets the integral error sum to something.
            // I can see that you would be concerned that the integral error
            // is no longer valid for new situation, but it caused problems
            // with pitch suddenly moving the wrong direction.

            switch (newMode)
            {
                case VertMode.Pitch:
                    if (implicitSet)
                    {
                        // so the elevCtrl output is a scalar -1 to 1 for how much pitch input is given
                        // the input to elevCtrl is a desired "pitch angle" normally checked against
                        // the vesselData.pitch which is calculated from the planet "up vector" and
                        // the vessel.transform.up.
                        elevCtrl.SetPoint = vesselData.pitch;
                    }
                    targetVert = elevCtrl.SetPoint;
                    break;

                case VertMode.VSpeed:
                    if (implicitSet)
                    {
                        vertSpeedCtrl.SetPoint = vesselData.vertSpeed;
                    }
                    targetVert = vertSpeedCtrl.SetPoint;
                    break;

                case VertMode.Altitude:
                    if (implicitSet)
                    {
                        altCtrl.SetPoint = vessel.altitude;
                    }
                    targetVert = altCtrl.SetPoint;
                    break;

                case VertMode.RadarAltitude:
                    if (implicitSet)
                    {
                        altCtrl.SetPoint = vesselData.radarAlt;
                    }
                    targetVert = altCtrl.SetPoint;
                    break;

                case VertMode.Glideslope:
                    if (validFlightPlan())
                    {
                        vertSpeedCtrl.SetPoint = vesselData.vertSpeed; // flightPlan.GlideSlopeDescentRate(vessel, vesselData);
                        targetVert = vertSpeedCtrl.SetPoint;
                    }
                    else
                    {
                        vertSpeedCtrl.SetPoint = vesselData.vertSpeed;
                        targetVert = vertSpeedCtrl.SetPoint;
                    }
                    break;
            }

            VertActive = active;
            CurrentVertMode = newMode;
        }
Exemplo n.º 2
0
 public NiVertexColorProperty()
 {
     flags        = (ushort)0;
     vertexMode   = (VertMode)0;
     lightingMode = (LightMode)0;
 }
 public NiVertexColorProperty(NiFile niFile) : base(niFile)
 {
     flags        = niFile.Reader.ReadInt16();
     vertexMode   = (VertMode)niFile.Reader.ReadInt32();
     lightingMode = (LightMode)niFile.Reader.ReadInt32();
 }
 public void SetVert(bool active, bool setTarget, VertMode mode, double target)
 {
     if (setTarget)
     {
         switch (mode)
         {
             case VertMode.Altitude:
                 AsstList.Altitude.GetAsst(this).UpdateSetpoint(target, true, Vessel.altitude + vesModule.vesselData.vertSpeed / AsstList.Altitude.GetAsst(this).k_proportional);
                 break;
             case VertMode.RadarAltitude:
                 AsstList.Altitude.GetAsst(this).UpdateSetpoint(target, true, vesModule.vesselData.radarAlt + vesModule.vesselData.vertSpeed / AsstList.Altitude.GetAsst(this).k_proportional);
                 break;
             case VertMode.VSpeed:
                 AsstList.VertSpeed.GetAsst(this).UpdateSetpoint(target, true, vesModule.vesselData.vertSpeed + vesModule.vesselData.AoA / AsstList.VertSpeed.GetAsst(this).k_proportional);
                 break;
             case VertMode.Pitch:
                 AsstList.Elevator.GetAsst(this).UpdateSetpoint(target, true, vesModule.vesselData.pitch);
                 break;
         }
     }
     vertModeChanged(mode, active, !setTarget);
 }
        private void vertModeChanged(VertMode newMode, bool active, bool setTarget = true)
        {
            if (!active)
            {
                InputLockManager.RemoveControlLock(pitchLockID);
                pitchLockEngaged = false;
                AsstList.Altitude.GetAsst(this).Clear();
                AsstList.VertSpeed.GetAsst(this).Clear();
                AsstList.Elevator.GetAsst(this).Clear();
                StartCoroutine(fadeOutPitch());
            }
            else
            {
                if (!pitchLockEngaged)
                {
                    InputLockManager.SetControlLock(ControlTypes.PITCH, pitchLockID);
                    pitchLockEngaged = true;
                }
                bPause = false;

                ////////////////////////////////////////////////////////////////////////////////////////
                // Set the integral sums for the vertical control systems to improve transfer smoothness
                bool invert = Math.Abs(vesModule.vesselData.bank) > 90;
                if (VertActive)
                {
                    AsstList.Elevator.GetAsst(this).Preset(invert);
                    if (CurrentVertMode == VertMode.Altitude || CurrentVertMode == VertMode.RadarAltitude || CurrentVertMode == VertMode.VSpeed)
                    {
                        AsstList.VertSpeed.GetAsst(this).Preset(invert);
                        if (CurrentVertMode == VertMode.Altitude || CurrentVertMode == VertMode.RadarAltitude)
                            AsstList.Altitude.GetAsst(this).Preset(invert);
                        else
                            AsstList.Altitude.GetAsst(this).Preset(vesModule.vesselData.vertSpeed, invert);
                    }
                    else
                    {
                        AsstList.Altitude.GetAsst(this).Preset(vesModule.vesselData.vertSpeed, invert);
                        AsstList.VertSpeed.GetAsst(this).Preset(vesModule.vesselData.AoA, invert);
                    }
                }
                else
                {
                    AsstList.Altitude.GetAsst(this).Preset(vesModule.vesselData.vertSpeed, invert);
                    AsstList.VertSpeed.GetAsst(this).Preset(vesModule.vesselData.AoA, invert);
                    AsstList.Elevator.GetAsst(this).Preset(pitchSet, invert);
                }

                switch (newMode)
                {
                    case VertMode.Pitch:
                        if (setTarget)
                        {
                            AsstList.Elevator.GetAsst(this).UpdateSetpoint(vesModule.vesselData.pitch);
                        }
                        targetVert = AsstList.Elevator.GetAsst(this).target_setpoint.ToString("0.00");
                        break;
                    case VertMode.VSpeed:
                        if (setTarget)
                            AsstList.VertSpeed.GetAsst(this).UpdateSetpoint(vesModule.vesselData.vertSpeed, true, vesModule.vesselData.vertSpeed + vesModule.vesselData.AoA / AsstList.VertSpeed.GetAsst(this).k_proportional);
                        targetVert = AsstList.VertSpeed.GetAsst(this).target_setpoint.ToString("0.00");
                        break;
                    case VertMode.Altitude:
                        if (setTarget)
                            AsstList.Altitude.GetAsst(this).UpdateSetpoint(Vessel.altitude, true, Vessel.altitude + vesModule.vesselData.vertSpeed / AsstList.Altitude.GetAsst(this).k_proportional);
                        targetVert = AsstList.Altitude.GetAsst(this).target_setpoint.ToString("0.00");
                        break;
                    case VertMode.RadarAltitude:
                        if (setTarget)
                            AsstList.Altitude.GetAsst(this).UpdateSetpoint(vesModule.vesselData.radarAlt, true, vesModule.vesselData.radarAlt + vesModule.vesselData.vertSpeed / AsstList.Altitude.GetAsst(this).k_proportional);
                        targetVert = AsstList.Altitude.GetAsst(this).target_setpoint.ToString("0.00");
                        break;
                }
            }
            VertActive = active;
            CurrentVertMode = newMode;
        }
Exemplo n.º 6
0
 public void SetVert(bool active, bool setTarget, VertMode mode, double target)
 {
     if (active && setTarget)
     {
         switch (mode)
         {
             case VertMode.Altitude:
                 if (!VertActive)
                     AsstList.Altitude.GetAsst(this).SetPoint = vesModule.vesselRef.altitude + vesModule.vesselData.vertSpeed / AsstList.Altitude.GetAsst(this).PGain;
                 AsstList.Altitude.GetAsst(this).BumplessSetPoint = target;
                 break;
             case VertMode.RadarAltitude:
                 if (!VertActive)
                     AsstList.Altitude.GetAsst(this).SetPoint = vesModule.vesselData.radarAlt + vesModule.vesselData.vertSpeed / AsstList.Altitude.GetAsst(this).PGain;
                 AsstList.Altitude.GetAsst(this).BumplessSetPoint = target;
                 break;
             case VertMode.VSpeed:
                 AsstList.VertSpeed.GetAsst(this).SetPoint = vesModule.vesselData.vertSpeed + vesModule.vesselData.AoA / AsstList.VertSpeed.GetAsst(this).PGain;
                 AsstList.VertSpeed.GetAsst(this).BumplessSetPoint = target;
                 break;
             case VertMode.Pitch:
                 AsstList.Elevator.GetAsst(this).SetPoint = target;
                 break;
         }
     }
     vertModeChanged(mode, active, !setTarget);
 }