コード例 #1
0
        /// <summary>Flight Computer constructor.</summary>
        /// <param name="s">A signal processor (most probably a <see cref="ModuleSPU"/> instance.)</param>
        public FlightComputer(ISignalProcessor s)
        {
            SignalProcessor = s;
            Vessel = s.Vessel;
            SanctionedPilots = new List<Action<FlightCtrlState>>();
            pid = new PIDControllerV3(Vector3d.zero, Vector3d.zero, Vector3d.zero, 1, -1);
            setPIDParameters();
            lastAct = Vector3d.zero;
            LastTarget = TargetCommand.WithTarget(null);

            var attitude = AttitudeCommand.Off();
            _activeCommands[attitude.Priority] = attitude;

            GameEvents.onVesselChange.Add(OnVesselChange);
            GameEvents.onVesselSwitching.Add(OnVesselSwitching);
            GameEvents.onGameSceneSwitchRequested.Add(OnSceneSwitchRequested);

            RoverComputer = new RoverComputer();
            RoverComputer.SetVessel(Vessel);
        }
コード例 #2
0
ファイル: FlightComputer.cs プロジェクト: icedown/RemoteTech
        public FlightComputer(ISignalProcessor s)
        {
            SignalProcessor = s;
            Vessel = s.Vessel;
            SanctionedPilots = new List<Action<FlightCtrlState>>();
            pid = new PIDControllerV2(0, 0, 0, 1, -1);
            initPIDParameters();
            lastAct = Vector3d.zero;
            lastTarget = TargetCommand.WithTarget(null);

            var attitude = AttitudeCommand.Off();
            mActiveCommands[attitude.Priority] = attitude;

            GameEvents.onVesselChange.Add(OnVesselChange);

            mRoverComputer = new RoverComputer();
            mRoverComputer.SetVessel(Vessel);
        }
コード例 #3
0
ファイル: FlightComputer.cs プロジェクト: icedown/RemoteTech
 private void UpdateLastTarget()
 {
     int lastTargetIndex = mCommandQueue.FindLastIndex(c => (c is TargetCommand));
     if (lastTargetIndex >= 0)
     {
         lastTarget = mCommandQueue[lastTargetIndex] as TargetCommand;
     }
     else if (mActiveCommands.ContainsKey(lastTarget.Priority) &&
              mActiveCommands[lastTarget.Priority] is TargetCommand)
     {
         lastTarget = mActiveCommands[lastTarget.Priority] as TargetCommand;
     }
     else
     {
         lastTarget = TargetCommand.WithTarget(null);
     }
 }
コード例 #4
0
ファイル: FlightComputer.cs プロジェクト: ec429/RemoteTech
        public void OnFixedUpdate()
        {
            if (Vessel == null)
            {
                Vessel = SignalProcessor.Vessel;
                mRoverComputer.SetVessel(Vessel);
            }

            // only handle onFixedUpdate if the ship is unpacked
            if (Vessel.packed)
                return;

            // Do we have a config?
            if (fcLoadedConfigs != null)
            {
                // than load
                load(fcLoadedConfigs);
                fcLoadedConfigs = null;
            }

            // Re-attach periodically
            Vessel.OnFlyByWire -= OnFlyByWirePre;
            Vessel.OnFlyByWire -= OnFlyByWirePost;
            if (Vessel != SignalProcessor.Vessel)
            {
                SanctionedPilots.Clear();
                Vessel = SignalProcessor.Vessel;
                mRoverComputer.SetVessel(Vessel);
            }
            Vessel.OnFlyByWire = OnFlyByWirePre + Vessel.OnFlyByWire + OnFlyByWirePost;

            // Update proportional controller for changes in ship state
            updatePIDParameters();

            // Send updates for Target
            if (FlightGlobals.fetch.VesselTarget != DelayedTarget && (mCommandQueue.FindLastIndex(c => (lastTarget = c as TargetCommand) != null)) == -1)
            {
                Enqueue(TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget));
            }
        }
コード例 #5
0
ファイル: AbstractCommand.cs プロジェクト: icedown/RemoteTech
        /// <summary>
        /// Load and creates a command after saving a command. Returns null if no object
        /// has been loaded.
        /// </summary>
        /// <param name="n">Node with the command infos</param>
        /// <param name="fc">Current flightcomputer</param>
        public static ICommand LoadCommand(ConfigNode n, FlightComputer fc)
        {
            ICommand command = null;

            // switch the different commands
            switch (n.name)
            {
                case "AttitudeCommand":     { command = new AttitudeCommand(); break; }
                case "ActionGroupCommand":  { command = new ActionGroupCommand(); break; }
                case "BurnCommand":         { command = new BurnCommand(); break; }
                case "ManeuverCommand":     { command = new ManeuverCommand(); break; }
                case "CancelCommand":       { command = new CancelCommand(); break; }
                case "TargetCommand":       { command = new TargetCommand(); break; }
                case "EventCommand":        { command = new EventCommand(); break; }
                case "DriveCommand":        { command = new DriveCommand(); break; }
                case "ExternalAPICommand":  { command = new ExternalAPICommand(); break; }
            }

            if (command != null)
            {
                ConfigNode.LoadObjectFromConfig(command, n);
                // additional loadings
                var result = command.Load(n, fc);
                RTLog.Verbose("Loading command {0}({1})={2}", RTLogLevel.LVL1, n.name, command.CmdGuid, result);
                // delete command if we can't load the command correctlys
                if (result == false)
                    command = null;
            }

            return command;
        }