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;
while( timeIndex < time.length-2 && startTime > time[timeIndex+1] ) {
while( timeIndex < time.length-1 && startTime > time[timeIndex+1] ) {
timeIndex++;
}
if ( timeIndex == time.length ) {
if ( timeIndex == time.length-1 ) {
return 0.0;
}

View File

@ -63,6 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
/* Cached data */
final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>();
final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
final private Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
private int boundsModID = -1;
private BoundingBox cachedBounds = new BoundingBox();
@ -109,23 +110,23 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public void clearAllStages() {
this._setAllStages(false);
this.updateMotors();
}
public void setAllStages() {
this._setAllStages(true);
this.updateMotors();
}
private void _setAllStages(final boolean _active) {
for (StageFlags cur : stages.values()) {
cur.active = _active;
}
updateMotors();
}
public void copyStages(FlightConfiguration other) {
for (StageFlags cur : other.stages.values())
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) {
_setStageActive( stageNumber, false );
updateMotors();
}
/**
@ -196,7 +198,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
flags.active = !flags.active;
return;
}
this.updateMotors();
updateMotors();
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() {
Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
for( MotorConfiguration config : this.motors.values() ){
if( isComponentActive( config.getMount() )){
activeMotors.add( config );
}
}
return activeMotors;
}
private void updateMotors() {
this.motors.clear();
motors.clear();
for ( RocketComponent comp : getActiveComponents() ){
if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){
@ -519,10 +515,16 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
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

View File

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