Get rid of redundant apogeeAltitude. Use maxAltitude[index] instead

(this actually solves the reported bug; apogeeAltitude was being set
to the first altitude after apogee which could in pathological conditions
already be 0).
This commit is contained in:
JoePfeiffer 2022-10-15 16:59:42 -06:00
parent df00500077
commit 942b3adacf

View File

@ -270,7 +270,6 @@ public class SimulationRunDialog extends JDialog {
private final int index; private final int index;
private final double burnoutTimeEstimate; private final double burnoutTimeEstimate;
private volatile double burnoutVelocity; private volatile double burnoutVelocity;
private volatile double apogeeAltitude;
private final CustomExpressionSimulationListener exprListener; private final CustomExpressionSimulationListener exprListener;
@ -278,7 +277,8 @@ public class SimulationRunDialog extends JDialog {
* Keep track of current phase ("stage") of simulation * Keep track of current phase ("stage") of simulation
* -2: Boost. Estimate progress using time from 0 to burnoutTimeEstimate * -2: Boost. Estimate progress using time from 0 to burnoutTimeEstimate
* -1: Coast. Estimate progress using velocity from v(burnoutTimeEstimate) to 0 * -1: Coast. Estimate progress using velocity from v(burnoutTimeEstimate) to 0
* 0 ... n: Landing. stages from alt(max) ... 0 (?) * 0 ... n: Landing. Estimate progress using altitude from alt(max) ... 0
* (it appears as if the idea is to use values above 0 to support multiple stages, but this is not implemented)
*/ */
private volatile int simulationStage = -2; private volatile int simulationStage = -2;
@ -362,14 +362,13 @@ public class SimulationRunDialog extends JDialog {
// Past apogee, switch to landing // 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); log.debug("CHANGING to simulationStage " + simulationStage + ", apogee=" + simulationMaxAltitude[index]);
log.debug("CHANGING to simulationStage " + simulationStage + ", apogee=" + apogeeAltitude);
} }
// >= 0 Landing. z-position from apogee to zero // >= 0 Landing. z-position from apogee to zero
// TODO: MEDIUM: several stages // TODO: MEDIUM: several stages
log.debug("simulationStage landing (" + simulationStage + "): alt=" + status.getRocketPosition().z + " apogee=" + apogeeAltitude); log.debug("simulationStage landing (" + simulationStage + "): alt=" + status.getRocketPosition().z + " apogee=" + simulationMaxAltitude[index]);
setSimulationProgress(MathUtil.map(status.getRocketPosition().z, apogeeAltitude, 0, APOGEE_PROGRESS, 1.0)); setSimulationProgress(MathUtil.map(status.getRocketPosition().z, simulationMaxAltitude[index], 0, APOGEE_PROGRESS, 1.0));
updateProgress(); updateProgress();
} }
@ -444,7 +443,6 @@ public class SimulationRunDialog extends JDialog {
switch (event.getType()) { switch (event.getType()) {
case APOGEE: case APOGEE:
simulationStage = 0; simulationStage = 0;
apogeeAltitude = status.getRocketPosition().z;
log.debug("APOGEE, setting progress"); log.debug("APOGEE, setting progress");
setSimulationProgress(APOGEE_PROGRESS); setSimulationProgress(APOGEE_PROGRESS);
publish(status); publish(status);