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

Add new SimulatedTime variable in Saturn class, which makes it possible for MissionTime to be updated before launch #1298

Draft
wants to merge 1 commit into
base: Orbiter2016
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions Orbitersdk/samples/ProjectApollo/src_csm/satsystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,9 @@ void Saturn::SystemsTimestep(double simt, double simdt, double mjd) {
//

Failures.Timestep();
dsky.Timestep(MissionTime);
dsky2.Timestep(MissionTime);
agc.Timestep(MissionTime, simdt);
dsky.Timestep(simt);
dsky2.Timestep(simt);
agc.Timestep(SimulatedTime, simdt);
optics.TimeStep(simdt);


Expand All @@ -806,45 +806,45 @@ void Saturn::SystemsTimestep(double simt, double simdt, double mjd) {
rjec.TimeStep(simdt);
tvsa.TimeStep(simdt);
eda.Timestep(simdt);
cws.TimeStep(MissionTime);
dockingprobe.TimeStep(MissionTime, simdt);
secs.Timestep(MissionTime, simdt);
els.Timestep(MissionTime, simdt);
cws.TimeStep(SimulatedTime);
dockingprobe.TimeStep(simt, simdt);
secs.Timestep(simt, simdt);
els.Timestep(simt, simdt);
ordeal.Timestep(simdt);
mechanicalAccelerometer.Timestep(simdt);
MissionTimerDisplay.Timestep(simt, simdt, false);
MissionTimer306Display.Timestep(simt, simdt, false);
EventTimerDisplay.Timestep(simt, simdt, true);
EventTimer306Display.Timestep(simt, simdt, true);
fdaiLeft.SetAttitude(eda.GetFDAI1Attitude());
fdaiLeft.Timestep(MissionTime, simdt);
fdaiLeft.Timestep(simt, simdt);
fdaiRight.SetAttitude(eda.GetFDAI2Attitude());
fdaiRight.Timestep(MissionTime, simdt);
SPSPropellant.Timestep(MissionTime, simdt);
fdaiRight.Timestep(simt, simdt);
SPSPropellant.Timestep(simt, simdt);
JoystickTimestep();
EPSTimestep();
SMQuadARCS.Timestep(MissionTime, simdt);
SMQuadBRCS.Timestep(MissionTime, simdt);
SMQuadCRCS.Timestep(MissionTime, simdt);
SMQuadDRCS.Timestep(MissionTime, simdt);
CMRCS1.Timestep(MissionTime, simdt); // Must be after JoystickTimestep
CMRCS2.Timestep(MissionTime, simdt);
SMQuadARCS.Timestep(simt, simdt);
SMQuadBRCS.Timestep(simt, simdt);
SMQuadCRCS.Timestep(simt, simdt);
SMQuadDRCS.Timestep(simt, simdt);
CMRCS1.Timestep(simt, simdt); // Must be after JoystickTimestep
CMRCS2.Timestep(simt, simdt);
SideHatch.Timestep(simdt);
ForwardHatch.Timestep(simdt);

//Telecom update is last so telemetry reflects the current state
udl.Timestep();
pmp.TimeStep(MissionTime);
usb.TimeStep(MissionTime);
hga.TimeStep(MissionTime, simdt);
pmp.TimeStep(simt);
usb.TimeStep(SimulatedTime);
hga.TimeStep(SimulatedTime, simdt);
omnia.TimeStep();
omnib.TimeStep();
omnic.TimeStep();
omnid.TimeStep();
if (pMission->CSMHasVHFRanging()) vhfranging.TimeStep(simdt);
vhftransceiver.Timestep();
sce.Timestep();
dataRecorder.TimeStep( MissionTime, simdt );
dataRecorder.TimeStep( SimulatedTime, simdt );
RRTsystem.TimeStep(simdt);

//
Expand Down
41 changes: 28 additions & 13 deletions Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ void Saturn::initSaturn()
// Default mission time to an hour prior to launch.
//

SimulatedTime = 0.0;
MissionTime = (-3600);
NextMissionEventTime = 0;

Expand Down Expand Up @@ -1403,15 +1404,17 @@ void Saturn::GetApolloName(char *s)
sprintf(s, "AS-%d", VehicleNo);
}

void Saturn::UpdateLaunchTime(double t)

void Saturn::UpdateLaunchTime(double dt)
{
if (t < 0)
//Don't allow earlier launch
if (dt < 0.0)
return;
//Don't allow during terminal countdown
if (MissionTime >= -186.0)
return;

if (MissionTime < 0) {
MissionTime = (-t);
}
//Update time
MissionTime -= dt;
}

//
Expand Down Expand Up @@ -1589,7 +1592,7 @@ void Saturn::clbkPostStep(double simt, double simdt, double mjd)
// to inhibit Orbiter's thrust control
//

SPSEngine.Timestep(MissionTime, simdt);
SPSEngine.Timestep(SimulatedTime, simdt);

// Better acceleration measurement stability
imu.Timestep(simdt);
Expand Down Expand Up @@ -1661,6 +1664,7 @@ void Saturn::clbkSaveState(FILEHANDLE scn)
oapiWriteScenario_int (scn, "PANEL_ID", PanelId);
oapiWriteScenario_int(scn, "VIEWPOS", viewpos);
papiWriteScenario_double (scn, "TCP", TCPO);
papiWriteScenario_double(scn, "SIMULATEDTIME", SimulatedTime);
papiWriteScenario_double (scn, "MISSNTIME", MissionTime);
papiWriteScenario_double (scn, "NMISSNTIME", NextMissionEventTime);

Expand Down Expand Up @@ -2250,6 +2254,10 @@ bool Saturn::ProcessConfigFileLine(FILEHANDLE scn, char *line)
else if (!strnicmp (line, "SATTYPE", 7)) {
sscanf (line+7, "%d", &SaturnType);
}
else if (!strnicmp(line, "SIMULATEDTIME", 13)) {
sscanf(line + 13, "%f", &ftcp);
SimulatedTime = ftcp;
}
else if (!strnicmp(line, "MISSNTIME", 9)) {
sscanf (line+9, "%f", &ftcp);
MissionTime = ftcp;
Expand Down Expand Up @@ -2789,6 +2797,12 @@ void Saturn::GetScenarioState (FILEHANDLE scn, void *vstatus)
}
}

//Backwards compatibility for simulated time
if (SimulatedTime == 0.0)
{
SimulatedTime = MissionTime;
}

//
// Recalculate stage masses.
//
Expand Down Expand Up @@ -3075,15 +3089,16 @@ void Saturn::GenericTimestep(double simt, double simdt, double mjd)
// Update mission time.
//

SimulatedTime += simdt;
MissionTime += simdt;

//
// Panel flash counter.
//

if (MissionTime >= NextFlashUpdate) {
if (SimulatedTime >= NextFlashUpdate) {
PanelFlashOn = !PanelFlashOn;
NextFlashUpdate = MissionTime + 0.25;
NextFlashUpdate = SimulatedTime + 0.25;
}

//
Expand Down Expand Up @@ -3255,9 +3270,9 @@ void Saturn::GenericTimestep(double simt, double simdt, double mjd)

if (noiselat > 0.0 || (vAccel.x*vAccel.x + vAccel.y*vAccel.y + vAccel.z*vAccel.z) > 0.01) {
JostleViewpoint(noiselat, noiselong, noisefreq, simdt, -seatacc.x / 200.0, -seatacc.y / 200.0, -seatacc.z / 300.0);
LastVPAccelTime = MissionTime;
LastVPAccelTime = SimulatedTime;
}
else if (MissionTime<LastVPAccelTime + 5.0){
else if (SimulatedTime <LastVPAccelTime + 5.0){
ViewOffsetx *= 0.95;
ViewOffsety *= 0.95;
ViewOffsetz *= 0.95;
Expand Down Expand Up @@ -3305,9 +3320,9 @@ void Saturn::GenericTimestep(double simt, double simdt, double mjd)
// Destroy obsolete stages
//

if (MissionTime >= NextDestroyCheckTime) {
if (SimulatedTime >= NextDestroyCheckTime) {
DestroyStages(simt);
NextDestroyCheckTime = MissionTime + 1.0;
NextDestroyCheckTime = SimulatedTime + 1.0;
}

//
Expand Down
18 changes: 15 additions & 3 deletions Orbitersdk/samples/ProjectApollo/src_csm/saturn.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,11 @@ class Saturn: public ProjectApolloConnectorVessel, public PanelSwitchListener {

///
/// This function can be used during the countdown to update the MissionTime. Since we launch when
/// MissionTime reaches zero, setting MissionTime to (-t) tells the code when to launch.
/// MissionTime reaches zero, delay the MissionTime by dt tells the code when to launch.
/// \brief Update the launch time.
/// \param t Specifies the time in seconds to wait before launch.
/// \param t Specifies the time in seconds to delay the launch.
///
void UpdateLaunchTime(double t);
virtual void UpdateLaunchTime(double dt);

///
/// Set up the default mesh for the virtual cockpit.
Expand Down Expand Up @@ -1399,10 +1399,22 @@ class Saturn: public ProjectApolloConnectorVessel, public PanelSwitchListener {
// Current mission time and mission times for stage events.
//

///
/// The current Simulated Time, which runs continuously throughout the mission.
/// If the mission elapsed time is not changed before launch, essentially a launch
/// delay, then SimulatedTime is identical to MissionTime. This time can be used for
/// subsystems that need a steadily updating time, which does not need to have a
/// specific time reference/start time.
/// \brief Simulated Time.
///
double SimulatedTime;

///
/// The current Mission Elapsed Time. This is the main variable used for timing
/// automated events during the mission, giving the time in seconds from launch
/// (negative for the pre-launch countdown).
/// It can be changed during pre-launch to enact a launch delay, but should not
/// be modified after launch.
/// \brief Mission Elapsed Time.
///
double MissionTime;
Expand Down
26 changes: 26 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_mfd/ProjectApolloMFD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,21 @@ bool ProjectApolloMFD::SetReferencePlanet (char *rstr)
return false;
}

bool ProjectApolloMFD::SetLaunchTime(char *rstr)
{
double DT;

if (sscanf(rstr, "%lf", &DT) == 1)
{
if (saturn)
{
saturn->UpdateLaunchTime(DT);
return true;
}
}
return false;
}

bool ProjectApolloMFD::SetCrewNumber (char *rstr)
{
int n;
Expand Down Expand Up @@ -1938,6 +1953,12 @@ void ProjectApolloMFD::menuVAGCCoreDump()
lem->VirtualAGCCoreDump();
}

void ProjectApolloMFD::menuChangeLaunchTime()
{
bool LaunchTimeInput(void *id, char *str, void *data);
oapiOpenInputBox("Choose delay in launch time (positive value):", LaunchTimeInput, 0, 20, (void*)this);
}

void ProjectApolloMFD::menuSetCrewNumber()
{
bool CrewNumberInput(void *id, char *str, void *data);
Expand Down Expand Up @@ -2493,6 +2514,11 @@ bool ReferencePlanetInput (void *id, char *str, void *data)
return ((ProjectApolloMFD*)data)->SetReferencePlanet(str);
}

bool LaunchTimeInput(void *id, char *str, void *data)
{
return ((ProjectApolloMFD*)data)->SetLaunchTime(str);
}

bool CrewNumberInput (void *id, char *str, void *data)
{
return ((ProjectApolloMFD*)data)->SetCrewNumber(str);
Expand Down
2 changes: 2 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_mfd/ProjectApolloMFD.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ProjectApolloMFD: public MFD2 {
void GetStateVector (void);
bool SetSource(char *rstr);
bool SetReferencePlanet(char *rstr);
bool SetLaunchTime(char *rstr);
bool SetCrewNumber (char *rstr);
bool SetPrimECSTestHeaterPower (char *rstr);
bool SetSecECSTestHeaterPower (char *rstr);
Expand Down Expand Up @@ -80,6 +81,7 @@ class ProjectApolloMFD: public MFD2 {
void menuKillRot();
void menuSaveEMSScroll();
void menuVAGCCoreDump();
void menuChangeLaunchTime();
void menuSetCrewNumber();
void menuSetCDRInSuit();
void menuSetLMPInSuit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ ProjectApolloMFDButtons::ProjectApolloMFDButtons()
RegisterFunction("DBG", OAPI_KEY_D, &ProjectApolloMFD::menuSetDebugPage);


static const MFDBUTTONMENU mnuGNC[4] = {
static const MFDBUTTONMENU mnuGNC[5] = {
{ "Back", 0, 'B' },
{ "Kill rotation", 0, 'K' },
{ "Save EMS scroll", 0, 'E' },
{ "Virtual AGC core dump", 0, 'D' }
{ "Virtual AGC core dump", 0, 'D' },
{ "Change Saturn launch time", 0, 'T' }
};

page.GNC = RegisterPage(mnuGNC, sizeof(mnuGNC) / sizeof(MFDBUTTONMENU));
Expand All @@ -48,6 +49,7 @@ ProjectApolloMFDButtons::ProjectApolloMFDButtons()
RegisterFunction("KILR", OAPI_KEY_K, &ProjectApolloMFD::menuKillRot);
RegisterFunction("EMS", OAPI_KEY_E, &ProjectApolloMFD::menuSaveEMSScroll);
RegisterFunction("DMP", OAPI_KEY_D, &ProjectApolloMFD::menuVAGCCoreDump);
RegisterFunction("TLO", OAPI_KEY_D, &ProjectApolloMFD::menuChangeLaunchTime);


static const MFDBUTTONMENU mnuECS[8] = {
Expand Down