[Fix] Fixed bug in RSE file loading ( XML-formatted engine description)
This patch is based off a thread from "The Rocketry Forum" ( http://www.rocketryforum.com/showthread.php?70475-Problems-with-custom-motors-in-OpenRocket ) . Complaint: Poster had a water-rocket engine file which would raise IOExceptions upon automatic load. (1) the original .rse motor file, posted in the thread above, has an invalid motor length. (2) The corrected .rse file follows at the end of this commit message. Bug: The mass auto-scaling code would over-estimate the mass loss, and declare a negative mass upon motor exhaustion. The negative mass is small (in this case, ~= -1E-16). However, this error is larger than the single-precision epsilon. Fix: Added a loop which checked for negative mass during the thrust curve, and reset those values back to zero. (AbstractMotorLoader.java:105) Also, expanded the number and detail level of some related exception reporting. (ThrustCurveMotor:137) ---- <engine-database> <engine-list> <engine mfg="Water" code="W90psi" Type="single-use" dia="18.001" len="200." initWt="800." propWt="800." delays="1000" auto-calc-mass="1" auto-calc-cg="0" avgThrust="280.059" peakThrust="428.329" throatDia="0." exitDia="0." Itot="21.284" burn-time="0.08" massFrac="99.88" Isp="2.71" tDiv="10" tStep="-1." tFix="1" FDiv="10" FStep="-1." FFix="1" mDiv="10" mStep="-1." mFix="1" cgDiv="10" cgStep="-1." cgFix="1"> <comments>Water Rocket, 90 psi, 800g</comments> <data> <eng-data t="0." f="0." m="800." cg="81.6327"/> <eng-data t="0.001" f="428.329" m="791.95" cg="89.1566"/> <eng-data t="0.005" f="405.382" m="729.279" cg="107.229"/> <eng-data t="0.008" f="383.711" m="684.79" cg="115.663"/> <eng-data t="0.016" f="346.742" m="574.971" cg="132.53"/> <eng-data t="0.023" f="319.972" m="487.264" cg="142.169"/> <eng-data t="0.031" f="294.476" m="394.885" cg="154.217"/> <eng-data t="0.041" f="267.705" m="289.234" cg="163.855"/> <eng-data t="0.051" f="244.759" m="192.927" cg="172.289"/> <eng-data t="0.059" f="229.462" m="121.63" cg="178.313"/> <eng-data t="0.067" f="215.439" m="54.742" cg="186.747"/> <eng-data t="0.072" f="203.966" m="15.3326" cg="189.157"/> <eng-data t="0.076" f="0." m="0." cg="192.857"/> </data> </engine> </engine-list> </engine-database>
This commit is contained in:
parent
43aa40c7a9
commit
2d1c843bfb
@ -15,7 +15,7 @@ import net.sf.openrocket.util.MathUtil;
|
||||
|
||||
public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
@ -40,7 +40,6 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
protected abstract List<Motor> load(Reader reader, String filename) throws IOException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the default charset to use when loading rocket files of this type.
|
||||
* <p>
|
||||
@ -52,11 +51,11 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
protected abstract Charset getDefaultCharset();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////// Helper methods //////////
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the mass of a motor at distinct points in time based on the
|
||||
* initial total mass, propellant weight and thrust.
|
||||
@ -88,6 +87,7 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
double f1 = thrust.get(i);
|
||||
|
||||
double dm = 0.5 * (f0 + f1) * (t1 - t0);
|
||||
|
||||
deltam.add(dm);
|
||||
totalMassChange += dm;
|
||||
t0 = t1;
|
||||
@ -102,10 +102,15 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
mass.add(total);
|
||||
}
|
||||
|
||||
// to correct negative mass error condition: (caused by rounding errors in the above loops)
|
||||
for (int mass_index = 0; mass_index < mass.size(); mass_index++) {
|
||||
if (mass.get(mass_index) < 0) {
|
||||
mass.set(mass_index, 0.0d);
|
||||
}
|
||||
}
|
||||
return mass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to remove a delay (or plugged) from the end of a motor designation,
|
||||
* if present.
|
||||
@ -121,7 +126,6 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to tokenize a string using whitespace as the delimiter.
|
||||
*/
|
||||
@ -168,7 +172,7 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static void finalizeThrustCurve(List<Double> time, List<Double> thrust,
|
||||
List... lists) {
|
||||
|
@ -135,8 +135,8 @@ public class RockSimMotorLoader extends AbstractMotorLoader {
|
||||
private final double initMass;
|
||||
private final double propMass;
|
||||
private final Motor.Type type;
|
||||
private boolean calculateMass;
|
||||
private boolean calculateCG;
|
||||
private boolean calculateMass = false;
|
||||
private boolean calculateCG = false;
|
||||
|
||||
private String description = "";
|
||||
|
||||
@ -324,8 +324,8 @@ public class RockSimMotorLoader extends AbstractMotorLoader {
|
||||
if (time == null || time.size() == 0)
|
||||
throw new SAXException("Illegal motor data");
|
||||
|
||||
|
||||
finalizeThrustCurve(time, force, mass, cg);
|
||||
|
||||
final int n = time.size();
|
||||
|
||||
if (hasIllegalValue(mass))
|
||||
@ -336,6 +336,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader {
|
||||
if (calculateMass) {
|
||||
mass = calculateMass(time, force, initMass, propMass);
|
||||
}
|
||||
|
||||
if (calculateCG) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
cg.set(i, length / 2);
|
||||
|
@ -134,11 +134,14 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
||||
if (c.isNaN()) {
|
||||
throw new IllegalArgumentException("Invalid CG " + c);
|
||||
}
|
||||
if (c.x < 0 || c.x > length) {
|
||||
throw new IllegalArgumentException("Invalid CG position " + c.x);
|
||||
if (c.x < 0) {
|
||||
throw new IllegalArgumentException("Invalid CG position " + String.format("%f", c.x) + ": CG is below the start of the motor.");
|
||||
}
|
||||
if (c.x > length) {
|
||||
throw new IllegalArgumentException("Invalid CG position: " + String.format("%f", c.x) + ": CG is above the end of the motor.");
|
||||
}
|
||||
if (c.weight < 0) {
|
||||
throw new IllegalArgumentException("Negative mass " + c.weight);
|
||||
throw new IllegalArgumentException("Negative mass " + c.weight + "at time=" + time[Arrays.asList(cg).indexOf(c)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user