Allow out of order stage separation

This commit is contained in:
JoePfeiffer 2022-10-03 11:39:00 -06:00
parent 0b7d9fe0ef
commit 0f3fffb21d
2 changed files with 43 additions and 8 deletions

View File

@ -147,6 +147,34 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
updateActiveInstances(); updateActiveInstances();
} }
/**
* This method clears a stage and all stages below (higher stage number)
*
* @param stageNumber first stage number to turn off
*/
public void clearStagesBelow(int stageNumber) {
// I can't just use _setStageActive(stageNumber, false, true)
// because that won't clear side boosters' active flags (should it?)
for (int i = stageNumber; i < rocket.getStageCount(); i++) {
_setStageActive(i, false, false);
}
updateMotors();
updateActiveInstances();
}
/**
* This method clears all stages above (but not including) a stage
*
* @param stageNumber first stage number to stay active
*/
public void clearStagesAbove(int stageNumber) {
for (int i = 0; i < stageNumber; i++) {
_setStageActive(i, false, false);
}
updateMotors();
updateActiveInstances();
}
/** /**
* Activates all stages as active starting from the specified component * Activates all stages as active starting from the specified component
* to the top-most stage in the rocket. Active stages are those stages * to the top-most stage in the rocket. Active stages are those stages
@ -187,7 +215,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
/** /**
* This method flags the specified stage as requested. Other stages are unaffected. * This method flags the specified stage as requested. Substages may be affected, depending on third parameter
* *
* @param stageNumber stage number to flag * @param stageNumber stage number to flag
* @param _active inactive (<code>false</code>) or active (<code>true</code>) * @param _active inactive (<code>false</code>) or active (<code>true</code>)

View File

@ -305,6 +305,9 @@ public class BasicEventSimulationEngine implements SimulationEngine {
if (event.getSource() != null && event.getSource().getParent() != null && if (event.getSource() != null && event.getSource().getParent() != null &&
!currentStatus.getConfiguration().isComponentActive(event.getSource())) { !currentStatus.getConfiguration().isComponentActive(event.getSource())) {
log.trace("Ignoring event from unattached component"); log.trace("Ignoring event from unattached component");
log.debug(" source " + event.getSource());
log.debug(" parent " + event.getSource().getParent());
log.debug(" active " + currentStatus.getConfiguration().isComponentActive(event.getSource()));
continue; continue;
} }
@ -381,7 +384,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
} }
// and queue up the burnout for this motor, as well. // and queue up the burnout for this motor, as well.
// double duration = motorState.getMotor().getBurnTimeEstimate();
double duration = motorState.getBurnTime(); double duration = motorState.getBurnTime();
double burnout = currentStatus.getSimulationTime() + duration; double burnout = currentStatus.getSimulationTime() + duration;
addEvent(new FlightEvent(FlightEvent.Type.BURNOUT, burnout, addEvent(new FlightEvent(FlightEvent.Type.BURNOUT, burnout,
@ -436,19 +438,24 @@ public class BasicEventSimulationEngine implements SimulationEngine {
case STAGE_SEPARATION: { case STAGE_SEPARATION: {
RocketComponent boosterStage = event.getSource(); RocketComponent boosterStage = event.getSource();
final int stageNumber = boosterStage.getStageNumber(); final int stageNumber = boosterStage.getStageNumber();
log.debug("separating at stage " + stageNumber);
if (currentStatus.getConfiguration().isStageActive(stageNumber-1)) { if (currentStatus.getConfiguration().isStageActive(stageNumber-1)) {
// Record the event. // Record the event.
currentStatus.getFlightData().addEvent(event); currentStatus.getFlightData().addEvent(event);
// Mark the status as having dropped the booster // Create a new simulation branch for the booster
currentStatus.getConfiguration().clearStage( stageNumber);
// Prepare the simulation branch
SimulationStatus boosterStatus = new SimulationStatus(currentStatus); SimulationStatus boosterStatus = new SimulationStatus(currentStatus);
// Prepare the new simulation branch
boosterStatus.setFlightData(new FlightDataBranch(boosterStage.getName(), FlightDataType.TYPE_TIME)); boosterStatus.setFlightData(new FlightDataBranch(boosterStage.getName(), FlightDataType.TYPE_TIME));
// Mark the booster status as only having the booster.
boosterStatus.getConfiguration().setOnlyStage(stageNumber); // Mark the current status as having dropped the current stage and all stages below it
currentStatus.getConfiguration().clearStagesBelow( stageNumber);
// Mark the booster status as having no active stages above
boosterStatus.getConfiguration().clearStagesAbove(stageNumber);
toSimulate.push(boosterStatus); toSimulate.push(boosterStatus);
log.info(String.format("==>> @ %g; from Branch: %s ---- Branching: %s ---- \n", log.info(String.format("==>> @ %g; from Branch: %s ---- Branching: %s ---- \n",
currentStatus.getSimulationTime(), currentStatus.getSimulationTime(),