/// <summary>Enqueue a <see cref="FlightCtrlState"/> to the flight control queue.</summary> /// <param name="fs">The <see cref="FlightCtrlState"/> to be queued.</param> private void Enqueue(FlightCtrlState fs) { var dfs = new DelayedFlightCtrlState(fs); dfs.TimeStamp += Delay; if (StockAutopilotCommand.IsAutoPilotEngaged(this) && RTSettings.Instance.EnableSignalDelay) // remove the delay if the autopilot is engaged { var autopilotfs = new DelayedFlightCtrlState(fs); // make copy of FS and apply no delay //nullify autopilot inputs in the delayed fs dfs.State.roll = 0f; dfs.State.rollTrim = 0f; dfs.State.pitch = 0f; dfs.State.pitchTrim = 0f; dfs.State.yaw = 0f; dfs.State.yawTrim = 0f; //nullify throttle autopilotfs.State.mainThrottle = 0f; _flightCtrlQueue.Enqueue(autopilotfs); } _flightCtrlQueue.Enqueue(dfs); }
/// <summary>Enqueue a <see cref="FlightCtrlState"/> to the flight control queue.</summary> /// <param name="fs">The <see cref="FlightCtrlState"/> to be queued.</param> private void Enqueue(FlightCtrlState fs) { var dfs = new DelayedFlightCtrlState(fs); dfs.TimeStamp += Delay; if (StockAutopilotCommand.IsAutoPilotEngaged(this)) // remove the delay if the autopilot is engaged { dfs.TimeStamp -= Delay; } _flightCtrlQueue.Enqueue(dfs); }
/// <summary>Called when the flight computer is disposed. This happens when the <see cref="ModuleSPU"/> is destroyed.</summary> public void Dispose() { RTLog.Notify("FlightComputer: Dispose"); GameEvents.onVesselChange.Remove(OnVesselChange); GameEvents.onVesselSwitching.Remove(OnVesselSwitching); GameEvents.onGameSceneSwitchRequested.Remove(OnSceneSwitchRequested); if (Vessel != null) { // remove flight code controls. Vessel.OnFlyByWire -= OnFlyByWirePre; Vessel.OnFlyByWire -= OnFlyByWirePost; } _flightComputerWindow?.Hide(); // Remove RT listeners from KSP Autopilot if (StockAutopilotCommand.UIreference != null) { 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.RemoveListener(delegate { StockAutopilotCommand.AutopilotButtonClick(buttonIndex, this); }); } StockAutopilotCommand.UIreference = null; } }
/// <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 } }