Merge pull request #208 from teyrana/master
[Fix] Fixed bug in RSE file loading ( XML-formatted engine description)
This commit is contained in:
commit
1c48d69c8c
@ -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>
|
||||
@ -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;
|
||||
@ -99,13 +99,16 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
scale = prop / totalMassChange;
|
||||
for (double dm : deltam) {
|
||||
total -= dm * scale;
|
||||
mass.add(total);
|
||||
// to correct negative mass error condition: (caused by rounding errors in the above loop)
|
||||
if (total < 0) {
|
||||
total = 0;
|
||||
}
|
||||
mass.add(total);
|
||||
|
||||
}
|
||||
return mass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to remove a delay (or plugged) from the end of a motor designation,
|
||||
* if present.
|
||||
@ -121,7 +124,6 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to tokenize a string using whitespace as the delimiter.
|
||||
*/
|
||||
|
@ -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)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.sf.openrocket.file.motor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -16,6 +18,7 @@ public class TestMotorLoader {
|
||||
|
||||
private static final String DIGEST1 = "e523030bc96d5e63313b5723aaea267d";
|
||||
private static final String DIGEST2 = "6a41f0f10b7283793eb0e6b389753729";
|
||||
private static final String DIGEST3 = "e3164a735f9a50500f2725f0a33d246b";
|
||||
|
||||
|
||||
@Test
|
||||
@ -25,7 +28,7 @@ public class TestMotorLoader {
|
||||
test(loader, "test1.eng", DIGEST1);
|
||||
test(loader, "test2.rse", DIGEST2);
|
||||
test(loader, "test.zip", DIGEST2, DIGEST1);
|
||||
|
||||
test(loader, "test3.rse", DIGEST3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -38,6 +41,11 @@ public class TestMotorLoader {
|
||||
test(new RockSimMotorLoader(), "test2.rse", DIGEST2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRocksimMotorLoader3() throws IOException {
|
||||
test(new RockSimMotorLoader(), "test3.rse", DIGEST3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZipMotorLoader() throws IOException {
|
||||
test(new ZipFileMotorLoader(), "test.zip", DIGEST2, DIGEST1);
|
||||
|
27
core/test/net/sf/openrocket/file/motor/test3.rse
Normal file
27
core/test/net/sf/openrocket/file/motor/test3.rse
Normal file
@ -0,0 +1,27 @@
|
||||
<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>
|
Loading…
x
Reference in New Issue
Block a user