Merge pull request #1221 from JoePfeiffer/fix-1210

Correctly identify when time is past end of thrustcurve so thrust is 0 in getAverageThrust
This commit is contained in:
SiboVG 2022-03-07 23:29:56 +01:00 committed by GitHub
commit 498a42a3c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View File

@ -338,11 +338,11 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
int timeIndex = 0; int timeIndex = 0;
while( timeIndex < time.length-2 && startTime > time[timeIndex+1] ) { while( timeIndex < time.length-1 && startTime > time[timeIndex+1] ) {
timeIndex++; timeIndex++;
} }
if ( timeIndex == time.length ) { if ( timeIndex == time.length-1 ) {
return 0.0; return 0.0;
} }

View File

@ -63,6 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
/* Cached data */ /* Cached data */
final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>(); final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>();
final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>(); final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
final private Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
private int boundsModID = -1; private int boundsModID = -1;
private BoundingBox cachedBounds = new BoundingBox(); private BoundingBox cachedBounds = new BoundingBox();
@ -109,23 +110,23 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public void clearAllStages() { public void clearAllStages() {
this._setAllStages(false); this._setAllStages(false);
this.updateMotors();
} }
public void setAllStages() { public void setAllStages() {
this._setAllStages(true); this._setAllStages(true);
this.updateMotors();
} }
private void _setAllStages(final boolean _active) { private void _setAllStages(final boolean _active) {
for (StageFlags cur : stages.values()) { for (StageFlags cur : stages.values()) {
cur.active = _active; cur.active = _active;
} }
updateMotors();
} }
public void copyStages(FlightConfiguration other) { public void copyStages(FlightConfiguration other) {
for (StageFlags cur : other.stages.values()) for (StageFlags cur : other.stages.values())
stages.put(cur.stageNumber, new StageFlags(cur.stageNumber, cur.active)); stages.put(cur.stageNumber, new StageFlags(cur.stageNumber, cur.active));
updateMotors();
} }
/** /**
@ -135,6 +136,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
*/ */
public void clearStage(final int stageNumber) { public void clearStage(final int stageNumber) {
_setStageActive( stageNumber, false ); _setStageActive( stageNumber, false );
updateMotors();
} }
/** /**
@ -196,7 +198,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
flags.active = !flags.active; flags.active = !flags.active;
return; return;
} }
this.updateMotors(); updateMotors();
log.error("error: attempt to retrieve via a bad stage number: " + stageNumber); log.error("error: attempt to retrieve via a bad stage number: " + stageNumber);
} }
@ -498,18 +500,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
public Collection<MotorConfiguration> getActiveMotors() { public Collection<MotorConfiguration> getActiveMotors() {
Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
for( MotorConfiguration config : this.motors.values() ){
if( isComponentActive( config.getMount() )){
activeMotors.add( config );
}
}
return activeMotors; return activeMotors;
} }
private void updateMotors() { private void updateMotors() {
this.motors.clear(); motors.clear();
for ( RocketComponent comp : getActiveComponents() ){ for ( RocketComponent comp : getActiveComponents() ){
if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){ if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){
@ -519,10 +515,16 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
continue; continue;
} }
this.motors.put( motorConfig.getMID(), motorConfig); motors.put( motorConfig.getMID(), motorConfig);
} }
} }
activeMotors.clear();
for( MotorConfiguration config : motors.values() ){
if( isComponentActive( config.getMount() )){
activeMotors.add( config );
}
}
} }
@Override @Override

View File

@ -181,7 +181,7 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
thrust = 0; thrust = 0;
final double currentTime = status.getSimulationTime() + timestep; final double currentTime = status.getSimulationTime() + timestep;
Collection<MotorClusterState> activeMotorList = status.getMotors(); Collection<MotorClusterState> activeMotorList = status.getActiveMotors();
for (MotorClusterState currentMotorState : activeMotorList ) { for (MotorClusterState currentMotorState : activeMotorList ) {
thrust += currentMotorState.getAverageThrust( status.getSimulationTime(), currentTime ); thrust += currentMotorState.getAverageThrust( status.getSimulationTime(), currentTime );
//thrust += currentMotorState.getThrust( currentTime ); //thrust += currentMotorState.getThrust( currentTime );