Skip to content

Commit

Permalink
Merge pull request #250 from KSP-RO/feature/thrustModifier
Browse files Browse the repository at this point in the history
Scale engine runtime by commanded thrust
  • Loading branch information
jwvanderbeck authored Aug 2, 2022
2 parents f7d0349 + eefba89 commit 61a515e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
19 changes: 19 additions & 0 deletions TestFlightAPI/TestFlightAPI/EngineModuleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ public float requestedThrust
}
}

public float commandedThrust
{
get
{
if (engineType == EngineModuleType.UNKNOWN)
return 0f;
// current thrust / maxThrust * vac_Isp / current_Isp / ispMult / flowMult
// var currentThrust = moduleEngine.finalThrust;
// var maxThrust = moduleEngine.maxThrust;
// var vac_Isp = moduleEngine.atmCurveIsp.Evaluate(0f);
// var current_Isp = moduleEngine.realIsp;
// var ispMult = moduleEngine.multIsp;
// var flowMult = moduleEngine.flowMultiplier;

return moduleEngine.finalThrust / moduleEngine.maxThrust * moduleEngine.atmCurveIsp.Evaluate(0f) /
moduleEngine.realIsp / moduleEngine.multIsp / moduleEngine.flowMultiplier;
}
}

public float finalThrust
{
get
Expand Down
20 changes: 17 additions & 3 deletions TestFlightReliability_EngineCycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public class TestFlightReliability_EngineCycle : TestFlightReliabilityBase
/// </summary>
[KSPField]
public float ratedBurnTime = 0f;


/// <summary>
/// Multiplier to how much time is added to the engine's runTime based on set throttle position
/// </summary>
[KSPField]
public FloatCurve thrustModifier = null;

/// <summary>
/// maximum rated continuous burn time between restarts
/// </summary>
Expand Down Expand Up @@ -94,8 +100,10 @@ protected void UpdateCycle()
// engine is running

// increase both continuous and cumulative run times
currentRunTime += deltaTime; // continuous
engineOperatingTime += deltaTime; // cumulative
// add burn time based on time passed, optionally modified by the thrust
float actualThrustModifier = thrustModifier.Evaluate(engine.commandedThrust);
currentRunTime += deltaTime * actualThrustModifier; // continuous
engineOperatingTime += deltaTime * actualThrustModifier; // cumulative


// calculate total failure rate modifier
Expand Down Expand Up @@ -278,6 +286,12 @@ public override void OnAwake()
continuousCycle.Add(0f, 1f);
}

if (thrustModifier == null)
{
thrustModifier = new FloatCurve();
thrustModifier.Add(0f, 1f);
}

}

public override List<string> GetTestFlightInfo(float reliabilityAtTime)
Expand Down

0 comments on commit 61a515e

Please sign in to comment.