motor updates
authorplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Mon, 23 Jan 2012 19:03:24 +0000 (19:03 +0000)
committerplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Mon, 23 Jan 2012 19:03:24 +0000 (19:03 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@367 180e2498-e6e9-4542-8430-84ac67f01cd8

core/run.sh
core/src/net/sf/openrocket/file/motor/RASPMotorLoader.java
core/src/net/sf/openrocket/file/motor/RockSimMotorLoader.java
core/src/net/sf/openrocket/motor/Motor.java
core/src/net/sf/openrocket/motor/MotorDigest.java
core/src/net/sf/openrocket/motor/ThrustCurveMotorPlaceholder.java [new file with mode: 0644]

index 1828ef78ca36b64d4362d6671d1f6091f40085b2..54ceeed1316a4f251ec794a642b8484e189ab9db 100755 (executable)
@@ -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 "$@"
 
index cbe517e74d6d917506207b18a82112d8ef410337..df1ddeccb4f96e859d38753ad6d04050bd05b1ba 100644 (file)
@@ -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);
index 5e04c98c5c2be4f1eb790b8a1e4cd998a8c38df0..353695e0cc132dc32d28c9837861ba731fc22337 100644 (file)
@@ -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 <code>Motor</code> from a RockSim motor definition file specified by the 
         * <code>Reader</code>. The <code>Reader</code> 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<Double> list) {
                for (Double d : list) {
                        if (d == null || d.isNaN() || d.isInfinite()) {
index 21104f0d6e6f3259bce8e118c01e732b6a23aa5a..744a6154ebfad26caf73d1c9c20d0b936cdea99d 100644 (file)
@@ -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 <sampo.niskanen@iki.fi>
         */
        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 <code>String</code>
@@ -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();
        
 }
index e50cbf9f2197aac9d56112c901035380c5a7dc6f..92f01d3c001639ed40d8c930ba1c2fc9c8a73074 100644 (file)
@@ -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 (file)
index 0000000..3245eb1
--- /dev/null
@@ -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;
+       }
+       
+       
+}