Skip to content

Commit

Permalink
Merge pull request #1339 from indy91/SIIFix
Browse files Browse the repository at this point in the history
Fix simulated S-II engine failures that are set before S-II engine st…
  • Loading branch information
indy91 authored Jan 28, 2025
2 parents 62f6f2f + 5744b9d commit 39d9255
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ void CSMMalfunctionSimulation::ResetFailure(unsigned i)
case CSMFailures_SM_Jett2_Fail:
sat->CmSmSep2Switch.SetFailed(false);
break;
case CSMFailures_SI_Engine_1_Failure:
case CSMFailures_SI_Engine_2_Failure:
case CSMFailures_SI_Engine_3_Failure:
case CSMFailures_SI_Engine_4_Failure:
case CSMFailures_SI_Engine_5_Failure:
case CSMFailures_SI_Engine_6_Failure:
case CSMFailures_SI_Engine_7_Failure:
case CSMFailures_SI_Engine_8_Failure:
case CSMFailures_SII_Engine_1_Failure:
case CSMFailures_SII_Engine_2_Failure:
case CSMFailures_SII_Engine_3_Failure:
case CSMFailures_SII_Engine_4_Failure:
case CSMFailures_SII_Engine_5_Failure:
case CSMFailures_SIVB_Engine_Failure:
case CSMFailures_SIVB_O2_H2_Burner_Failure:
sat->SetFailure(i, false);
break;
Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/Saturn1b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,10 @@ void Saturn1b::SetFailure(int failuretype, bool condition)
case CSMFailures_SI_Engine_6_Failure:
case CSMFailures_SI_Engine_7_Failure:
case CSMFailures_SI_Engine_8_Failure:
if (sib) sib->SetEngineFailed(failuretype - CSMFailures_SI_Engine_1_Failure);
if (sib) sib->SetEngineFailed(failuretype - CSMFailures_SI_Engine_1_Failure, condition);
break;
case CSMFailures_SIVB_Engine_Failure:
if (sivb) sivb->SetEngineFailed();
if (sivb) sivb->SetEngineFailed(condition);
break;
}
}
6 changes: 3 additions & 3 deletions Orbitersdk/samples/ProjectApollo/src_saturn/Saturn5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,17 +1033,17 @@ void SaturnV::SetFailure(int failuretype, bool condition)
case CSMFailures_SI_Engine_3_Failure:
case CSMFailures_SI_Engine_4_Failure:
case CSMFailures_SI_Engine_5_Failure:
if (sic) sic->SetEngineFailed(failuretype - CSMFailures_SI_Engine_1_Failure);
if (sic) sic->SetEngineFailed(failuretype - CSMFailures_SI_Engine_1_Failure, condition);
break;
case CSMFailures_SII_Engine_1_Failure:
case CSMFailures_SII_Engine_2_Failure:
case CSMFailures_SII_Engine_3_Failure:
case CSMFailures_SII_Engine_4_Failure:
case CSMFailures_SII_Engine_5_Failure:
if (sii) sii->SetEngineFailed(failuretype - CSMFailures_SII_Engine_1_Failure);
if (sii) sii->SetEngineFailed(failuretype - CSMFailures_SII_Engine_1_Failure, condition);
break;
case CSMFailures_SIVB_Engine_Failure:
if (sivb) sivb->SetEngineFailed();
if (sivb) sivb->SetEngineFailed(condition);
break;
case CSMFailures_SIVB_O2_H2_Burner_Failure:
if (sivb) sivb->SetO2H2BurnerFailed(condition);
Expand Down
57 changes: 34 additions & 23 deletions Orbitersdk/samples/ProjectApollo/src_saturn/j2engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void J2Engine::SaveState(FILEHANDLE scn, char *start_str, char *end_str) {
papiWriteScenario_bool(scn, "EDSCUTOFF", EDSCutoff);
papiWriteScenario_bool(scn, "RSSCUTOFF", RSSCutoff);
papiWriteScenario_bool(scn, "ENGINERUNNING", EngineRunning);
if (EngineFailed) papiWriteScenario_bool(scn, "ENGINEFAILED", EngineFailed);
papiWriteScenario_double(scn, "THRUSTTIMER", ThrustTimer);
oapiWriteLine(scn, end_str);
}
Expand All @@ -76,6 +77,7 @@ void J2Engine::LoadState(FILEHANDLE scn, char *end_str) {
papiReadScenario_bool(line, "EDSCUTOFF", EDSCutoff);
papiReadScenario_bool(line, "RSSCUTOFF", RSSCutoff);
papiReadScenario_bool(line, "ENGINERUNNING", EngineRunning);
papiReadScenario_bool(line, "ENGINEFAILED", EngineFailed);
papiReadScenario_double(line, "THRUSTTIMER", ThrustTimer);
}
}
Expand All @@ -84,7 +86,7 @@ void J2Engine::Timestep(double simdt)
{
if (th_j2 == NULL) return;

ThrustOK = vessel->GetThrusterLevel(th_j2) > 0.65 && !EngineFailed;
ThrustOK = vessel->GetThrusterLevel(th_j2) > 0.65;

if (!EngineRunning)
{
Expand Down Expand Up @@ -113,31 +115,30 @@ void J2Engine::Timestep(double simdt)
EngineStop = false;
}

if (EngineStop)
if (EngineStop || EngineFailed)
{
if (ThrustLevel > 0.0)
{
ThrustTimer += simdt;

// Cutoff transient thrust
if (ThrustTimer < 2.0) {
if (ThrustTimer < 0.25) {
// 95% of thrust dies in the first .25 second
ThrustLevel = 1.0 - (ThrustTimer*3.3048);
if (ThrustTimer < 0.25) {
// 95% of thrust dies in the first .25 second
ThrustLevel = 1.0 - (ThrustTimer*3.3048);
vessel->SetThrusterLevel(th_j2, ThrustLevel);
}
else {
if (ThrustTimer < 1.5) {
// The remainder dies over the next 1.25 second
ThrustLevel = 0.1738 - ((ThrustTimer - 0.25)*0.1390);
vessel->SetThrusterLevel(th_j2, ThrustLevel);
}
else {
if (ThrustTimer < 1.5) {
// The remainder dies over the next 1.25 second
ThrustLevel = 0.1738 - ((ThrustTimer - 0.25)*0.1390);
vessel->SetThrusterLevel(th_j2, ThrustLevel);
}
else {
// Engine is completely shut down at 1.5 second
ThrustLevel = 0.0;
vessel->SetThrusterLevel(th_j2, ThrustLevel);
EngineRunning = false;
}
// Engine is completely shut down at 1.5 second
ThrustLevel = 0.0;
vessel->SetThrusterLevel(th_j2, ThrustLevel);
EngineRunning = false;
ThrustTimer = 0.0;
}
}
}
Expand All @@ -146,23 +147,33 @@ void J2Engine::Timestep(double simdt)
{
ThrustTimer += simdt;

//First Burn
if (ThrustTimer >= 1.0 && ThrustTimer < 3.2) {
if (ThrustTimer < 1.0)
{
ThrustLevel = 0.0;
}
else if (ThrustTimer < 3.2)
{
ThrustLevel = (ThrustTimer - 1.0)*0.45;
vessel->SetThrusterLevel(th_j2, ThrustLevel);
}
else if (ThrustTimer > 3.2 && ThrustLevel < 1.0)
else
{
ThrustLevel = 1.0;
vessel->SetThrusterLevel(th_j2, ThrustLevel);

EngineRunning = true;
ThrustTimer = 0.0;
}
vessel->SetThrusterLevel(th_j2, ThrustLevel);
}
else if (ThrustTimer > 0.0)
{
ThrustTimer = 0.0;
}

/*
if (EngineFailed)
{
sprintf(oapiDebugString(), "EngineStart %d EngineStop %d EngineRunning %d ThrustTimer %lf ThrustLevel %lf", EngineStart, EngineStop, EngineRunning, ThrustTimer, ThrustLevel);
}
*/
}

void J2Engine::SetThrusterDir(double beta_y, double beta_p)
Expand Down
2 changes: 1 addition & 1 deletion Orbitersdk/samples/ProjectApollo/src_saturn/j2engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class J2Engine
void SetEDSCutoff() { EDSCutoff = true; }
void ResetEDSCutoff() { EDSCutoff = false; }
void SetThrusterDir(double beta_y, double beta_p);
void SetFailed() { EngineFailed = true; }
void SetFailed(bool fail) { EngineFailed = fail; }

bool GetThrustOK() { return ThrustOK; }
bool GetFailed() { return EngineFailed; }
Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/s1bsystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,11 @@ double SIBSystems::GetSumThrust()
return thrust;
}

void SIBSystems::SetEngineFailed(int n)
void SIBSystems::SetEngineFailed(int n, bool fail)
{
if (n < 0 || n > 7) return;

h1engines[n]->SetFailed();
h1engines[n]->SetFailed(fail);
}

bool SIBSystems::GetEngineStop()
Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/s1bsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class H1Engine
void SetGSECutoff() { GSECutoff = true; }
void SetThrustNotOKCutoff() { ThrustNotOKCutoff = true; }
void SetThrusterDir(double beta_y, double beta_p);
void SetFailed() { EngineFailed = true; }
void SetFailed(bool fail) { EngineFailed = fail; }

bool GetThrustOK() { return ThrustOK; }
double GetThrustLevel() { return ThrustLevel; }
Expand Down Expand Up @@ -82,7 +82,7 @@ class SIBSystems
void SaveState(FILEHANDLE scn);
void LoadState(FILEHANDLE scn);

void SetEngineFailed(int n);
void SetEngineFailed(int n, bool fail);

virtual void SetEngineStart(int n);
void SwitchSelector(int channel);
Expand Down
6 changes: 4 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/s1csystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void F1Engine::SaveState(FILEHANDLE scn, char *start_str, char *end_str) {
papiWriteScenario_bool(scn, "GSECUTOFF", GSECutoff);
papiWriteScenario_bool(scn, "RSSCUTOFF", RSSCutoff);
papiWriteScenario_bool(scn, "ENGINERUNNING", EngineRunning);
if (EngineFailed) papiWriteScenario_bool(scn, "ENGINEFAILED", EngineFailed);
papiWriteScenario_double(scn, "THRUSTTIMER", ThrustTimer);
papiWriteScenario_double(scn, "PITCHCMD", pitchCmd);
papiWriteScenario_double(scn, "PITCHPOS", pitchPos);
Expand All @@ -89,6 +90,7 @@ void F1Engine::LoadState(FILEHANDLE scn, char *end_str) {
papiReadScenario_bool(line, "GSECUTOFF", GSECutoff);
papiReadScenario_bool(line, "RSSCUTOFF", RSSCutoff);
papiReadScenario_bool(line, "ENGINERUNNING", EngineRunning);
papiReadScenario_bool(line, "ENGINEFAILED", EngineFailed);
papiReadScenario_double(line, "THRUSTTIMER", ThrustTimer);
papiReadScenario_double(line, "PITCHCMD", pitchCmd);
papiReadScenario_double(line, "PITCHPOS", pitchPos);
Expand Down Expand Up @@ -482,11 +484,11 @@ void SICSystems::GetThrustOK(bool *ok)
}
}

void SICSystems::SetEngineFailed(int n)
void SICSystems::SetEngineFailed(int n, bool condition)
{
if (n >= 0 && n <= 4)
{
f1engines[n]->SetFailed();
f1engines[n]->SetFailed(condition);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/s1csystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class F1Engine
void SetEDSCutoff() { EDSCutoff = true; }
void SetGSECutoff() { GSECutoff = true; }
void SetThrusterDir(double beta_y, double beta_p);
void SetFailed() { EngineFailed = true; }
void SetFailed(bool fail) { EngineFailed = fail; }

bool GetThrustOK() { return ThrustOK; }
double GetThrustLevel() { return ThrustLevel; }
Expand Down Expand Up @@ -96,7 +96,7 @@ class SICSystems
void SetThrusterDir(int n, double beta_y, double beta_p);
void SwitchSelector(int channel);

void SetEngineFailed(int n);
void SetEngineFailed(int n, bool condition);

bool PropellantLowLevel();
void GetThrustOK(bool *ok);
Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/siisystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ void SIISystems::Timestep(double simdt)
}
}

void SIISystems::SetEngineFailed(int n)
void SIISystems::SetEngineFailed(int n, bool fail)
{
if (n < 0 || n > 4) return;

j2engines[n]->SetFailed();
j2engines[n]->SetFailed(fail);
}

#define MR_STATS 5
Expand Down
2 changes: 1 addition & 1 deletion Orbitersdk/samples/ProjectApollo/src_saturn/siisystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SIISystems
void SetMixtureRatio(double ratio);
void SwitchSelector(int channel);

void SetEngineFailed(int n);
void SetEngineFailed(int n, bool fail);

void GetThrustOK(bool *ok);
bool GetPropellantDepletionEngineCutoff();
Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_saturn/sivbsystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,9 +1618,9 @@ void SIVBSystems::GetJ2ISP(double ratio, double &isp, double &ThrustAdjust)
}
}

void SIVBSystems::SetEngineFailed()
void SIVBSystems::SetEngineFailed(bool fail)
{
EngineFailed = true;
EngineFailed = fail;
}

void SIVBSystems::SetO2H2BurnerFailed(bool fail)
Expand Down
2 changes: 1 addition & 1 deletion Orbitersdk/samples/ProjectApollo/src_saturn/sivbsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class SIVBSystems : public BaseSIVBSystems
double GetLOXTankUllagePressurePSI() { return LOXTankUllagePressurePSI; }
bool GetBurnerMalfunction() { return BurnerMalfunctionSignal; }

void SetEngineFailed();
void SetEngineFailed(bool fail);
void SetO2H2BurnerFailed(bool fail);

void SaveState(FILEHANDLE scn);
Expand Down

0 comments on commit 39d9255

Please sign in to comment.