Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for unstable ignition and burn time calculation #882

Merged
merged 23 commits into from Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
470c6e0
Merge remote-tracking branch 'MuMech/dev' into dev
Starwaster Sep 11, 2015
b8853fc
Merge remote-tracking branch 'refs/remotes/MuMech/dev' into dev
Starwaster Feb 25, 2016
6b086dd
Merge remote-tracking branch 'refs/remotes/MuMech/dev' into dev
Starwaster Aug 1, 2016
4259b8b
Fix issue bad 'wrong side' behavior
Starwaster Aug 15, 2016
24aefd1
Allow overriding of MANAGED (#796)
krisalyssa Oct 3, 2016
17711a4
Merge remote-tracking branch 'refs/remotes/MuMech/dev' into dev
Starwaster Oct 12, 2016
10b2910
Merge pull request #7 from MuMech/dev
Starwaster Oct 12, 2016
8574dec
Merge remote-tracking branch 'refs/remotes/MuMech/dev' into dev
Starwaster Oct 26, 2016
3f483e1
Reverted FixSpeed() changes
Starwaster Oct 28, 2016
9bc82bb
Revert "Reverted FixSpeed() changes"
Starwaster Oct 28, 2016
67d6a07
* Reverted earlier FixSpeed() changes
Starwaster Oct 28, 2016
8be594b
Tweaked 'wrong side' detection
Starwaster Oct 28, 2016
4a05e3e
Merge pull request #8 from MuMech/dev
Starwaster Nov 6, 2016
2c33615
Merge branch 'dev'
sarbian Dec 12, 2016
9d2dbed
let attitude control settle before autowarp (#847)
OliverPA77 Dec 31, 2016
20f88e2
Revert "let attitude control settle before autowarp" (#852)
sarbian Dec 31, 2016
6cda157
README.md points to re-created KSP forum thread (#859)
jimvanderveen Jan 24, 2017
7505872
Merge remote-tracking branch 'refs/remotes/MuMech/dev' into dev
Starwaster Apr 22, 2017
ca34d0b
Changes 'Limit throttle' setting to red if 0%
Starwaster Apr 23, 2017
f63352e
Fixes for unstable ignition / other limiters
Starwaster Apr 23, 2017
a386e4a
Merge remote-tracking branch 'refs/remotes/MuMech/master' into dev
Starwaster Apr 23, 2017
bca30ed
Revert "Merge remote-tracking branch 'refs/remotes/MuMech/master' int…
Starwaster Apr 24, 2017
bf477a9
re-commit of missing changes
Starwaster Apr 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 27 additions & 3 deletions MechJeb2/MechJebModuleNodeExecutor.cs
Expand Up @@ -36,6 +36,10 @@ public string NextNodeCountdown()
double dV = node.GetBurnVector(orbit).magnitude;
double halfBurnTIme;
double burnTIme = BurnTime(dV, out halfBurnTIme);
if (double.IsInfinity(halfBurnTIme))
{
halfBurnTIme = 0.0;
}
return GuiUtils.TimeToDHMS(node.UT - halfBurnTIme - vesselState.time);
}

Expand Down Expand Up @@ -124,8 +128,8 @@ public override void OnFixedUpdate()
double burnTime = BurnTime(dVLeft, out halfBurnTime);

double timeToNode = node.UT - vesselState.time;

if (halfBurnTime > 0 && timeToNode < halfBurnTime)
//(!double.IsInfinity(num) && num > 0.0 && num2 < num) || num2 <= 0.0
if ((!double.IsInfinity(halfBurnTime) && halfBurnTime > 0 && timeToNode < halfBurnTime) || timeToNode < 0)
{
burnTriggered = true;
if (!MuUtils.PhysicsRunning()) core.warp.MinimumWarp();
Expand Down Expand Up @@ -223,7 +227,27 @@ private double BurnTime(double dv, out double halfBurnTime)
// TODO: Be smarter about throttle limits on future stages.
if (i == stats.vacStats.Length - 1)
{
stageAvgAccel *= vesselState.throttleLimit;
if (this.core.thrust.limiter != MechJebModuleThrustController.LimitMode.UnstableIgnition)
{
stageAvgAccel *= (double)this.vesselState.throttleLimit;
}
else
{
double fLimitTemp = 1.0;
if (this.core.thrust.limitThrottle)
{
fLimitTemp = this.core.thrust.maxThrottle;
}
if (this.core.thrust.limitAcceleration)
{
fLimitTemp = Math.Min(fLimitTemp, this.core.thrust.maxAccelerationLimit);
}
if (this.core.thrust.limiterMinThrottle)
{
fLimitTemp = Math.Max(this.core.thrust.minThrottle, fLimitTemp);
}
stageAvgAccel *= fLimitTemp;
}
}

halfBurnTime += Math.Min(halfDvLeft, stageBurnDv) / stageAvgAccel;
Expand Down
13 changes: 9 additions & 4 deletions MechJeb2/MechJebModuleThrustController.cs
Expand Up @@ -113,6 +113,8 @@ public void LimitToPreventUnstableIgnitionInfoItem()
[Persistent(pass = (int)Pass.Global)]
public EditableDouble maxAcceleration = 40;

public double maxAccelerationLimit = 1;

[GeneralInfoItem("Limit acceleration", InfoItem.Category.Thrust)]
public void LimitAccelerationInfoItem()
{
Expand All @@ -136,7 +138,7 @@ public void LimitThrottleInfoItem()
{
GUILayout.BeginHorizontal();
GUIStyle s = new GUIStyle(GUI.skin.toggle);
if (limiter == LimitMode.Throttle) s.onHover.textColor = s.onNormal.textColor = Color.green;
if (limiter == LimitMode.Throttle) s.onHover.textColor = s.onNormal.textColor = maxThrottle > 0d ? Color.green : Color.red;
limitThrottle = GUILayout.Toggle(limitThrottle, "Limit throttle to", s, GUILayout.Width(110));
maxThrottle.text = GUILayout.TextField(maxThrottle.text, GUILayout.Width(30));
GUILayout.Label("%", GUILayout.ExpandWidth(false));
Expand Down Expand Up @@ -431,6 +433,8 @@ public override void Drive(FlightCtrlState s)
float limit = AccelerationLimitedThrottle();
if(limit < throttleLimit) limiter = LimitMode.Acceleration;
throttleLimit = Mathf.Min(throttleLimit, limit);
// to provide an externally facing value. (used when ignition is unstable so we can approximate throttle limit when ignition stablizes)
maxAccelerationLimit = throttleLimit;
}

if (electricThrottle && ElectricEngineRunning())
Expand Down Expand Up @@ -458,15 +462,16 @@ public override void Drive(FlightCtrlState s)
// RealFuels ullage integration. Stock always has stableUllage.
if (limitToPreventUnstableIgnition && !vesselState.stableUllage)
{
if (( targetThrottle > 0.0F || s.mainThrottle > 0.0F ) && throttleLimit > 0.0F ) {
if (( targetThrottle > 0.0F || s.mainThrottle > 0.0F ) && throttleLimit > 0.0F )
{
// We want to fire the throttle, and nothing else is limiting us, but we have unstable ullage
limiter = LimitMode.UnstableIgnition;
if (vessel.ActionGroups[KSPActionGroup.RCS] && s.Z == 0) {
// RCS is on, so use it to ullage
s.Z = -1.0F;
}
}
throttleLimit = 0.0F;
limiter = LimitMode.UnstableIgnition;
throttleLimit = 0.0F;
}

if (double.IsNaN(throttleLimit)) throttleLimit = 0;
Expand Down