Exemplo n.º 1
0
        public void autopilotModeCallback(byte ID, object Data)
        {
            byte[] payload = (byte[])Data;

            VesselAutopilot autopilot = FlightGlobals.ActiveVessel.Autopilot;

            if (autopilot == null)
            {
                Debug.Log("KerbalSimpit : Ignoring a SAS MODE Message since I could not find the autopilot");
                return;
            }

            mySASMode = (VesselAutopilot.AutopilotMode)(payload[0]);

            if (autopilot.CanSetMode(mySASMode))
            {
                autopilot.SetMode(mySASMode);
                if (KSPit.Config.Verbose)
                {
                    Debug.Log(String.Format("KerbalSimpit: payload is {0}", mySASMode));
                    Debug.Log(String.Format("KerbalSimpit: SAS mode is {0}", FlightGlobals.ActiveVessel.Autopilot.Mode.ToString()));
                }
            }
            else
            {
                Debug.Log(String.Format("KerbalSimpit: Unable to set SAS mode to {0}", mySASMode.ToString()));
            }
        }
Exemplo n.º 2
0
        public void Update(VesselAutopilot.VesselRSAS rsas)
        {
            PIDRclamp[] sasPID = new PIDRclamp[3];
            sasPID[(int)SASList.Pitch] = rsas.pidPitch;
            sasPID[(int)SASList.Bank] = rsas.pidRoll;
            sasPID[(int)SASList.Hdg] = rsas.pidYaw;

            foreach (SASList s in Enum.GetValues(typeof(SASList)))
            {
                PIDGains[(int)s, 0] = sasPID[(int)s].KP;
                PIDGains[(int)s, 1] = sasPID[(int)s].KI;
                PIDGains[(int)s, 2] = sasPID[(int)s].KD;
            }
        }
Exemplo n.º 3
0
        public void Update(VesselAutopilot.VesselSAS sas)
        {
            PIDclamp[] sasPID = new PIDclamp[3];
            sasPID[(int)SASList.Pitch] = sas.pidLockedPitch;
            sasPID[(int)SASList.Bank] = sas.pidLockedRoll;
            sasPID[(int)SASList.Hdg] = sas.pidLockedYaw;

            foreach (SASList s in Enum.GetValues(typeof(SASList)))
            {
                PIDGains[(int)s, 0] = sasPID[(int)s].kp;
                PIDGains[(int)s, 1] = sasPID[(int)s].ki;
                PIDGains[(int)s, 2] = sasPID[(int)s].kd;
                PIDGains[(int)s, 3] = sasPID[(int)s].clamp;
            }
        }
Exemplo n.º 4
0
        // used for adding a new stock preset
        public RSASPreset(VesselAutopilot.VesselRSAS rsas, string Name)
        {
            name = Name;

            PIDRclamp[] rsasPID = new PIDRclamp[3];
            rsasPID[(int)SASList.Pitch] = rsas.pidPitch;
            rsasPID[(int)SASList.Bank] = rsas.pidRoll;
            rsasPID[(int)SASList.Hdg] = rsas.pidYaw;

            foreach (SASList s in Enum.GetValues(typeof(SASList)))
            {
                PIDGains[(int)s, 0] = rsasPID[(int)s].KP;
                PIDGains[(int)s, 1] = rsasPID[(int)s].KI;
                PIDGains[(int)s, 2] = rsasPID[(int)s].KD;
            }
        }
        public static bool SetActualMode(this VesselAutopilot autopilot, VesselAutopilot.AutopilotMode mode)
        {
            mode = ConvertMode(mode);

            if (autopilot.CanSetMode(mode))
            {
                var result = autopilot.SetMode(mode);

                var autopilotUI = GameObject.FindObjectOfType <VesselAutopilotUI>();
                if (autopilotUI != null && mode >= 0 && (int)mode < autopilotUI.modeButtons.Length)
                {
                    autopilotUI.modeButtons[(int)mode].SetState(true);
                }

                return(result);
            }

            return(false);
        }
Exemplo n.º 6
0
        public void SASInfoProvider()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                // This can happen when docking/undocking/changing scene, etc.
                return;
            }

            VesselAutopilot autopilot = FlightGlobals.ActiveVessel.Autopilot;

            if (autopilot == null)
            {
                return;
            }

            if (autopilot.Enabled)
            {
                newSASInfo.currentSASMode = (byte)autopilot.Mode;
            }
            else
            {
                newSASInfo.currentSASMode = 255; //special value to indicate a disabled SAS
            }

            newSASInfo.SASModeAvailability = 0;
            foreach (VesselAutopilot.AutopilotMode i in Enum.GetValues(typeof(VesselAutopilot.AutopilotMode)))
            {
                if (autopilot.CanSetMode(i))
                {
                    newSASInfo.SASModeAvailability = (ushort)(newSASInfo.SASModeAvailability | (1 << (byte)i));
                }
            }

            if (mySASInfo.currentSASMode != newSASInfo.currentSASMode ||
                mySASInfo.SASModeAvailability != newSASInfo.SASModeAvailability)
            {
                if (SASInfoChannel != null)
                {
                    mySASInfo = newSASInfo;
                    SASInfoChannel.Fire(OutboundPackets.SASInfo, mySASInfo);
                }
            }
        }
 /// <summary>
 /// Force the SAS mode buttons on the flight view to update when we
 /// update modes under the hood.  Code from
 /// http://forum.kerbalspaceprogram.com/threads/105074-Updating-the-auto-pilot-UI?p=1633958&viewfull=1#post1633958
 /// </summary>
 /// <param name="newMode">The new autopilot mode</param>
 private void ForceUpdateSASModeToggleButtons(VesselAutopilot.AutopilotMode newMode)
 {
     // find the UI object on screen
     UIStateToggleButton[] SASbtns = UnityEngine.Object.FindObjectOfType<VesselAutopilotUI>().modeButtons;
     // set our mode, note it takes the mode as an int, generally top to bottom, left to right, as seen on the screen. Maneuver node being the exception, it is 9
     SASbtns.ElementAt<UIStateToggleButton>((int)newMode).SetState(true);
 }
Exemplo n.º 8
0
 public void SelectAutopilotMode(VesselAutopilot.AutopilotMode autopilotMode)
 {
     if (currentVessel.Autopilot.Mode != autopilotMode)
     {
         if (!currentVessel.Autopilot.CanSetMode(autopilotMode))
         {
             // throw an exception if the mode is not available
             throw new Safe.Exceptions.KOSException(
                 string.Format("Cannot set autopilot value, pilot/probe does not support {0}, or there is no node/target", autopilotMode));
         }
         currentVessel.Autopilot.SetMode(autopilotMode);
         //currentVessel.Autopilot.Enable();
         // change the autopilot indicator
         ((Module.kOSProcessor)Shared.Processor).SetAutopilotMode((int)autopilotMode);
         if (RemoteTechHook.IsAvailable(currentVessel.id))
         {
             Debug.Log(string.Format("kOS: Adding RemoteTechPilot: autopilot For : " + currentVessel.id));
             // TODO: figure out how to make RemoteTech allow the built in autopilot control.  This may require modification to RemoteTech itself.
         }
     }
 }
 public static bool CanSetActualMode(this VesselAutopilot autopilot, VesselAutopilot.AutopilotMode mode)
 {
     return(autopilot.CanSetMode(ConvertMode(mode)));
 }
Exemplo n.º 10
0
 public static VesselAutopilot.AutopilotMode GetActualMode(this VesselAutopilot autopilot)
 {
     return(ConvertMode(autopilot.Mode));
 }