From: plaa Date: Mon, 23 Jan 2012 19:03:24 +0000 (+0000) Subject: motor updates X-Git-Tag: upstream/12.03~1^2~104 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=b34816a005e47ead29ee43a74ebc15ecc0a41141;p=debian%2Fopenrocket motor updates git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@367 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/run.sh b/core/run.sh index 1828ef78..54ceeed1 100755 --- a/core/run.sh +++ b/core/run.sh @@ -14,5 +14,5 @@ while echo "$1" | grep -q "^-" ; do done -java -cp bin/:lib/miglayout15-swing.jar:lib/jcommon-1.0.16.jar:lib/jfreechart-1.0.13.jar:lib/iText-5.0.2.jar:. $JAVAOPTS net.sf.openrocket.startup.Startup "$@" +java -cp bin/:lib/miglayout15-swing.jar:lib/jcommon-1.0.16.jar:lib/jfreechart-1.0.13.jar:lib/iText-5.0.2.jar $JAVAOPTS net.sf.openrocket.startup.Startup "$@" diff --git a/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java b/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java index cbe517e7..df1ddecc 100644 --- a/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java +++ b/core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java @@ -22,8 +22,8 @@ public class RASPMotorLoader extends AbstractMotorLoader { public static final Charset CHARSET = Charset.forName(CHARSET_NAME); - - + + @Override protected Charset getDefaultCharset() { return CHARSET; @@ -197,7 +197,7 @@ public class RASPMotorLoader extends AbstractMotorLoader { motorDigest.update(DataType.MASS_SPECIFIC, totalW, totalW - propW); motorDigest.update(DataType.FORCE_PER_TIME, thrustArray); final String digest = motorDigest.getDigest(); - + try { Manufacturer m = Manufacturer.getManufacturer(manufacturer); diff --git a/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java b/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java index 5e04c98c..353695e0 100644 --- a/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java +++ b/core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java @@ -32,19 +32,19 @@ public class RockSimMotorLoader extends AbstractMotorLoader { public static final Charset CHARSET = Charset.forName(CHARSET_NAME); - + /** Any delay longer than this will be interpreted as a plugged motor. */ private static final int DELAY_LIMIT = 90; - + @Override protected Charset getDefaultCharset() { return CHARSET; } - + /** * Load a Motor from a RockSim motor definition file specified by the * Reader. The Reader is responsible for using the correct @@ -73,7 +73,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader { } - + /** * Initial handler for the RockSim engine files. */ @@ -234,7 +234,15 @@ public class RockSimMotorLoader extends AbstractMotorLoader { // Motor type str = attributes.get("Type"); - type = Motor.Type.fromName(str); + if ("single-use".equalsIgnoreCase(str)) { + type = Motor.Type.SINGLE; + } else if ("hybrid".equalsIgnoreCase(str)) { + type = Motor.Type.HYBRID; + } else if ("reloadable".equalsIgnoreCase(str)) { + type = Motor.Type.RELOAD; + } else { + type = Motor.Type.UNKNOWN; + } // Calculate mass str = attributes.get("auto-calc-mass"); @@ -315,7 +323,7 @@ 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(); @@ -340,7 +348,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader { cgArray[i] = new Coordinate(cg.get(i), 0, 0, mass.get(i)); } - + // Create the motor digest from all data available in the file MotorDigest motorDigest = new MotorDigest(); motorDigest.update(DataType.TIME_ARRAY, timeArray); @@ -352,10 +360,11 @@ public class RockSimMotorLoader extends AbstractMotorLoader { if (!calculateCG) { motorDigest.update(DataType.CG_PER_TIME, toArray(cg)); } + // FIXME: Should this use CG_SPECIFIC ??? motorDigest.update(DataType.FORCE_PER_TIME, thrustArray); final String digest = motorDigest.getDigest(); - + try { Manufacturer m = Manufacturer.getManufacturer(manufacturer); Motor.Type t = type; @@ -451,7 +460,7 @@ public class RockSimMotorLoader extends AbstractMotorLoader { } - + private static boolean hasIllegalValue(List list) { for (Double d : list) { if (d == null || d.isNaN() || d.isInfinite()) { diff --git a/core/src/net/sf/openrocket/motor/Motor.java b/core/src/net/sf/openrocket/motor/Motor.java index 21104f0d..744a6154 100644 --- a/core/src/net/sf/openrocket/motor/Motor.java +++ b/core/src/net/sf/openrocket/motor/Motor.java @@ -3,16 +3,16 @@ package net.sf.openrocket.motor; import net.sf.openrocket.util.Coordinate; public interface Motor { - + /** * Enum of rocket motor types. * * @author Sampo Niskanen */ public enum Type { - SINGLE("Single-use", "Single-use solid propellant motor"), - RELOAD("Reloadable", "Reloadable solid propellant motor"), - HYBRID("Hybrid", "Hybrid rocket motor engine"), + SINGLE("Single-use", "Single-use solid propellant motor"), + RELOAD("Reloadable", "Reloadable solid propellant motor"), + HYBRID("Hybrid", "Hybrid rocket motor engine"), UNKNOWN("Unknown", "Unknown motor type"); private final String name; @@ -23,21 +23,7 @@ public interface Motor { this.description = description; } - public static Type fromName( String name ) { - if ( name == null ) { - return UNKNOWN; - } - if ("single-use".equalsIgnoreCase(name)) { - return SINGLE; - } else if ("hybrid".equalsIgnoreCase(name)) { - return HYBRID; - } else if ("reloadable".equalsIgnoreCase(name)) { - return RELOAD; - } else { - return UNKNOWN; - } - } - + /** * Return a short name of this motor type. * @return a short name of the motor type. @@ -75,16 +61,16 @@ public interface Motor { */ public static final double MARGINAL_THRUST = 0.05; - - + + /** * Return the motor type. * * @return the motorType */ public Type getMotorType(); - - + + /** * Return the designation of the motor. * @@ -100,7 +86,7 @@ public interface Motor { */ public String getDesignation(double delay); - + /** * Return extra description for the motor. This may include for example * comments on the source of the thrust curve. The returned String @@ -117,7 +103,7 @@ public interface Motor { * @return the diameter */ public double getDiameter(); - + /** * Return the length of the motor. This should be a "characteristic" length, * and the exact definition may depend on the motor type. Typically this should @@ -129,21 +115,33 @@ public interface Motor { public double getLength(); public String getDigest(); - + public MotorInstance getInstance(); public Coordinate getLaunchCG(); + public Coordinate getEmptyCG(); + /** + * Return an estimate of the burn time of this motor, or NaN if an estimate is unavailable. + */ public double getBurnTimeEstimate(); + + /** + * Return an estimate of the average thrust of this motor, or NaN if an estimate is unavailable. + */ public double getAverageThrustEstimate(); + + /** + * Return an estimate of the maximum thrust of this motor, or NaN if an estimate is unavailable. + */ public double getMaxThrustEstimate(); - public double getTotalImpulseEstimate(); - public double[] getTimePoints(); - public double[] getThrustPoints(); - public Coordinate[] getCGPoints(); + /** + * Return an estimate of the total impulse of this motor, or NaN if an estimate is unavailable. + */ + public double getTotalImpulseEstimate(); } diff --git a/core/src/net/sf/openrocket/motor/MotorDigest.java b/core/src/net/sf/openrocket/motor/MotorDigest.java index e50cbf9f..92f01d3c 100644 --- a/core/src/net/sf/openrocket/motor/MotorDigest.java +++ b/core/src/net/sf/openrocket/motor/MotorDigest.java @@ -68,7 +68,23 @@ public class MotorDigest { } - public void update(DataType type, int... values) { + + public void update(DataType type, double... values) { + int multiplier = type.getMultiplier(); + + int[] intValues = new int[values.length]; + for (int i = 0; i < values.length; i++) { + double v = values[i]; + v = next(v); + v *= multiplier; + v = next(v); + intValues[i] = (int) Math.round(v); + } + update(type, intValues); + } + + + private void update(DataType type, int... values) { // Check for correct order if (lastOrder >= type.getOrder()) { @@ -91,23 +107,6 @@ public class MotorDigest { } - private void update(DataType type, int multiplier, double... values) { - - int[] intValues = new int[values.length]; - for (int i = 0; i < values.length; i++) { - double v = values[i]; - v = next(v); - v *= multiplier; - v = next(v); - intValues[i] = (int) Math.round(v); - } - update(type, intValues); - } - - public void update(DataType type, double... values) { - update(type, type.getMultiplier(), values); - } - private static double next(double v) { return v + Math.signum(v) * EPSILON; } @@ -123,7 +122,7 @@ public class MotorDigest { } - + private byte[] bytes(int value) { return new byte[] { (byte) ((value >>> 24) & 0xFF), (byte) ((value >>> 16) & 0xFF), @@ -138,7 +137,7 @@ public class MotorDigest { * @param m the motor to digest * @return the digest */ - public static String digestMotor(Motor m) { + public static String digestMotor(ThrustCurveMotor m) { // Create the motor digest from data available in RASP files MotorDigest motorDigest = new MotorDigest(); diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotorPlaceholder.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotorPlaceholder.java new file mode 100644 index 00000000..3245eb15 --- /dev/null +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotorPlaceholder.java @@ -0,0 +1,112 @@ +package net.sf.openrocket.motor; + +import net.sf.openrocket.util.BugException; +import net.sf.openrocket.util.Coordinate; + +public class ThrustCurveMotorPlaceholder implements Motor { + + private final Motor.Type type; + private final String manufacturer; + private final String designation; + private final double diameter; + private final double length; + private final String digest; + private final double delay; + private final double launchMass; + private final double emptyMass; + + + public ThrustCurveMotorPlaceholder(Type type, String manufacturer, String designation, double diameter, double length, + String digest, double delay, double launchMass, double emptyMass) { + this.type = type; + this.manufacturer = manufacturer; + this.designation = designation; + this.diameter = diameter; + this.length = length; + this.digest = digest; + this.delay = delay; + this.launchMass = launchMass; + this.emptyMass = emptyMass; + } + + + @Override + public Type getMotorType() { + return type; + } + + public String getManufacturer() { + return manufacturer; + } + + @Override + public String getDesignation() { + return designation; + } + + @Override + public String getDesignation(double designationDelay) { + return designation + "-" + ThrustCurveMotor.getDelayString(designationDelay); + } + + @Override + public String getDescription() { + return ""; + } + + @Override + public double getDiameter() { + return diameter; + } + + @Override + public double getLength() { + return length; + } + + @Override + public String getDigest() { + return digest; + } + + public double getDelay() { + return delay; + } + + @Override + public MotorInstance getInstance() { + throw new BugException("Called getInstance on PlaceholderMotor"); + } + + @Override + public Coordinate getLaunchCG() { + return new Coordinate(length / 2, 0, 0, launchMass); + } + + @Override + public Coordinate getEmptyCG() { + return new Coordinate(length / 2, 0, 0, emptyMass); + } + + @Override + public double getBurnTimeEstimate() { + return Double.NaN; + } + + @Override + public double getAverageThrustEstimate() { + return Double.NaN; + } + + @Override + public double getMaxThrustEstimate() { + return Double.NaN; + } + + @Override + public double getTotalImpulseEstimate() { + return Double.NaN; + } + + +}