public TMode PutIntoATCommandMode() { TMode Current = GetMode(); switch (Current) { case TMode.TRANSPARENT: return(PutIntoATCommandModeAssumingInTransparentMode()); case TMode.BOOTLOADER: int PrevBaud = _Port.BaudRate; _Port.BaudRate = BOOTLOADER_BAUD; WriteBootloaderCode(Uploader.Code.REBOOT); _Port.BaudRate = PrevBaud; _Mode = TMode.INIT; break; case TMode.BOOTLOADER_X: // boot Thread.Sleep(100); _Port.Write("\r\n"); Thread.Sleep(100); _Port.Write("BOOTNEW\r\n"); Thread.Sleep(100); _Mode = TMode.INIT; break; } return(GetMode()); }
/// <summary> /// Put into transparent mode. /// </summary> /// <returns></returns> public TMode PutIntoTransparentMode() { if (GetMode() == TMode.TRANSPARENT) { System.Diagnostics.Debug.WriteLine("Already in transparent mode"); return(TMode.TRANSPARENT); } else { if (PutIntoATCommandMode() == TMode.AT_COMMAND) { _Port.Write("\r\n"); Thread.Sleep(100); _Port.Write("ATO\r\n"); Thread.Sleep(100); if (WaitForToken("ATO\r\n", 100)) { System.Diagnostics.Debug.WriteLine("Put into transparent mode OK"); } else { System.Diagnostics.Debug.WriteLine("Failed to put into transparent mode"); } _Mode = TMode.TRANSPARENT; return(TMode.TRANSPARENT); } else { System.Diagnostics.Debug.WriteLine("Failed to put into AT cmd mode"); return(TMode.UNKNOWN); } } }
/// <summary> /// set dialog mode (combine, intersect or subtract) /// </summary> /// <param name="AMode"></param> public void SetMode(TFrmExtractCombineIntersectSubtractDialog.TMode AMode) { FMode = AMode; // hide field for base extract if not in subtraction mode if (FMode != TMode.ecisSubtractMode) { int ReducedHeight = txtBaseExtract.Height; txtBaseExtract.Height = 0; lblBaseExtract.Height = 0; txtBaseExtract.Hide(); lblBaseExtract.Hide(); pnlTop.Height = pnlTop.Height - ReducedHeight; lblExplanation.Location = new System.Drawing.Point(lblExplanation.Location.X, lblExplanation.Location.Y - ReducedHeight); } switch (FMode) { case TMode.ecisCombineMode: lblExplanation.Text = Catalog.GetString("Please add extracts to the list that you want to combine and then click OK:"); FindForm().Text = "Combine Extracts"; break; case TMode.ecisIntersectMode: lblExplanation.Text = Catalog.GetString("Please add extracts to the list that you want to intersect and then click OK:"); FindForm().Text = "Intersect Extracts"; break; case TMode.ecisSubtractMode: lblExplanation.Text = Catalog.GetString("Please add extracts to the list to be subtracted from the one above:"); FindForm().Text = "Subtract Extracts"; break; } }
public TMode GetMode() { if (_Mode == TMode.INIT) { _Mode = DetermineMode(); } return(_Mode); }
public void ThrustOff() { targetThrottle = 0; vessel.ctrlState.mainThrottle = 0; tmode = TMode.OFF; if (vessel == FlightGlobals.ActiveVessel) { FlightInputHandler.state.mainThrottle = 0; //so that the on-screen throttle gauge reflects the autopilot throttle } }
public void ThrustOff() { if (vessel == null || vessel.ctrlState == null) return; targetThrottle = 0; vessel.ctrlState.mainThrottle = 0; tmode = TMode.OFF; SetFlightGlobals(0); }
void CheckIfInBootloaderMode() { if (IsInBootloaderXMode()) { _Mode = TMode.BOOTLOADER_X; } else if (IsInBootloaderMode()) { _Mode = TMode.BOOTLOADER; } }
/// <summary> /// Assuming in transparent mode, try to put it into AT command mode. /// If fails, determine mode and then try again. /// </summary> public TMode PutIntoATCommandModeAssumingInTransparentMode() { _Port.ReadTimeout = 2000; //Console.WriteLine("Waiting 1500ms"); Thread.Sleep(1500); _Port.DiscardInBuffer(); //Console.WriteLine("Sending +++"); _Port.Write("+++"); //Console.WriteLine("Waiting up to 3s for OK"); if (WaitForToken("OK\r\n", 3000)) { _Mode = TMode.AT_COMMAND; return(TMode.AT_COMMAND); } _Mode = TMode.INIT; return(PutIntoATCommandMode()); }
/// <summary> /// /Add constructor logic here /// </summary> /// <param name="enMode"></param> public clsRtf2Html(TMode enMode) { Debug.Assert(enMode==TMode.c_modRTF2HTML); //vice versa unsupported at the moment m_enMode = enMode; m_RTFTree = new CRTFNode(); SetTitle = "RTF2HTML Generated Document"; m_arrColors=new ArrayList(); //Color[] m_arrHTMLElements=new ArrayList(); //CHTMLElement[] m_mapFontNames=new ArrayList(); //CMapStringToString[] m_RTFTree=new CRTFNode(); m_strName=string.Empty; m_strCode=string.Empty; m_strThisCode=string.Empty; m_strPlain=string.Empty; m_strLang=string.Empty; ResetMetaData(); }
public void AssumeMode(TMode Mode) { _Mode = Mode; }
public override void Drive(FlightCtrlState s) { //detect user input: if (s.mainThrottle < 1e-4 && lastThrottle > 1e-4) { targetThrottle = 0; //detect player pressing 'x' } else if (Mathf.Abs(s.mainThrottle - lastThrottle) > 1e-4) { targetThrottle = Mathf.Clamp01((s.mainThrottle - lastThrottle) + targetThrottle); } if ((tmode != TMode.OFF) && (vesselState.thrustAvailable > 0)) { double spd = 0; switch (tmode) { case TMode.KEEP_ORBITAL: spd = vesselState.speedOrbital; break; case TMode.KEEP_SURFACE: spd = vesselState.speedSurface; break; case TMode.KEEP_VERTICAL: spd = vesselState.speedVertical; Vector3d rot = Vector3d.up; if (trans_kill_h) { Vector3 hsdir = Vector3.Exclude(vesselState.up, vesselState.velocityVesselSurface); Vector3 dir = -hsdir + vesselState.up * Math.Max(Math.Abs(spd), 20 * mainBody.GeeASL); if ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) > 5000) && (hsdir.magnitude > Math.Max(Math.Abs(spd), 100 * mainBody.GeeASL) * 2)) { tmode = TMode.DIRECT; trans_spd_act = 100; rot = -hsdir; } else { rot = dir.normalized; } core.attitude.attitudeTo(rot, AttitudeReference.INERTIAL, null); } break; } double t_err = (trans_spd_act - spd) / vesselState.maxThrustAccel; if ((tmode == TMode.KEEP_ORBITAL && Vector3d.Dot(vesselState.forward, vesselState.velocityVesselOrbit) < 0) || (tmode == TMode.KEEP_SURFACE && Vector3d.Dot(vesselState.forward, vesselState.velocityVesselSurface) < 0)) { //allow thrust to declerate t_err *= -1; } double t_act = pid.Compute(t_err); if ((tmode != TMode.KEEP_VERTICAL) || !trans_kill_h || (core.attitude.attitudeError < 2) || ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) < 1000) && (core.attitude.attitudeError < 90))) { if (tmode == TMode.DIRECT) { trans_prev_thrust = targetThrottle = trans_spd_act / 100.0F; } else { trans_prev_thrust = targetThrottle = Mathf.Clamp01(trans_prev_thrust + (float)t_act); } } else { if ((core.attitude.attitudeError >= 2) && (vesselState.torqueThrustPYAvailable > Math.Min( vesselState.torqueAvailable.x, vesselState.torqueAvailable.z) * 10)) { trans_prev_thrust = targetThrottle = 0.1F; } else { trans_prev_thrust = targetThrottle = 0; } } } s.mainThrottle = targetThrottle; float throttleLimit = 1; limiter = LimitMode.None; if (limitThrottle) { if (maxThrottle < throttleLimit) limiter = LimitMode.Throttle; throttleLimit = Mathf.Min(throttleLimit, (float)maxThrottle); } if (limitToTerminalVelocity) { float limit = TerminalVelocityThrottle(); if (limit < throttleLimit) limiter = LimitMode.TerminalVelocity; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventOverheats) { float limit = TemperatureSafetyThrottle(); if(limit < throttleLimit) limiter = LimitMode.Temperature; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitAcceleration) { float limit = AccelerationLimitedThrottle(); if(limit < throttleLimit) limiter = LimitMode.Acceleration; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventFlameout) { // This clause benefits being last: if we don't need much air // due to prior limits, we can close some intakes. float limit = FlameoutSafetyThrottle(); if (limit < throttleLimit) limiter = LimitMode.Flameout; throttleLimit = Mathf.Min(throttleLimit, limit); } if (double.IsNaN(throttleLimit)) throttleLimit = 0; throttleLimit = Mathf.Clamp01(throttleLimit); vesselState.throttleLimit = throttleLimit; if (s.mainThrottle < throttleLimit) limiter = LimitMode.None; s.mainThrottle = Mathf.Min(s.mainThrottle, throttleLimit); if (smoothThrottle) { s.mainThrottle = SmoothThrottle(s.mainThrottle); } if (double.IsNaN(s.mainThrottle)) s.mainThrottle = 0; s.mainThrottle = Mathf.Clamp01(s.mainThrottle); lastThrottle = s.mainThrottle; }
public object Convert(object Value, Type TargetType, object Parameter, CultureInfo Culture) { TMode Mode = (TMode)Value; string Name = Parameter.ToString(); if (Mode == TMode.Qrr) { switch (Name) { case "TrrMeasureBy9050Method": return(Visibility.Visible); case "OffStateVoltage": return(Visibility.Collapsed); case "OsvRate": return(Visibility.Collapsed); case "Tq": return(Visibility.Collapsed); //видны case "Qrr": return(Visibility.Visible); case "Irr": return(Visibility.Visible); case "Trr": return(Visibility.Visible); default: return(Visibility.Visible); } } else { if (Mode == TMode.QrrTq) { switch (Name) { case "TrrMeasureBy9050Method": return(Visibility.Collapsed); case "OffStateVoltage": return(Visibility.Visible); case "OsvRate": return(Visibility.Visible); case "Tq": return(Visibility.Visible); //скрыты case "Qrr": return(Visibility.Collapsed); case "Irr": return(Visibility.Collapsed); case "Trr": return(Visibility.Collapsed); default: return(Visibility.Visible); } } else { return(Visibility.Visible); } } }
public override void Drive(FlightCtrlState s) { float threshold = 0.1F; bool _userCommandingRotation = !(Mathfx.Approx(s.pitch, s.pitchTrim, threshold) && Mathfx.Approx(s.yaw, s.yawTrim, threshold) && Mathfx.Approx(s.roll, s.rollTrim, threshold)); bool _userCommandingTranslation = !(Math.Abs(s.X) < threshold && Math.Abs(s.Y) < threshold && Math.Abs(s.Z) < threshold); if (_userCommandingRotation && !_userCommandingTranslation) { userCommandingRotationSmoothed = 2; } else if (userCommandingRotationSmoothed > 0) { userCommandingRotationSmoothed--; } if (core.GetComputerModule<MechJebModuleThrustWindow>().hidden && core.GetComputerModule<MechJebModuleAscentGuidance>().hidden) { return; } if ((tmode != TMode.OFF) && (vesselState.thrustAvailable > 0)) { double spd = 0; switch (tmode) { case TMode.KEEP_ORBITAL: spd = vesselState.speedOrbital; break; case TMode.KEEP_SURFACE: spd = vesselState.speedSurface; break; case TMode.KEEP_VERTICAL: spd = vesselState.speedVertical; Vector3d rot = Vector3d.up; if (trans_kill_h) { Vector3 hsdir = Vector3.ProjectOnPlane(vesselState.surfaceVelocity, vesselState.up); Vector3 dir = -hsdir + vesselState.up * Math.Max(Math.Abs(spd), 20 * mainBody.GeeASL); if ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) > 5000) && (hsdir.magnitude > Math.Max(Math.Abs(spd), 100 * mainBody.GeeASL) * 2)) { tmode = TMode.DIRECT; trans_spd_act = 100; rot = -hsdir; } else { rot = dir.normalized; } core.attitude.attitudeTo(rot, AttitudeReference.INERTIAL, null); } break; } double t_err = (trans_spd_act - spd) / vesselState.maxThrustAccel; if ((tmode == TMode.KEEP_ORBITAL && Vector3d.Dot(vesselState.forward, vesselState.orbitalVelocity) < 0) || (tmode == TMode.KEEP_SURFACE && Vector3d.Dot(vesselState.forward, vesselState.surfaceVelocity) < 0)) { //allow thrust to declerate t_err *= -1; } double t_act = pid.Compute(t_err); if ((tmode != TMode.KEEP_VERTICAL) || !trans_kill_h || (core.attitude.attitudeError < 2) || ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) < 1000) && (core.attitude.attitudeError < 90))) { if (tmode == TMode.DIRECT) { trans_prev_thrust = targetThrottle = trans_spd_act / 100.0F; } else { trans_prev_thrust = targetThrottle = Mathf.Clamp01(trans_prev_thrust + (float)t_act); } } else { bool useGimbal = (vesselState.torqueFromEngine.x / vessel.ctrlState.mainThrottle > vesselState.torqueAvailable.x * 10) || (vesselState.torqueFromEngine.z / vessel.ctrlState.mainThrottle > vesselState.torqueAvailable.z * 10); bool useDiffThrottle = (vesselState.torqueFromDiffThrottle.x > vesselState.torqueAvailable.x * 10) || (vesselState.torqueFromDiffThrottle.z > vesselState.torqueAvailable.z * 10); if ((core.attitude.attitudeError >= 2) && (useGimbal || (useDiffThrottle && core.thrust.differentialThrottle))) { trans_prev_thrust = targetThrottle = 0.1F; } else { trans_prev_thrust = targetThrottle = 0; } } } // Only set throttle if a module need it. Othewise let the user or other mods set it // There is always at least 1 user : the module itself (why ?) if (users.Count() > 1) s.mainThrottle = targetThrottle; float throttleLimit = 1; limiter = LimitMode.None; if (limitThrottle) { if (maxThrottle < throttleLimit) limiter = LimitMode.Throttle; throttleLimit = Mathf.Min(throttleLimit, (float)maxThrottle); } if (limitToTerminalVelocity) { float limit = TerminalVelocityThrottle(); if (limit < throttleLimit) limiter = LimitMode.TerminalVelocity; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitDynamicPressure) { float limit = MaximumDynamicPressureThrottle(); if (limit < throttleLimit) limiter = LimitMode.DynamicPressure; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventOverheats) { float limit = (float)TemperatureSafetyThrottle(); if(limit < throttleLimit) limiter = LimitMode.Temperature; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitAcceleration) { float limit = AccelerationLimitedThrottle(); if(limit < throttleLimit) limiter = LimitMode.Acceleration; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventFlameout) { // This clause benefits being last: if we don't need much air // due to prior limits, we can close some intakes. float limit = FlameoutSafetyThrottle(); if (limit < throttleLimit) limiter = LimitMode.Flameout; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limiterMinThrottle && limiter != LimitMode.None && throttleLimit < minThrottle) { limiter = LimitMode.MinThrottle; throttleLimit = (float) minThrottle; } if (double.IsNaN(throttleLimit)) throttleLimit = 0; throttleLimit = Mathf.Clamp01(throttleLimit); vesselState.throttleLimit = throttleLimit; if (s.mainThrottle < throttleLimit) limiter = LimitMode.None; s.mainThrottle = Mathf.Min(s.mainThrottle, throttleLimit); if (smoothThrottle) { s.mainThrottle = SmoothThrottle(s.mainThrottle); } if (double.IsNaN(s.mainThrottle)) s.mainThrottle = 0; s.mainThrottle = Mathf.Clamp01(s.mainThrottle); if (s.Z == 0 && core.rcs.rcsThrottle && vesselState.rcsThrust) s.Z = -s.mainThrottle; lastThrottle = s.mainThrottle; if (!core.attitude.enabled) { Vector3d act = new Vector3d(s.pitch, s.yaw, s.roll); differentialThrottleDemandedTorque = -Vector3d.Scale(act.xzy, vesselState.torqueFromDiffThrottle * s.mainThrottle * 0.5f); } }
public void ThrustOff() { targetThrottle = 0; vessel.ctrlState.mainThrottle = 0; tmode = TMode.OFF; }
public override void Drive(FlightCtrlState s) { if (core.GetComputerModule <MechJebModuleThrustWindow>().hidden&& core.GetComputerModule <MechJebModuleAscentGuidance>().hidden) { return; } if ((tmode != TMode.OFF) && (vesselState.thrustAvailable > 0)) { double spd = 0; switch (tmode) { case TMode.KEEP_ORBITAL: spd = vesselState.speedOrbital; break; case TMode.KEEP_SURFACE: spd = vesselState.speedSurface; break; case TMode.KEEP_VERTICAL: spd = vesselState.speedVertical; Vector3d rot = Vector3d.up; if (trans_kill_h) { Vector3 hsdir = Vector3.Exclude(vesselState.up, vessel.srf_velocity); Vector3 dir = -hsdir + vesselState.up * Math.Max(Math.Abs(spd), 20 * mainBody.GeeASL); if ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) > 5000) && (hsdir.magnitude > Math.Max(Math.Abs(spd), 100 * mainBody.GeeASL) * 2)) { tmode = TMode.DIRECT; trans_spd_act = 100; rot = -hsdir; } else { rot = dir.normalized; } core.attitude.attitudeTo(rot, AttitudeReference.INERTIAL, null); } break; } double t_err = (trans_spd_act - spd) / vesselState.maxThrustAccel; if ((tmode == TMode.KEEP_ORBITAL && Vector3d.Dot(vesselState.forward, vessel.obt_velocity) < 0) || (tmode == TMode.KEEP_SURFACE && Vector3d.Dot(vesselState.forward, vessel.srf_velocity) < 0)) { //allow thrust to declerate t_err *= -1; } double t_act = pid.Compute(t_err); if ((tmode != TMode.KEEP_VERTICAL) || !trans_kill_h || (core.attitude.attitudeError < 2) || ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) < 1000) && (core.attitude.attitudeError < 90))) { if (tmode == TMode.DIRECT) { trans_prev_thrust = targetThrottle = trans_spd_act / 100.0F; } else { trans_prev_thrust = targetThrottle = Mathf.Clamp01(trans_prev_thrust + (float)t_act); } } else { if ((core.attitude.attitudeError >= 2) && (vesselState.torqueThrustPYAvailable > Math.Min(vesselState.torqueAvailable.x, vesselState.torqueAvailable.z) * 10)) { trans_prev_thrust = targetThrottle = 0.1F; } else { trans_prev_thrust = targetThrottle = 0; } } } // Only set throttle if a module need it. Othewise let the user or other mods set it // There is always at least 1 user : the module itself (why ?) if (users.Count() > 1) { s.mainThrottle = targetThrottle; } float throttleLimit = 1; limiter = LimitMode.None; if (limitThrottle) { if (maxThrottle < throttleLimit) { limiter = LimitMode.Throttle; } throttleLimit = Mathf.Min(throttleLimit, (float)maxThrottle); } if (limitToTerminalVelocity) { float limit = TerminalVelocityThrottle(); if (limit < throttleLimit) { limiter = LimitMode.TerminalVelocity; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventOverheats) { float limit = TemperatureSafetyThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Temperature; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitAcceleration) { float limit = AccelerationLimitedThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Acceleration; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventFlameout) { // This clause benefits being last: if we don't need much air // due to prior limits, we can close some intakes. float limit = FlameoutSafetyThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Flameout; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (double.IsNaN(throttleLimit)) { throttleLimit = 0; } throttleLimit = Mathf.Clamp01(throttleLimit); vesselState.throttleLimit = throttleLimit; if (s.mainThrottle < throttleLimit) { limiter = LimitMode.None; } s.mainThrottle = Mathf.Min(s.mainThrottle, throttleLimit); if (smoothThrottle) { s.mainThrottle = SmoothThrottle(s.mainThrottle); } if (double.IsNaN(s.mainThrottle)) { s.mainThrottle = 0; } s.mainThrottle = Mathf.Clamp01(s.mainThrottle); if (s.Z == 0 && vesselState.rcsThrust) { s.Z = -s.mainThrottle; } lastThrottle = s.mainThrottle; }
public override void Drive(FlightCtrlState s) { //detect user input: if (s.mainThrottle < 1e-4 && lastThrottle > 1e-4) { targetThrottle = 0; //detect player pressing 'x' } else if (Mathf.Abs(s.mainThrottle - lastThrottle) > 1e-4) { targetThrottle = Mathf.Clamp01((s.mainThrottle - lastThrottle) + targetThrottle); } if ((tmode != TMode.OFF) && (vesselState.thrustAvailable > 0)) { double spd = 0; switch (tmode) { case TMode.KEEP_ORBITAL: spd = vesselState.speedOrbital; break; case TMode.KEEP_SURFACE: spd = vesselState.speedSurface; break; case TMode.KEEP_VERTICAL: spd = vesselState.speedVertical; Vector3d rot = Vector3d.up; if (trans_kill_h) { Vector3 hsdir = Vector3.Exclude(vesselState.up, vesselState.velocityVesselSurface); Vector3 dir = -hsdir + vesselState.up * Math.Max(Math.Abs(spd), 20 * mainBody.GeeASL); if ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) > 5000) && (hsdir.magnitude > Math.Max(Math.Abs(spd), 100 * mainBody.GeeASL) * 2)) { tmode = TMode.DIRECT; trans_spd_act = 100; rot = -hsdir; } else { rot = dir.normalized; } core.attitude.attitudeTo(rot, AttitudeReference.INERTIAL, null); } break; } double t_err = (trans_spd_act - spd) / vesselState.maxThrustAccel; if ((tmode == TMode.KEEP_ORBITAL && Vector3d.Dot(vesselState.forward, vesselState.velocityVesselOrbit) < 0) || (tmode == TMode.KEEP_SURFACE && Vector3d.Dot(vesselState.forward, vesselState.velocityVesselSurface) < 0)) { //allow thrust to declerate t_err *= -1; } double t_act = pid.Compute(t_err); if ((tmode != TMode.KEEP_VERTICAL) || !trans_kill_h || (core.attitude.attitudeError < 2) || ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) < 1000) && (core.attitude.attitudeError < 90))) { if (tmode == TMode.DIRECT) { trans_prev_thrust = targetThrottle = trans_spd_act / 100.0F; } else { trans_prev_thrust = targetThrottle = Mathf.Clamp01(trans_prev_thrust + (float)t_act); } } else { if ((core.attitude.attitudeError >= 2) && (vesselState.torqueThrustPYAvailable > vesselState.torquePYAvailable * 10)) { trans_prev_thrust = targetThrottle = 0.1F; } else { trans_prev_thrust = targetThrottle = 0; } } } s.mainThrottle = targetThrottle; float throttleLimit = 1; limiter = LimitMode.None; if (limitThrottle) { if (maxThrottle < throttleLimit) { limiter = LimitMode.Throttle; } throttleLimit = Mathf.Min(throttleLimit, (float)maxThrottle); } if (limitToTerminalVelocity) { float limit = TerminalVelocityThrottle(); if (limit < throttleLimit) { limiter = LimitMode.TerminalVelocity; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventOverheats) { float limit = TemperatureSafetyThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Temperature; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitAcceleration) { float limit = AccelerationLimitedThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Acceleration; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventFlameout) { // This clause benefits being last: if we don't need much air // due to prior limits, we can close some intakes. float limit = FlameoutSafetyThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Flameout; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (double.IsNaN(throttleLimit)) { throttleLimit = 0; } throttleLimit = Mathf.Clamp01(throttleLimit); vesselState.throttleLimit = throttleLimit; if (s.mainThrottle < throttleLimit) { limiter = LimitMode.None; } s.mainThrottle = Mathf.Min(s.mainThrottle, throttleLimit); if (smoothThrottle) { s.mainThrottle = SmoothThrottle(s.mainThrottle); } if (double.IsNaN(s.mainThrottle)) { s.mainThrottle = 0; } s.mainThrottle = Mathf.Clamp01(s.mainThrottle); lastThrottle = s.mainThrottle; }
public override void Drive(FlightCtrlState s) { float threshold = 0.1F; bool _userCommandingRotation = !(Mathfx.Approx(s.pitch, s.pitchTrim, threshold) && Mathfx.Approx(s.yaw, s.yawTrim, threshold) && Mathfx.Approx(s.roll, s.rollTrim, threshold)); bool _userCommandingTranslation = !(Math.Abs(s.X) < threshold && Math.Abs(s.Y) < threshold && Math.Abs(s.Z) < threshold); if (_userCommandingRotation && !_userCommandingTranslation) { userCommandingRotationSmoothed = 2; } else if (userCommandingRotationSmoothed > 0) { userCommandingRotationSmoothed--; } if (core.GetComputerModule <MechJebModuleThrustWindow>().hidden&& core.GetComputerModule <MechJebModuleAscentGuidance>().hidden) { return; } if ((tmode != TMode.OFF) && (vesselState.thrustAvailable > 0)) { double spd = 0; switch (tmode) { case TMode.KEEP_ORBITAL: spd = vesselState.speedOrbital; break; case TMode.KEEP_SURFACE: spd = vesselState.speedSurface; break; case TMode.KEEP_VERTICAL: spd = vesselState.speedVertical; Vector3d rot = Vector3d.up; if (trans_kill_h) { Vector3 hsdir = Vector3.ProjectOnPlane(vesselState.surfaceVelocity, vesselState.up); Vector3 dir = -hsdir + vesselState.up * Math.Max(Math.Abs(spd), 20 * mainBody.GeeASL); if ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) > 5000) && (hsdir.magnitude > Math.Max(Math.Abs(spd), 100 * mainBody.GeeASL) * 2)) { tmode = TMode.DIRECT; trans_spd_act = 100; rot = -hsdir; } else { rot = dir.normalized; } core.attitude.attitudeTo(rot, AttitudeReference.INERTIAL, null); } break; } double t_err = (trans_spd_act - spd) / vesselState.maxThrustAccel; if ((tmode == TMode.KEEP_ORBITAL && Vector3d.Dot(vesselState.forward, vesselState.orbitalVelocity) < 0) || (tmode == TMode.KEEP_SURFACE && Vector3d.Dot(vesselState.forward, vesselState.surfaceVelocity) < 0)) { //allow thrust to declerate t_err *= -1; } double t_act = pid.Compute(t_err); if ((tmode != TMode.KEEP_VERTICAL) || !trans_kill_h || (core.attitude.attitudeError < 2) || ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) < 1000) && (core.attitude.attitudeError < 90))) { if (tmode == TMode.DIRECT) { trans_prev_thrust = targetThrottle = trans_spd_act / 100.0F; } else { trans_prev_thrust = targetThrottle = Mathf.Clamp01(trans_prev_thrust + (float)t_act); } } else { bool useGimbal = (vesselState.torqueFromEngine.x / vessel.ctrlState.mainThrottle > vesselState.torqueAvailable.x * 10) || (vesselState.torqueFromEngine.z / vessel.ctrlState.mainThrottle > vesselState.torqueAvailable.z * 10); bool useDiffThrottle = (vesselState.torqueFromDiffThrottle.x > vesselState.torqueAvailable.x * 10) || (vesselState.torqueFromDiffThrottle.z > vesselState.torqueAvailable.z * 10); if ((core.attitude.attitudeError >= 2) && (useGimbal || (useDiffThrottle && core.thrust.differentialThrottle))) { trans_prev_thrust = targetThrottle = 0.1F; } else { trans_prev_thrust = targetThrottle = 0; } } } // Only set throttle if a module need it. Othewise let the user or other mods set it // There is always at least 1 user : the module itself (why ?) if (users.Count() > 1) { s.mainThrottle = targetThrottle; } float throttleLimit = 1; limiter = LimitMode.None; if (limitThrottle) { if (maxThrottle < throttleLimit) { limiter = LimitMode.Throttle; } throttleLimit = Mathf.Min(throttleLimit, (float)maxThrottle); } if (limitToTerminalVelocity) { float limit = TerminalVelocityThrottle(); if (limit < throttleLimit) { limiter = LimitMode.TerminalVelocity; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitDynamicPressure) { float limit = MaximumDynamicPressureThrottle(); if (limit < throttleLimit) { limiter = LimitMode.DynamicPressure; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventOverheats) { float limit = (float)TemperatureSafetyThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Temperature; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitAcceleration) { float limit = AccelerationLimitedThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Acceleration; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (electricThrottle && ElectricEngineRunning()) { float limit = ElectricThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Electric; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventFlameout) { // This clause benefits being last: if we don't need much air // due to prior limits, we can close some intakes. float limit = FlameoutSafetyThrottle(); if (limit < throttleLimit) { limiter = LimitMode.Flameout; } throttleLimit = Mathf.Min(throttleLimit, limit); } if (limiterMinThrottle && limiter != LimitMode.None && throttleLimit < minThrottle) { limiter = LimitMode.MinThrottle; throttleLimit = (float)minThrottle; } if (double.IsNaN(throttleLimit)) { throttleLimit = 0; } throttleLimit = Mathf.Clamp01(throttleLimit); vesselState.throttleLimit = throttleLimit; if (s.mainThrottle < throttleLimit) { limiter = LimitMode.None; } s.mainThrottle = Mathf.Min(s.mainThrottle, throttleLimit); if (smoothThrottle) { s.mainThrottle = SmoothThrottle(s.mainThrottle); } if (double.IsNaN(s.mainThrottle)) { s.mainThrottle = 0; } s.mainThrottle = Mathf.Clamp01(s.mainThrottle); if (s.Z == 0 && core.rcs.rcsThrottle && vesselState.rcsThrust) { s.Z = -s.mainThrottle; } lastThrottle = s.mainThrottle; if (!core.attitude.enabled) { Vector3d act = new Vector3d(s.pitch, s.yaw, s.roll); differentialThrottleDemandedTorque = -Vector3d.Scale(act.xzy, vesselState.torqueFromDiffThrottle * s.mainThrottle * 0.5f); } }
public override void Drive(FlightCtrlState s) { if (core.GetComputerModule<MechJebModuleThrustWindow>().hidden && core.GetComputerModule<MechJebModuleAscentGuidance>().hidden) { return; } if ((tmode != TMode.OFF) && (vesselState.thrustAvailable > 0)) { double spd = 0; switch (tmode) { case TMode.KEEP_ORBITAL: spd = vesselState.speedOrbital; break; case TMode.KEEP_SURFACE: spd = vesselState.speedSurface; break; case TMode.KEEP_VERTICAL: spd = vesselState.speedVertical; Vector3d rot = Vector3d.up; if (trans_kill_h) { Vector3 hsdir = Vector3.Exclude(vesselState.up, vessel.srf_velocity); Vector3 dir = -hsdir + vesselState.up * Math.Max(Math.Abs(spd), 20 * mainBody.GeeASL); if ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) > 5000) && (hsdir.magnitude > Math.Max(Math.Abs(spd), 100 * mainBody.GeeASL) * 2)) { tmode = TMode.DIRECT; trans_spd_act = 100; rot = -hsdir; } else { rot = dir.normalized; } core.attitude.attitudeTo(rot, AttitudeReference.INERTIAL, null); } break; } double t_err = (trans_spd_act - spd) / vesselState.maxThrustAccel; if ((tmode == TMode.KEEP_ORBITAL && Vector3d.Dot(vesselState.forward, vessel.obt_velocity) < 0) || (tmode == TMode.KEEP_SURFACE && Vector3d.Dot(vesselState.forward, vessel.srf_velocity) < 0)) { //allow thrust to declerate t_err *= -1; } double t_act = pid.Compute(t_err); if ((tmode != TMode.KEEP_VERTICAL) || !trans_kill_h || (core.attitude.attitudeError < 2) || ((Math.Min(vesselState.altitudeASL, vesselState.altitudeTrue) < 1000) && (core.attitude.attitudeError < 90))) { if (tmode == TMode.DIRECT) { trans_prev_thrust = targetThrottle = trans_spd_act / 100.0F; } else { trans_prev_thrust = targetThrottle = Mathf.Clamp01(trans_prev_thrust + (float)t_act); } } else { if ((core.attitude.attitudeError >= 2) && (vesselState.torqueThrustPYAvailable > Math.Min( vesselState.torqueAvailable.x, vesselState.torqueAvailable.z) * 10)) { trans_prev_thrust = targetThrottle = 0.1F; } else { trans_prev_thrust = targetThrottle = 0; } } } // Only set throttle if a module need it. Othewise let the user or other mods set it // There is always at least 1 user : the module itself (why ?) if (users.Count() > 1) s.mainThrottle = targetThrottle; float throttleLimit = 1; limiter = LimitMode.None; if (limitThrottle) { if (maxThrottle < throttleLimit) limiter = LimitMode.Throttle; throttleLimit = Mathf.Min(throttleLimit, (float)maxThrottle); } if (limitToTerminalVelocity) { float limit = TerminalVelocityThrottle(); if (limit < throttleLimit) limiter = LimitMode.TerminalVelocity; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventOverheats) { float limit = TemperatureSafetyThrottle(); if(limit < throttleLimit) limiter = LimitMode.Temperature; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitAcceleration) { float limit = AccelerationLimitedThrottle(); if(limit < throttleLimit) limiter = LimitMode.Acceleration; throttleLimit = Mathf.Min(throttleLimit, limit); } if (limitToPreventFlameout) { // This clause benefits being last: if we don't need much air // due to prior limits, we can close some intakes. float limit = FlameoutSafetyThrottle(); if (limit < throttleLimit) limiter = LimitMode.Flameout; throttleLimit = Mathf.Min(throttleLimit, limit); } if (double.IsNaN(throttleLimit)) throttleLimit = 0; throttleLimit = Mathf.Clamp01(throttleLimit); vesselState.throttleLimit = throttleLimit; if (s.mainThrottle < throttleLimit) limiter = LimitMode.None; s.mainThrottle = Mathf.Min(s.mainThrottle, throttleLimit); if (smoothThrottle) { s.mainThrottle = SmoothThrottle(s.mainThrottle); } if (double.IsNaN(s.mainThrottle)) s.mainThrottle = 0; s.mainThrottle = Mathf.Clamp01(s.mainThrottle); if (s.Z == 0 && vesselState.rcsThrust) s.Z = -s.mainThrottle; lastThrottle = s.mainThrottle; }
public bool thrustActivate(ComputerModule controller, float value, TMode mode) { /* if ((controlModule != null) && (controller != null) && (controlModule != controller)) { return false; } */ trans_spd_act = value; tmode = mode; return true; }