示例#1
0
        public static ISignalProcessor GetSignalProcessor(this Vessel v)
        {
            RTLog.Notify("GetSignalProcessor({0}): Check", v.vesselName);

            ISignalProcessor result = null;

            if (v.loaded && v.parts.Count > 0)
            {
                var partModuleList = v.Parts.SelectMany(p => p.Modules.Cast <PartModule>()).Where(pm => pm.IsSignalProcessor()).ToList();
                // try to look for a moduleSPU
                result = partModuleList.FirstOrDefault(pm => pm.moduleName == "ModuleSPU") as ISignalProcessor ??
                         partModuleList.FirstOrDefault() as ISignalProcessor;
            }
            else
            {
                var protoPartList = v.protoVessel.protoPartSnapshots.SelectMany(x => x.modules).Where(ppms => ppms.IsSignalProcessor()).ToList();
                // try to look for a moduleSPU on a unloaded vessel
                var protoPartProcessor = protoPartList.FirstOrDefault(ppms => ppms.moduleName == "ModuleSPU") ??
                                         protoPartList.FirstOrDefault();

                // convert the found protoPartSnapshots to a ProtoSignalProcessor
                if (protoPartProcessor != null)
                {
                    result = new ProtoSignalProcessor(protoPartProcessor, v);
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Registers a signal processor for the vessel.
        /// </summary>
        /// <param name="vessel">The vessel.</param>
        /// <param name="spu">The signal processor.</param>
        /// <returns>Guid key under which the signal processor was registered.</returns>
        public Guid Register(Vessel vessel, ISignalProcessor spu)
        {
            RTLog.Notify("SatelliteManager: Register({0})", spu);

            var key = vessel.id;

            if (!_loadedSpuCache.ContainsKey(key))
            {
                UnregisterProto(vessel.id);
                _loadedSpuCache[key] = new List <ISignalProcessor>();
            }
            // Add if non duplicate
            var signalProcessor = _loadedSpuCache[key].Find(x => x == spu);

            if (signalProcessor != null)
            {
                return(key);
            }

            _loadedSpuCache[key].Add(spu);

            // Create a new satellite if it's the only loaded signal processor.
            if (_loadedSpuCache[key].Count != 1)
            {
                return(key);
            }

            _satelliteCache[key] = new VesselSatellite(_loadedSpuCache[key]);
            OnRegister(_satelliteCache[key]);

            return(key);
        }
示例#3
0
 public void OpenFlightComputer(ISignalProcessor sp)
 {
     if (sp.FlightComputer != null)
     {
         (new FlightComputerWindow(sp.FlightComputer)).Show();
     }
 }
示例#4
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> >();
            LastTarget       = TargetCommand.WithTarget(null);

            var attitude = AttitudeCommand.Off();

            _activeCommands[attitude.Priority] = attitude;

            //Use http://www.ni.com/white-paper/3782/en/ to fine-tune
            PIDController = new PIDController(PIDKp, PIDKi, PIDKd, 1.0, -1.0, true);
            PIDController.SetVessel(Vessel);

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

            RoverComputer = new RoverComputer(this, RoverPIDKp, RoverPIDKi, RoverPIDKd);
            RoverComputer.SetVessel(Vessel);

            // Add RT listeners from KSP Autopilot
            StockAutopilotCommand.UIreference = GameObject.FindObjectOfType <VesselAutopilotUI>();
            for (var index = 0; index < StockAutopilotCommand.UIreference.modeButtons.Length; index++)
            {
                var buttonIndex = index; // prevent compiler optimisation from assigning static final index value
                StockAutopilotCommand.UIreference.modeButtons[index].onClick.AddListener(delegate { StockAutopilotCommand.AutopilotButtonClick(buttonIndex, this); });
                // bad idea to use RemoveAllListeners() since no easy way to re-add the original stock listener to onClick
            }
        }
示例#5
0
        /// <summary>
        /// Registers a signal processor for the vessel.
        /// </summary>
        /// <param name="vessel">The vessel.</param>
        /// <param name="spu">The signal processor.</param>
        /// <returns>Guid key under which the signal processor was registered.</returns>
        public Guid Register(Vessel vessel, ISignalProcessor spu)
        {
            Guid key = vessel.protoVessel.vesselID;

            RTUtil.Log("SatelliteManager: Register {0}, {1} ", key, spu.Vessel.vesselName);
            // Unregister any unloaded proto-satellites if necessary.
            if (!mLoadedSpuCache.ContainsKey(key))
            {
                UnregisterProto(vessel.id);
                mLoadedSpuCache[key] = new List <ISignalProcessor>();
            }
            // Add if non duplicate
            ISignalProcessor instance = mLoadedSpuCache[key].Find(x => x == spu);

            if (instance == null)
            {
                mLoadedSpuCache[key].Add(spu);
                // Create a new satellite if it's the only loaded signal processor.
                if (mLoadedSpuCache[key].Count == 1)
                {
                    mSatelliteCache[key] = new VesselSatellite(mLoadedSpuCache[key]);
                    OnRegister(mSatelliteCache[key]);
                }
            }

            return(key);
        }
示例#6
0
        /// <summary>
        /// Registers a signal processor for the vessel.
        /// </summary>
        /// <param name="vessel">The vessel.</param>
        /// <param name="spu">The signal processor.</param>
        /// <returns>Guid key under which the signal processor was registered.</returns>
        public Guid Register(Vessel vessel, ISignalProcessor spu)
        {
            Guid key = vessel.id;

            RTLog.Notify("SatelliteManager: Register({0})", spu);

            if (!mLoadedSpuCache.ContainsKey(key))
            {
                UnregisterProto(vessel.id);
                mLoadedSpuCache[key] = new List <ISignalProcessor>();
            }
            // Add if non duplicate
            ISignalProcessor instance = mLoadedSpuCache[key].Find(x => x == spu);

            if (instance == null)
            {
                mLoadedSpuCache[key].Add(spu);
                // Create a new satellite if it's the only loaded signal processor.
                if (mLoadedSpuCache[key].Count == 1)
                {
                    mSatelliteCache[key] = new VesselSatellite(mLoadedSpuCache[key]);
                    OnRegister(mSatelliteCache[key]);
                }
            }

            return(key);
        }
示例#7
0
        /// <summary>
        /// Unregisters the specified signal processor.
        /// </summary>
        /// <param name="key">The key the signal processor was registered under.</param>
        /// <param name="spu">The signal processor.</param>
        public void Unregister(Guid key, ISignalProcessor spu)
        {
            RTUtil.Log("SatelliteManager: Unregister {0}", key);
            // Return if nothing to unregister.
            if (!mLoadedSpuCache.ContainsKey(key))
            {
                return;
            }
            // Find instance of the signal processor.
            int instance_id = mLoadedSpuCache[key].FindIndex(x => x == spu);

            if (instance_id != -1)
            {
                // Remove satellite if no signal processors remain.
                if (mLoadedSpuCache[key].Count == 1)
                {
                    if (mSatelliteCache.ContainsKey(key))
                    {
                        VesselSatellite sat = mSatelliteCache[key];
                        OnUnregister(sat);
                        mSatelliteCache.Remove(key);
                    }
                    mLoadedSpuCache[key].RemoveAt(instance_id);
                    mLoadedSpuCache.Remove(key);
                    RegisterProto(spu.Vessel);
                }
                else
                {
                    mLoadedSpuCache[key].RemoveAt(instance_id);
                }
            }
        }
示例#8
0
        public ProgcomUnit(ISignalProcessor s)
        {
            mSignalProcessor = s;
            mCPU             = CreateCPU();
            mAssembler       = CreateAssembler();

            IO = new ProgcomIO(this, 32, null);
        }
        public ProgcomUnit(ISignalProcessor s)
        {
            mSignalProcessor = s;
            mCPU = CreateCPU();
            mAssembler = CreateAssembler();

            IO = new ProgcomIO(this, 32, null);
        }
示例#10
0
 public FlightComputer(ISignalProcessor s)
 {
     SignalProcessor = s;
     Vessel = s.Vessel;
     SanctionedPilots = new List<Action<FlightCtrlState>>();
     Enqueue(TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget), true);
     Enqueue(AttitudeCommand.Off(), true);
 }
 public FlightComputer(ISignalProcessor s)
 {
     mSignalProcessor = s;
     mPreviousCtrl.CopyFrom(s.Vessel.ctrlState);
     mAttachedVessel = s.Vessel;
     mLegacyComputer = new Legacy.FlightComputer();
     mRoverComputer  = new RoverComputer(s.Vessel);
     Bifrost         = new BifrostUnit(s);
 }
示例#12
0
        public FlightComputer(ISignalProcessor s)
        {
            SignalProcessor = s;
            Vessel = s.Vessel;
            SanctionedPilots = new List<Action<FlightCtrlState>>();

            var target = TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget);
            mActiveCommands[target.Priority] = target;
            var attitude = AttitudeCommand.Off();
            mActiveCommands[attitude.Priority] = attitude;
        }
示例#13
0
        public BifrostUnit(ISignalProcessor s)
        {
            mSignalProcessor = s;
            mCPU             = new BifrostCPUWorker();

            Keyboard = new GenericKeyboard();
            Clock    = new GenericClock();
            Monitor  = new LEM1802();

            mCPU.CPU.ConnectDevice(Keyboard);
            mCPU.CPU.ConnectDevice(Clock);
            mCPU.CPU.ConnectDevice(Monitor);
        }
        public BifrostUnit(ISignalProcessor s)
        {
            mSignalProcessor = s;
            mCPU = new BifrostCPUWorker();

            Keyboard = new GenericKeyboard();
            Clock = new GenericClock();
            Monitor = new LEM1802();

            mCPU.CPU.ConnectDevice(Keyboard);
            mCPU.CPU.ConnectDevice(Clock);
            mCPU.CPU.ConnectDevice(Monitor);
        }
示例#15
0
        public FlightComputer(ISignalProcessor s)
        {
            SignalProcessor  = s;
            Vessel           = s.Vessel;
            SanctionedPilots = new List <Action <FlightCtrlState> >();

            var target = TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget);

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

            mActiveCommands[attitude.Priority] = attitude;
        }
示例#16
0
        void ExecuteFilter(ISignalProcessor <IsgTimeImageSignalSource, IsgTimeImageSignalSource> processor)
        {
            //Get a copy of the selected image and create new image, that can be operated on
            var imageSource = new IsgTimeImageSignalSource(Image.BitmapImage2Bitmap());

            //Use the selected filter on the image
            IsgTimeImageSignalSource res = processor.Process(imageSource);

            //Change the image in the view
            Image = BitmapToImageSource(res.Image);

            //dispose the copied image
            imageSource.Image.Dispose();
        }
        public void SetUp()
        {
            _signal1 = new Signal {
                Readouts = new List <double> {
                    1.5, 3, 5.5
                }
            };
            _signal2 = new Signal {
                Readouts = new List <double> {
                    1.5, -0.5, 2.5, -1
                }
            };

            _subject = new SignalProcessor();
        }
示例#18
0
        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;

            var target = TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget);

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

            mActiveCommands[attitude.Priority] = attitude;
        }
示例#19
0
        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;

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

            GameEvents.onVesselChange.Add(OnVesselChange);

            mRoverComputer = new RoverComputer();
            mRoverComputer.SetVessel(Vessel);
        }
示例#20
0
        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;

            var attitude = AttitudeCommand.Off();

            mActiveCommands[attitude.Priority] = attitude;

            GameEvents.onVesselChange.Add(OnVesselChange);

            mRoverComputer = new RoverComputer();
            mRoverComputer.SetVessel(Vessel);
        }
示例#21
0
        /// <summary>
        /// Unregisters the specified signal processor.
        /// </summary>
        /// <param name="key">The key the signal processor was registered under.</param>
        /// <param name="spu">The signal processor.</param>
        public void Unregister(Guid key, ISignalProcessor spu)
        {
            RTLog.Notify("SatelliteManager: Unregister({0})", spu);
            // Return if nothing to unregister.
            if (!_loadedSpuCache.ContainsKey(key))
            {
                return;
            }
            // Find instance of the signal processor.
            var instanceId = _loadedSpuCache[key].FindIndex(x => x == spu);

            if (instanceId == -1)
            {
                return;
            }

            // Remove satellite if no signal processors remain.
            if (_loadedSpuCache[key].Count == 1)
            {
                if (_satelliteCache.ContainsKey(key))
                {
                    VesselSatellite sat = _satelliteCache[key];
                    OnUnregister(sat);
                    _satelliteCache.Remove(key);
                }
                _loadedSpuCache[key].RemoveAt(instanceId);
                _loadedSpuCache.Remove(key);

                // search vessel by id
                var vessel = RTUtil.GetVesselById(key);
                if (vessel != null)
                {
                    // trigger the onRails on more time
                    // to re-register the satellite as a protoSat
                    OnVesselOnRails(vessel);
                }
            }
            else
            {
                _loadedSpuCache[key].RemoveAt(instanceId);
            }
        }
        /// <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);
        }
示例#23
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);
        }
示例#24
0
        /// <summary>
        /// Registers a protosatellite compiled from the unloaded vessel data.
        /// </summary>
        /// <param name="vessel">The vessel.</param>
        public void RegisterProto(Vessel vessel)
        {
            Guid key = vessel.protoVessel.vesselID;

            RTUtil.Log("SatelliteManager: RegisterProto {0} ", vessel.vesselName);
            // Return if there are still signal processors loaded.
            if (mLoadedSpuCache.ContainsKey(vessel.id))
            {
                return;
            }

            ISignalProcessor spu = vessel.GetSignalProcessor();

            if (spu != null)
            {
                List <ISignalProcessor> protos = new List <ISignalProcessor>();
                protos.Add(spu);
                mSatelliteCache[key] = new VesselSatellite(protos);
                OnRegister(mSatelliteCache[key]);
            }
        }
示例#25
0
        /// <summary>
        /// Registers a protosatellite compiled from the unloaded vessel data.
        /// </summary>
        /// <param name="vessel">The vessel.</param>
        public void RegisterProto(Vessel vessel)
        {
            Guid key = vessel.protoVessel.vesselID;

            RTLog.Notify("SatelliteManager: RegisterProto({0}, {1})", vessel.vesselName, key);
            // Return if there are still signal processors loaded.
            if (mLoadedSpuCache.ContainsKey(vessel.id))
            {
                mLoadedSpuCache.Remove(vessel.id);
            }

            ISignalProcessor spu = vessel.GetSignalProcessor();

            if (spu != null)
            {
                var protos = new List <ISignalProcessor> {
                    spu
                };
                mSatelliteCache[key] = new VesselSatellite(protos);
                OnRegister(mSatelliteCache[key]);
            }
        }
示例#26
0
 ///<summary>Called when loading control to subscribe a given control for signal processing.</summary>
 public static bool SubscribeSignalProcessor(ISignalProcessor sigProcessor)
 {
     //No need to check RemotingRole; no call to db.
     if (sigProcessor is Form)
     {
         ((Form)sigProcessor).FormClosed += delegate {
             _listISignalProcessors.Remove(sigProcessor);
         };
     }
     else if (sigProcessor is Window)
     {
         ((Window)sigProcessor).Closed += delegate {
             _listISignalProcessors.Remove(sigProcessor);
         };
     }
     else
     {
         return(false);
     }
     _listISignalProcessors.Add(sigProcessor);
     return(true);
 }
示例#27
0
 public SignalManager(ISignalProcessor signalProcessor)
 {
     _signalProcessor = signalProcessor;
 }
 public void OpenFlightComputer(ISignalProcessor sp)
 {
     if (sp.FlightComputer != null) {
         (new FlightComputerWindow(sp.FlightComputer)).Show();
     }
 }
示例#29
0
        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;

            var target = TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget);
            mActiveCommands[target.Priority] = target;
            var attitude = AttitudeCommand.Off();
            mActiveCommands[attitude.Priority] = attitude;
        }