Clarify comments and debug logging

This commit is contained in:
JoePfeiffer 2022-10-15 16:43:34 -06:00
parent 3745584e1a
commit df00500077

View File

@ -275,8 +275,10 @@ public class SimulationRunDialog extends JDialog {
private final CustomExpressionSimulationListener exprListener; private final CustomExpressionSimulationListener exprListener;
/* /*
* -2 = time from 0 ... burnoutTimeEstimate -1 = velocity from * Keep track of current phase ("stage") of simulation
* v(burnoutTimeEstimate) ... 0 0 ... n = stages from alt(max) ... 0 * -2: Boost. Estimate progress using time from 0 to burnoutTimeEstimate
* -1: Coast. Estimate progress using velocity from v(burnoutTimeEstimate) to 0
* 0 ... n: Landing. stages from alt(max) ... 0 (?)
*/ */
private volatile int simulationStage = -2; private volatile int simulationStage = -2;
@ -332,39 +334,41 @@ public class SimulationRunDialog extends JDialog {
SimulationStatus status = chunks.get(chunks.size() - 1); SimulationStatus status = chunks.get(chunks.size() - 1);
simulationStatuses[index] = status; simulationStatuses[index] = status;
// 1. time = 0 ... burnoutTimeEstimate // -2: Boost. time = 0 ... burnoutTimeEstimate
if (simulationStage == -2 && status.getSimulationTime() < burnoutTimeEstimate) { if (simulationStage == -2 && status.getSimulationTime() < burnoutTimeEstimate) {
log.debug("Method 1: t=" + status.getSimulationTime() + " est=" + burnoutTimeEstimate); log.debug("simulationStage boost: t=" + status.getSimulationTime() + " est=" + burnoutTimeEstimate);
setSimulationProgress( setSimulationProgress(
MathUtil.map(status.getSimulationTime(), 0, burnoutTimeEstimate, 0.0, BURNOUT_PROGRESS)); MathUtil.map(status.getSimulationTime(), 0, burnoutTimeEstimate, 0.0, BURNOUT_PROGRESS));
updateProgress(); updateProgress();
return; return;
} }
// Past burnout time estimate, switch to coast.
if (simulationStage == -2) { if (simulationStage == -2) {
simulationStage++; simulationStage++;
burnoutVelocity = MathUtil.max(status.getRocketVelocity().z, 0.1); burnoutVelocity = MathUtil.max(status.getRocketVelocity().z, 0.1);
log.debug("CHANGING to Method 2, vel=" + burnoutVelocity); log.debug("CHANGING to simulationStage " + simulationStage + ", vel=" + burnoutVelocity);
} }
// 2. z-velocity from burnout velocity to zero // -1: Coast. z-velocity from burnout velocity to zero
if (simulationStage == -1 && status.getRocketVelocity().z >= 0) { if (simulationStage == -1 && status.getRocketVelocity().z >= 0) {
log.debug("Method 2: vel=" + status.getRocketVelocity().z + " burnout=" + burnoutVelocity); log.debug("simulationStage coast: vel=" + status.getRocketVelocity().z + " burnout=" + burnoutVelocity);
setSimulationProgress(MathUtil.map(status.getRocketVelocity().z, burnoutVelocity, 0, BURNOUT_PROGRESS, setSimulationProgress(MathUtil.map(status.getRocketVelocity().z, burnoutVelocity, 0, BURNOUT_PROGRESS,
APOGEE_PROGRESS)); APOGEE_PROGRESS));
updateProgress(); updateProgress();
return; return;
} }
// Past apogee, switch to landing
if (simulationStage == -1 && status.getRocketVelocity().z < 0) { if (simulationStage == -1 && status.getRocketVelocity().z < 0) {
simulationStage++; simulationStage++;
apogeeAltitude = MathUtil.max(status.getRocketPosition().z, 1); apogeeAltitude = MathUtil.max(status.getRocketPosition().z, 1);
log.debug("CHANGING to Method 3, apogee=" + apogeeAltitude); log.debug("CHANGING to simulationStage " + simulationStage + ", apogee=" + apogeeAltitude);
} }
// 3. z-position from apogee to zero // >= 0 Landing. z-position from apogee to zero
// TODO: MEDIUM: several stages // TODO: MEDIUM: several stages
log.debug("Method 3: alt=" + status.getRocketPosition().z + " apogee=" + apogeeAltitude); log.debug("simulationStage landing (" + simulationStage + "): alt=" + status.getRocketPosition().z + " apogee=" + apogeeAltitude);
setSimulationProgress(MathUtil.map(status.getRocketPosition().z, apogeeAltitude, 0, APOGEE_PROGRESS, 1.0)); setSimulationProgress(MathUtil.map(status.getRocketPosition().z, apogeeAltitude, 0, APOGEE_PROGRESS, 1.0));
updateProgress(); updateProgress();
} }