Skip to content

Commit

Permalink
Fix an RCS bug
Browse files Browse the repository at this point in the history
burntime and propellant counts were getting double-counted.

debug logging was also excessive.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Aug 4, 2023
1 parent 45710d6 commit 6c988a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
16 changes: 3 additions & 13 deletions MechJeb2/MechJebLib/Simulations/FuelFlowSimulation.cs
Expand Up @@ -67,15 +67,9 @@ private void SimulateRCS(SimVessel vessel, bool max)
if (vessel.ActiveRcs.Count == 0)
break;

if (max)
Log("we've found some active engines in max");

UpdateRcsDrains(vessel);
double dt = MinimumRcsTimeStep();

if (max)
Log($"dt is {dt} in max");

ApplyRcsDrains(dt);
vessel.UpdateMass();
FinishRcsSegment(max, dt, lastmass, vessel.Mass, vessel.RcsThrust);
Expand Down Expand Up @@ -378,13 +372,9 @@ private double ResourceMaxTime()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FinishRcsSegment(bool max, double deltaTime, double startMass, double endMass, double rcsThrust)
{
Log($"deltatime: {deltaTime} startmass: {startMass} endmass: {endMass} rcsthrust: {rcsThrust}");

double rcsDeltaV = rcsThrust * deltaTime / (startMass - endMass) * Math.Log(startMass / endMass);
double rcsISP = rcsDeltaV / (G0 * Math.Log(startMass / endMass));

Log($"deltav: {rcsDeltaV} isp: {rcsISP}");

if (_currentSegment.RcsISP == 0)
_currentSegment.RcsISP = rcsISP;
if (_currentSegment.RcsThrust == 0)
Expand All @@ -395,15 +385,15 @@ private void FinishRcsSegment(bool max, double deltaTime, double startMass, doub
_currentSegment.MaxRcsDeltaV += rcsDeltaV;
if (_currentSegment.RcsStartTMR == 0)
_currentSegment.RcsStartTMR = rcsThrust / startMass;

_currentSegment.RcsMass += startMass - endMass;
_currentSegment.RcsDeltaTime += deltaTime;
}
else
{
_currentSegment.MinRcsDeltaV += rcsDeltaV;
_currentSegment.RcsEndTMR = _currentSegment.RcsThrust / endMass;
}

_currentSegment.RcsMass += startMass - endMass;
_currentSegment.RcsDeltaTime += deltaTime;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
1 change: 0 additions & 1 deletion MechJeb2/MechJebLib/Simulations/SimResource.cs
Expand Up @@ -34,7 +34,6 @@ public SimResource RCSDrain(double rcsDrain)
{
_rcsAmount -= rcsDrain;
if (Amount < 0) _rcsAmount = _amount;
Log($"RCSDrain: {rcsDrain} _amount: {_amount} _rcsAmount: {_rcsAmount}");

return this;
}
Expand Down

0 comments on commit 6c988a4

Please sign in to comment.