[Bugfix] Fixed Simulation bug - propellant mass storage

fixed propellantMass bug.
This commit is contained in:
Daniel_M_Williams 2015-12-04 09:30:09 -05:00
parent 729effd690
commit 65ddd1b2a2
5 changed files with 82 additions and 43 deletions

View File

@ -251,12 +251,12 @@ public class MassCalculator implements Monitorable {
*/ */
public double getPropellantMass(FlightConfiguration configuration, MassCalcType calcType ){ public double getPropellantMass(FlightConfiguration configuration, MassCalcType calcType ){
double mass = 0; double mass = 0;
//throw new BugException("getPropellantMass is not yet implemented.... "); //throw new BugException("getPropellantMass is not yet implemented.... ");
// add up the masses of all motors in the rocket // add up the masses of all motors in the rocket
if ( MassCalcType.NO_MOTORS != calcType ){ if ( MassCalcType.NO_MOTORS != calcType ){
for (MotorInstance curInstance : configuration.getActiveMotors()) { for (MotorInstance curInstance : configuration.getActiveMotors()) {
mass = mass + curInstance.getCG().weight - curInstance.getMotor().getEmptyCG().weight; mass = mass + curInstance.getPropellantMass();
mass = curInstance.getMotor().getLaunchCG().weight - curInstance.getMotor().getEmptyCG().weight;
} }
} }
return mass; return mass;

View File

@ -227,8 +227,14 @@ public class MassData {
return I_cm.zz; return I_cm.zz;
} }
// this is a tacked-on hack.
double m_p = Double.NaN;
public void setPropellantMass( final double _mp){
this.m_p = _mp;
}
public double getPropellantMass(){ public double getPropellantMass(){
return Double.NaN; return this.m_p;
} }
/** /**

View File

@ -15,20 +15,19 @@ import net.sf.openrocket.util.StateChangeListener;
* A single motor configuration. This includes the selected motor * A single motor configuration. This includes the selected motor
* and the ejection charge delay. * and the ejection charge delay.
*/ */
public class MotorInstance implements FlightConfigurableParameter<MotorInstance> { public abstract class MotorInstance implements FlightConfigurableParameter<MotorInstance> {
protected MotorInstanceId id = null;
// deferred to subclasses // deferred to subclasses
//protected MotorMount mount = null; //protected MotorMount mount = null;
//protected Motor motor = null; //protected Motor motor = null;
protected MotorInstanceId id = null;
protected double ejectionDelay = 0.0; protected double ejectionDelay = 0.0;
protected double ignitionDelay = 0.0; protected double ignitionDelay = 0.0;
protected IgnitionEvent ignitionEvent = IgnitionEvent.NEVER; protected IgnitionEvent ignitionEvent = IgnitionEvent.NEVER;
protected Coordinate position = Coordinate.ZERO; protected Coordinate position = Coordinate.ZERO;
protected double ignitionTime = 0.0; protected double ignitionTime = 0.0;
// comparison threshold
//private static final double EPSILON = 0.01;
protected int modID = 0; protected int modID = 0;
private final List<StateChangeListener> listeners = new ArrayList<StateChangeListener>(); private final List<StateChangeListener> listeners = new ArrayList<StateChangeListener>();
@ -39,6 +38,46 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
public boolean equals( Object other ){ public boolean equals( Object other ){
return (this==other); return (this==other);
} }
@Override
public Motor getMotor() {
throw new UnsupportedOperationException("Retrieve a motor from an immutable no-motors instance");
}
@Override
public MotorMount getMount() {
throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance");
}
@Override
public double getThrust() {
throw new UnsupportedOperationException("Trying to get thrust from an empty motor instance.");
}
@Override
public Coordinate getCM() {
throw new UnsupportedOperationException("Trying to get Center-of-Mass from an empty motor instance.");
}
@Override
public double getPropellantMass(){
throw new UnsupportedOperationException("Trying to get mass from an empty motor instance.");
}
@Override
public double getLongitudinalInertia() {
throw new UnsupportedOperationException("Trying to get inertia from an empty motor instance.");
}
@Override
public double getRotationalInertia() {
throw new UnsupportedOperationException("Trying to get inertia from an empty motor instance.");
}
@Override
public void step(double time, double acceleration, AtmosphericConditions cond) {
throw new UnsupportedOperationException("Cannot step an abstract base class");
}
}; };
protected MotorInstance() { protected MotorInstance() {
@ -61,25 +100,15 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
return this.ejectionDelay; return this.ejectionDelay;
} }
public void setMotor(Motor motor) { public void setMotor(Motor motor){}
throw new UnsupportedOperationException("Retrieve a motor from an immutable no-motors instance");
}
public Motor getMotor() { public abstract Motor getMotor();
throw new UnsupportedOperationException("Retrieve a motor from an immutable no-motors instance");
}
public void setEjectionDelay(double delay) { public void setEjectionDelay(double delay) {}
throw new UnsupportedOperationException("Trying to modify immutable no-motors configuration");
};
public MotorMount getMount() { public abstract MotorMount getMount();
throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance");
}
public void setMount(final MotorMount _mount) { public void setMount(final MotorMount _mount){}
throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance");
}
public Coordinate getOffset(){ public Coordinate getOffset(){
return this.position; return this.position;
@ -126,9 +155,7 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
* @param acceleration the average acceleration during the step. * @param acceleration the average acceleration during the step.
* @param cond the average atmospheric conditions during the step. * @param cond the average atmospheric conditions during the step.
*/ */
public void step(double time, double acceleration, AtmosphericConditions cond) { public abstract void step(double time, double acceleration, AtmosphericConditions cond);
// no-op
}
/** /**
@ -142,32 +169,30 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
/** /**
* Return the average thrust during the last step. * Return the average thrust during the last step.
*/ */
public double getThrust() { public abstract double getThrust();
return Double.NaN;
}
/** /**
* Return the average CG location during the last step. * Return the average CG location during the last step.
*/ */
public Coordinate getCG() { public Coordinate getCG() {
return Coordinate.NaN; return this.getCM();
} }
public abstract Coordinate getCM();
public abstract double getPropellantMass();
/** /**
* Return the average longitudinal moment of inertia during the last step. * Return the average longitudinal moment of inertia during the last step.
* This is the actual inertia, not the unit inertia! * This is the actual inertia, not the unit inertia!
*/ */
public double getLongitudinalInertia() { public abstract double getLongitudinalInertia();
return Double.NaN;
}
/** /**
* Return the average rotational moment of inertia during the last step. * Return the average rotational moment of inertia during the last step.
* This is the actual inertia, not the unit inertia! * This is the actual inertia, not the unit inertia!
*/ */
public double getRotationalInertia() { public abstract double getRotationalInertia();
return Double.NaN;
}
/** /**
* Return whether this motor still produces thrust. If this method returns false * Return whether this motor still produces thrust. If this method returns false

View File

@ -65,6 +65,16 @@ public class ThrustCurveMotorInstance extends MotorInstance {
return stepCG; return stepCG;
} }
@Override
public Coordinate getCM() {
return stepCG;
}
@Override
public double getPropellantMass(){
return (motor.getLaunchCG().weight - motor.getEmptyCG().weight);
}
@Override @Override
public Coordinate getOffset( ){ public Coordinate getOffset( ){
if( null == mount ){ if( null == mount ){

View File

@ -129,8 +129,9 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
cg = calc.getCG(status.getConfiguration(), MassCalcType.LAUNCH_MASS); cg = calc.getCG(status.getConfiguration(), MassCalcType.LAUNCH_MASS);
longitudinalInertia = calc.getLongitudinalInertia(status.getConfiguration(), MassCalcType.LAUNCH_MASS); longitudinalInertia = calc.getLongitudinalInertia(status.getConfiguration(), MassCalcType.LAUNCH_MASS);
rotationalInertia = calc.getRotationalInertia(status.getConfiguration(), MassCalcType.LAUNCH_MASS); rotationalInertia = calc.getRotationalInertia(status.getConfiguration(), MassCalcType.LAUNCH_MASS);
mass = new MassData(cg, rotationalInertia, longitudinalInertia);
propellantMass = calc.getPropellantMass(status.getConfiguration(), MassCalcType.LAUNCH_MASS); propellantMass = calc.getPropellantMass(status.getConfiguration(), MassCalcType.LAUNCH_MASS);
mass = new MassData(cg, longitudinalInertia, rotationalInertia, propellantMass); mass.setPropellantMass( propellantMass );
// Call post-listener // Call post-listener
mass = SimulationListenerHelper.firePostMassCalculation(status, mass); mass = SimulationListenerHelper.firePostMassCalculation(status, mass);
@ -144,9 +145,6 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
} }
/** /**
* Calculate the average thrust produced by the motors in the current configuration, allowing * Calculate the average thrust produced by the motors in the current configuration, allowing
* listeners to override. The average is taken between <code>status.time</code> and * listeners to override. The average is taken between <code>status.time</code> and