void GrumpyKerbal(FlightCtrlState state) { try { currentTime = Planetarium.GetUniversalTime(); double waitTime = currentTime + delayTime; FlightCtrlState storeState = new FlightCtrlState(); storeState.CopyFrom(state); flightState.Enqueue(new FlightState(storeState, waitTime)); while (currentTime > flightState.Peek().Time) { FlightState topState = flightState.Dequeue(); state.CopyFrom(topState.State); lastState = topState.State; return; } if (lastState != null) { state.CopyFrom(lastState); } else { state.Neutralize(); } } catch (Exception ex) { Debug.Log("Snacks - GrumpyKerbal: " + ex.Message + ex.StackTrace); } }
/// <summary> /// Here we copy the flight state we received and apply to the specific vessel. /// This method is called by ksp as it's a delegate. It's called on every FixedUpdate /// </summary> private void LunaOnVesselFlyByWire(Guid id, FlightCtrlState st) { if (!Enabled || !FlightStateSystemReady) { return; } if (CurrentFlightState.TryGetValue(id, out var value)) { if (VesselCommon.IsSpectating) { st.CopyFrom(value.GetInterpolatedValue()); } else { //If we are close to a vessel and we both are in space don't copy the //input controls as then the vessel jitters, specially if the other player has SAS on if (FlightGlobals.ActiveVessel && FlightGlobals.ActiveVessel.situation > Vessel.Situations.FLYING) { var interpolatedState = value.GetInterpolatedValue(); st.mainThrottle = interpolatedState.mainThrottle; st.gearDown = interpolatedState.gearDown; st.gearUp = interpolatedState.gearUp; st.headlight = interpolatedState.headlight; st.killRot = interpolatedState.killRot; } else { st.CopyFrom(value.GetInterpolatedValue()); } } } }
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); }
public void CopyFrom(ControlInputs other) { state.CopyFrom(other.state); ThrottleUpdated = other.ThrottleUpdated; WheelThrottleUpdated = other.WheelThrottleUpdated; WheelSteerUpdated = other.WheelSteerUpdated; }
/// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary> /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param> /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param> private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { var delayed = new FlightCtrlState(); float maxThrottle = (Delay >= 0.01) ? 0.0f : fcs.mainThrottle; //Comment: if rocket at launchpad is Local Control and switchs to Remote Control upon launching, throttle is initially zero in this transition //however, it is lethal RO issue as zero throttle even once will count against engine's limited number of ignitions //Workaround: just pipe FCS throttle to delayed state until delay is large enough to revert back to normal RT operation while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = _flightCtrlQueue.Dequeue().State; maxThrottle = Math.Max(maxThrottle, delayed.mainThrottle); } delayed.mainThrottle = maxThrottle; if (!KeepThrottleNoConnect && !InputAllowed) // enforce the rule of shutting throttle down on connection loss { delayed.mainThrottle = 0f; } else if (KeepThrottleNoConnect && LockedThrottleNoConnect) // when connection is lost with the disabled rule of shutting throttle down, throttle is locked { delayed.mainThrottle = LockedThrottlePositionNoConnect; } fcs.CopyFrom(delayed); }
public void OnFlyByWire(FlightCtrlState state) { // State may arrive with SAS or WASD controls pre-applied. Save it and reset pitch/yaw/roll so that it doesn't mess with input. FlightCtrlState preState = new FlightCtrlState(); preState.CopyFrom(state); if (AdvancedFlyByWire.Instance.m_IgnoreFlightCtrlState) { state.pitch = 0; state.yaw = 0; state.roll = 0; } // skill vessel input if we're in time-warp m_DisableVesselControls = TimeWarp.fetch != null && TimeWarp.fetch.current_rate_index != 0 && TimeWarp.fetch.Mode == TimeWarp.Modes.HIGH; m_Throttle.SetMinMaxValues(-state.mainThrottle, 1.0f - state.mainThrottle); m_WheelThrottle.SetMinMaxValues(-1.0f, 1.0f); foreach (ControllerConfiguration config in m_Configuration.controllers) { if (config.isEnabled) { config.iface.Update(state); UpdateAxes(config, state); if (FlightGlobals.ActiveVessel.isEVA) { EVAController.Instance.UpdateEVAFlightProperties(config, state); } CameraController.Instance.UpdateCameraProperties ( m_CameraPitch.Update(), m_CameraHeading.Update(), m_CameraZoom.Update(), config.cameraSensitivity ); } } UpdateFlightProperties(state); ZeroOutFlightProperties(); // Apply pre-state if not neutral and no AFBW input (including trim). if (!preState.isNeutral && AdvancedFlyByWire.Instance.m_IgnoreFlightCtrlState) { float t = controlDetectionThreshold; bool hasInput = Math.Abs(state.pitch) > t || Math.Abs(state.yaw) > t || Math.Abs(state.roll) > t; // hasInput will always be true if trim is active on any axis if (!hasInput) { state.pitch = preState.pitch; state.yaw = preState.yaw; state.roll = preState.roll; } else { state.yaw = Utility.Clamp(state.yaw + state.yawTrim, -1.0f, 1.0f); state.pitch = Utility.Clamp(state.pitch + state.pitchTrim, -1.0f, 1.0f); state.roll = Utility.Clamp(state.roll + state.rollTrim, -1.0f, 1.0f); } } }
public void SendCurrentFlightState() { var flightState = new FlightCtrlState(); flightState.CopyFrom(FlightGlobals.ActiveVessel.ctrlState); var msg = new VesselFlightStateMsgData { VesselId = FlightGlobals.ActiveVessel.id, GearDown = flightState.gearDown, GearUp = flightState.gearUp, Headlight = flightState.headlight, KillRot = flightState.killRot, MainThrottle = flightState.mainThrottle, Pitch = flightState.pitch, PitchTrim = flightState.pitchTrim, Roll = flightState.roll, RollTrim = flightState.rollTrim, WheelSteer = flightState.wheelSteer, WheelSteerTrim = flightState.wheelSteerTrim, WheelThrottle = flightState.wheelThrottle, WheelThrottleTrim = flightState.wheelThrottleTrim, X = flightState.X, Y = flightState.Y, Yaw = flightState.yaw, YawTrim = flightState.yawTrim, Z = flightState.Z }; SendMessage(msg); }
private void OnVesselFlyByWire(Guid id, FlightCtrlState st) { if (FlightStatesDictionary.ContainsKey(id)) { st.CopyFrom(FlightStatesDictionary[id]); } }
public void SendCurrentFlightState() { var flightState = new FlightCtrlState(); flightState.CopyFrom(FlightGlobals.ActiveVessel.ctrlState); var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselFlightStateMsgData>(); msgData.PingMs = NetworkStatistics.PingMs; msgData.GameTime = TimeSyncSystem.UniversalTime; msgData.SubspaceId = WarpSystem.Singleton.CurrentSubspace; msgData.VesselId = FlightGlobals.ActiveVessel.id; msgData.GearDown = flightState.gearDown; msgData.GearUp = flightState.gearUp; msgData.Headlight = flightState.headlight; msgData.KillRot = flightState.killRot; msgData.MainThrottle = flightState.mainThrottle; msgData.Pitch = flightState.pitch; msgData.PitchTrim = flightState.pitchTrim; msgData.Roll = flightState.roll; msgData.RollTrim = flightState.rollTrim; msgData.WheelSteer = flightState.wheelSteer; msgData.WheelSteerTrim = flightState.wheelSteerTrim; msgData.WheelThrottle = flightState.wheelThrottle; msgData.WheelThrottleTrim = flightState.wheelThrottleTrim; msgData.X = flightState.X; msgData.Y = flightState.Y; msgData.Yaw = flightState.yaw; msgData.YawTrim = flightState.yawTrim; msgData.Z = flightState.Z; SendMessage(msgData); }
public void SendCurrentFlightState() { var flightState = new FlightCtrlState(); flightState.CopyFrom(FlightGlobals.ActiveVessel.ctrlState); var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselFlightStateMsgData>(); msgData.VesselId = FlightGlobals.ActiveVessel.id; msgData.GearDown = flightState.gearDown; msgData.GearUp = flightState.gearUp; msgData.Headlight = flightState.headlight; msgData.KillRot = flightState.killRot; msgData.MainThrottle = flightState.mainThrottle; msgData.Pitch = flightState.pitch; msgData.PitchTrim = flightState.pitchTrim; msgData.Roll = flightState.roll; msgData.RollTrim = flightState.rollTrim; msgData.WheelSteer = flightState.wheelSteer; msgData.WheelSteerTrim = flightState.wheelSteerTrim; msgData.WheelThrottle = flightState.wheelThrottle; msgData.WheelThrottleTrim = flightState.wheelThrottleTrim; msgData.X = flightState.X; msgData.Y = flightState.Y; msgData.Yaw = flightState.yaw; msgData.YawTrim = flightState.yawTrim; msgData.Z = flightState.Z; msgData.TimeStamp = LunaTime.UtcNow.Ticks; msgData.GameTime = Planetarium.GetUniversalTime(); SendMessage(msgData); }
public VesselCtrlUpdate(Vessel vessel, Dictionary <Guid, VesselCtrlUpdate> ctrlUpdates, double planetTimeValid, FlightCtrlState oldFcs) { this.vessel = vessel; this.ctrlUpdates = ctrlUpdates; this.planetTimeValid = planetTimeValid; newFcs = new FlightCtrlState(); newFcs.CopyFrom(oldFcs); }
public void SendVesselUpdate() { //TODO: This does not have much performance 0.8ms max... maybe we can use the protovessel for this and do it in another thread? var engines = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleEngines>(); var shieldedDocks = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDockingNode>() .Where(e => !e.IsDisabled && e.deployAnimator != null).ToArray(); // ReSharper disable once UnusedVariable var iScalars = FlightGlobals.ActiveVessel.FindPartModulesImplementing <IScalarModule>(); //This throws a nullpointerexception if you don't have any IScalarModules on the craft. For example, a buggy with only a rovermate core (the white box) and wheels. //IScalarModule module = iScalars.First(); //Put a hook that when the module stops, we send an event //module.OnStop(); var activeEngines = engines.Where(e => e.EngineIgnited).Select(e => e.part.craftID).ToArray(); var stoppedEngines = engines.Where(e => !e.EngineIgnited).Select(e => e.part.craftID).ToArray(); var decouplers = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDecouple>() .Where(e => !e.isDecoupled).Select(e => e.part.craftID).ToArray(); var anchoredDecouplers = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleAnchoredDecoupler>() .Where(e => !e.isDecoupled).Select(e => e.part.craftID).ToArray(); var clamps = FlightGlobals.ActiveVessel.FindPartModulesImplementing <LaunchClamp>().Select(e => e.part.craftID).ToArray(); var docks = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDockingNode>().Where(e => !e.IsDisabled).Select(e => e.part.craftID).ToArray(); var closedShieldDocks = shieldedDocks.Where(d => d.deployAnimator.animSwitch).Select(e => e.part.craftID).ToArray(); var openedShieldDocks = shieldedDocks.Where(d => !d.deployAnimator.animSwitch).Select(e => e.part.craftID).ToArray(); var actionGrpControls = new[] { FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.Gear], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.Light], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.Brakes], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.SAS], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.RCS] }; var flightState = new FlightCtrlState(); flightState.CopyFrom(FlightGlobals.ActiveVessel.ctrlState); var msg = new VesselUpdateMsgData { Stage = FlightGlobals.ActiveVessel.currentStage, ActiveEngines = activeEngines, StoppedEngines = stoppedEngines, Decouplers = decouplers, AnchoredDecouplers = anchoredDecouplers, Clamps = clamps, Docks = docks, VesselId = FlightGlobals.ActiveVessel.id, ActiongroupControls = actionGrpControls, OpenedShieldedDocks = openedShieldDocks, ClosedShieldedDocks = closedShieldDocks }; if (LastMsgSent == null || !MessageDataEqualsToLastMsgSent(msg)) { SendMessage(msg); LastMsgSent = msg; } }
private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { FlightCtrlState delayed = new FlightCtrlState(); while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = mFlightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }
public void UpdateControls(FlightCtrlState vesselFcs) { if (Planetarium.GetUniversalTime() < planetTimeValid) { vesselFcs.CopyFrom(newFcs); } else { vessel.OnFlyByWire -= UpdateControls; ctrlUpdates.Remove(vessel.id); } }
public void SetTarget(VesselFlightStateMsgData msgData) { //If we are in the middle of an interpolation let it finish if (CanInterpolate && !InterpolationFinished) { return; } if (Start == null) { Start = GetFlightCtrlStateFromMsg(msgData); StartTimeStamp = msgData.TimeStamp; return; } if (Target == null) { Target = GetFlightCtrlStateFromMsg(msgData); EndTimeStamp = msgData.TimeStamp; return; } //We've finished the interpolation so... _lerpPercentage = 0; Start.CopyFrom(Target); StartTimeStamp = EndTimeStamp; Target.mainThrottle = msgData.MainThrottle; Target.wheelThrottleTrim = msgData.WheelThrottleTrim; Target.X = msgData.X; Target.Y = msgData.Y; Target.Z = msgData.Z; Target.killRot = msgData.KillRot; Target.gearUp = msgData.GearUp; Target.gearDown = msgData.GearDown; Target.headlight = msgData.Headlight; Target.wheelThrottle = msgData.WheelThrottle; Target.roll = msgData.Roll; Target.yaw = msgData.Yaw; Target.pitch = msgData.Pitch; Target.rollTrim = msgData.RollTrim; Target.yawTrim = msgData.YawTrim; Target.pitchTrim = msgData.PitchTrim; Target.wheelSteer = msgData.WheelSteer; Target.wheelSteerTrim = msgData.WheelSteerTrim; EndTimeStamp = msgData.TimeStamp; }
private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { FlightCtrlState delayed = new FlightCtrlState(); // Keep the throttle on no connection if (this.KeepThrottleNoConnect == true) { delayed.mainThrottle = fcs.mainThrottle; } while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = mFlightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }
public void SendVesselUpdate() { var engines = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleEngines>(); var activeEngines = engines.Where(e => e.EngineIgnited).Select(e => e.part.craftID).ToArray(); var stoppedEngines = engines.Where(e => !e.EngineIgnited).Select(e => e.part.craftID).ToArray(); var decouplers = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDecouple>() .Where(e => !e.isDecoupled).Select(e => e.part.craftID).ToArray(); var anchoredDecouplers = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleAnchoredDecoupler>() .Where(e => !e.isDecoupled).Select(e => e.part.craftID).ToArray(); var clamps = FlightGlobals.ActiveVessel.FindPartModulesImplementing <LaunchClamp>().Select(e => e.part.craftID).ToArray(); var docks = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDockingNode>().Where(e => !e.IsDisabled).Select(e => e.part.craftID).ToArray(); var actionGrpControls = new[] { FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.Gear], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.Light], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.Brakes], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.SAS], FlightGlobals.ActiveVessel.ActionGroups[KSPActionGroup.RCS] }; var flightState = new FlightCtrlState(); flightState.CopyFrom(FlightGlobals.ActiveVessel.ctrlState); var msg = new VesselUpdateMsgData { Stage = FlightGlobals.ActiveVessel.currentStage, ActiveEngines = activeEngines, StoppedEngines = stoppedEngines, Decouplers = decouplers, AnchoredDecouplers = anchoredDecouplers, Clamps = clamps, Docks = docks, VesselId = FlightGlobals.ActiveVessel.id, ActiongroupControls = actionGrpControls, }; if (MsgIsDifferentThanLastMsgSent(msg)) { SendMessage(msg); LastMsgSent = msg; } }
private void PopFlightCtrlState(FlightCtrlState fcs) { FlightCtrlState delayed = mPreviousCtrl; // Pop any due flightctrlstates off the queue while (mFlightCtrlBuffer.Count > 0 && mFlightCtrlBuffer.Peek().TimeStamp < RTUtil.GetGameTime()) { delayed = mFlightCtrlBuffer.Dequeue().State; } if (!InputAllowed) { float keepThrottle = mPreviousCtrl.mainThrottle; delayed.Neutralize(); delayed.mainThrottle = keepThrottle; } fcs.CopyFrom(delayed); }
/// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary> /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param> /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param> private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { //TODO: `sat` parameter is never used. Check if is needed somewhere: if it's not, remove it. var delayed = new FlightCtrlState(); // Keep the throttle on no connection if (KeepThrottleNoConnect) { delayed.mainThrottle = fcs.mainThrottle; } while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = _flightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }
//retrieve the flight control state entered at a given time public void pop(FlightCtrlState controls, double time) { if (states.Count == 0 || states.Peek().ActTime > time) { setNeutral(controls); return; //returns neutral if no controls are entered or the entered controls are not within the signal delay } TimedCtrlState popState = states.Peek(); while (states.Peek().ActTime < time) { popState = states.Dequeue(); } controls.CopyFrom(popState.flightCtrlState); if (controls.killRot) // this overrides the delay in attitute control if SAS is activated. Thereby allowing SAS to make control changes without delay { controls.pitch = pitch; controls.roll = roll; controls.yaw = yaw; } }
/// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary> /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param> /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param> private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { var delayed = new FlightCtrlState(); delayed.mainThrottle = fcs.mainThrottle; if (!KeepThrottleNoConnect && !InputAllowed) // enforce the rule of shutting throttle down on connection loss { delayed.mainThrottle = 0f; } else if (KeepThrottleNoConnect && LockedThrottleNoConnect) // when connection is lost with the disabled rule of shutting throttle down, throttle is locked { delayed.mainThrottle = LockedThrottlePositionNoConnect; } while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = _flightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }
//retrieve the flight control state entered at a given time public void pop(FlightCtrlState controls, double time) { if (states.Count == 0 || states.Peek().ActTime > time) { setNeutral(controls); return; //returns neutral if no controls are entered or the entered controls are not within the signal delay } TimedCtrlState popState = states.Peek(); while (states.Peek().ActTime < time) { popState = states.Dequeue(); } controls.CopyFrom(popState.flightCtrlState); if (controls.killRot) // this overrides the delay in attitute control if SAS is activated. Thereby allowing SAS to make control changes without delay { controls.pitch = pitch; controls.roll = roll; controls.yaw = yaw; } }
private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { FlightCtrlState delayed = new FlightCtrlState(); while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = mFlightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }
public void OnFlyByWire(FlightCtrlState state) { // State may arrive with SAS or WASD controls pre-applied. Save it and reset pitch/yaw/roll so that it doesn't mess with input. FlightCtrlState preState = new FlightCtrlState(); preState.CopyFrom(state); if (AdvancedFlyByWire.Instance.m_IgnoreFlightCtrlState) { state.pitch = 0; state.yaw = 0; state.roll = 0; } // skill vessel input if we're in time-warp m_DisableVesselControls = TimeWarp.fetch != null && TimeWarp.fetch.current_rate_index != 0 && TimeWarp.fetch.Mode == TimeWarp.Modes.HIGH; m_Throttle.SetMinMaxValues(-state.mainThrottle, 1.0f - state.mainThrottle); m_WheelThrottle.SetMinMaxValues(-1.0f, 1.0f); foreach (ControllerConfiguration config in m_Configuration.controllers) { if (config.isEnabled) { config.iface.Update(state); UpdateAxes(config, state); if (FlightGlobals.ActiveVessel.isEVA) { EVAController.Instance.UpdateEVAFlightProperties(config, state); } CameraController.Instance.UpdateCameraProperties ( m_CameraPitch.Update(), m_CameraHeading.Update(), m_CameraZoom.Update(), config.cameraSensitivity ); } } UpdateFlightProperties(state); ZeroOutFlightProperties(); // Apply pre-state if not neutral and no AFBW input (including trim). if (!preState.isNeutral && AdvancedFlyByWire.Instance.m_IgnoreFlightCtrlState) { float t = controlDetectionThreshold; bool hasInput = Math.Abs(state.pitch) > t || Math.Abs(state.yaw) > t || Math.Abs(state.roll) > t; // hasInput will always be true if trim is active on any axis if (!hasInput) { state.pitch = preState.pitch; state.yaw = preState.yaw; state.roll = preState.roll; } } }
public void CopyFromVessel(Vessel updateVessel) { updateOK = true; SetVesselWorker(vesselWorker); try { vesselID = updateVessel.id; planetTime = Planetarium.GetUniversalTime(); bodyName = updateVessel.mainBody.bodyName; rotation[0] = updateVessel.srfRelRotation.x; rotation[1] = updateVessel.srfRelRotation.y; rotation[2] = updateVessel.srfRelRotation.z; rotation[3] = updateVessel.srfRelRotation.w; angularVelocity[0] = updateVessel.angularVelocity.x; angularVelocity[1] = updateVessel.angularVelocity.y; angularVelocity[2] = updateVessel.angularVelocity.z; //Flight state flightState.CopyFrom(updateVessel.ctrlState); actiongroupControls[0] = updateVessel.ActionGroups[KSPActionGroup.Gear]; actiongroupControls[1] = updateVessel.ActionGroups[KSPActionGroup.Light]; actiongroupControls[2] = updateVessel.ActionGroups[KSPActionGroup.Brakes]; actiongroupControls[3] = updateVessel.ActionGroups[KSPActionGroup.SAS]; actiongroupControls[4] = updateVessel.ActionGroups[KSPActionGroup.RCS]; if (updateVessel.altitude < 10000) { //Use surface position under 10k isSurfaceUpdate = true; position[0] = updateVessel.latitude; position[1] = updateVessel.longitude; position[2] = updateVessel.altitude; VesselUtil.DMPRaycastPair groundRaycast = VesselUtil.RaycastGround(updateVessel.latitude, updateVessel.longitude, updateVessel.mainBody); position[3] = groundRaycast.altitude; terrainNormal[0] = groundRaycast.terrainNormal.x; terrainNormal[1] = groundRaycast.terrainNormal.y; terrainNormal[2] = groundRaycast.terrainNormal.z; Vector3d srfVel = Quaternion.Inverse(updateVessel.mainBody.bodyTransform.rotation) * updateVessel.srf_velocity; velocity[0] = srfVel.x; velocity[1] = srfVel.y; velocity[2] = srfVel.z; Vector3d srfAcceleration = Quaternion.Inverse(updateVessel.mainBody.bodyTransform.rotation) * updateVessel.acceleration; acceleration[0] = srfAcceleration.x; acceleration[1] = srfAcceleration.y; acceleration[2] = srfAcceleration.z; } else { //Use orbital positioning over 10k isSurfaceUpdate = false; orbit[0] = updateVessel.orbit.inclination; orbit[1] = updateVessel.orbit.eccentricity; orbit[2] = updateVessel.orbit.semiMajorAxis; orbit[3] = updateVessel.orbit.LAN; orbit[4] = updateVessel.orbit.argumentOfPeriapsis; orbit[5] = updateVessel.orbit.meanAnomalyAtEpoch; orbit[6] = updateVessel.orbit.epoch; } sasEnabled = updateVessel.Autopilot.Enabled; if (sasEnabled) { autopilotMode = (int)updateVessel.Autopilot.Mode; lockedRotation[0] = updateVessel.Autopilot.SAS.lockedRotation.x; lockedRotation[1] = updateVessel.Autopilot.SAS.lockedRotation.y; lockedRotation[2] = updateVessel.Autopilot.SAS.lockedRotation.z; lockedRotation[3] = updateVessel.Autopilot.SAS.lockedRotation.w; } } catch (Exception e) { DarkLog.Debug("Failed to get vessel update, exception: " + e); updateOK = false; } }
/// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary> /// <param name="fcs">The <see cref="FlightCtrlState"/> to be removed from the queue.</param> /// <param name="sat">The satellite from which the <see cref="FlightCtrlState"/> should be removed.</param> private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { //TODO: `sat` parameter is never used. Check if is needed somewhere: if it's not, remove it. var delayed = new FlightCtrlState(); // Keep the throttle on no connection if(KeepThrottleNoConnect) { delayed.mainThrottle = fcs.mainThrottle; } while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = _flightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }
public DelayedFlightCtrlState(FlightCtrlState fcs) { State = new FlightCtrlState(); State.CopyFrom(fcs); TimeStamp = RTUtil.GameTime; }
private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat) { FlightCtrlState delayed = new FlightCtrlState(); // Keep the throttle on no connection if(this.KeepThrottleNoConnect == true) { delayed.mainThrottle = fcs.mainThrottle; } while (mFlightCtrlQueue.Count > 0 && mFlightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime) { delayed = mFlightCtrlQueue.Dequeue().State; } fcs.CopyFrom(delayed); }