Export RASAero motor with designation from RASAero database
This commit is contained in:
parent
be7d9c4e54
commit
6b4c18e0d8
@ -2,6 +2,8 @@ package net.sf.openrocket.file.motor;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -28,7 +30,10 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
protected Charset getDefaultCharset() {
|
protected Charset getDefaultCharset() {
|
||||||
return CHARSET;
|
return CHARSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ThrustCurveMotor.Builder> load(InputStream stream, String filename, boolean removeDelayFromDesignation) throws IOException {
|
||||||
|
return load(new InputStreamReader(stream, getDefaultCharset()), filename, removeDelayFromDesignation);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a <code>Motor</code> from a RASP file specified by the <code>Reader</code>.
|
* Load a <code>Motor</code> from a RASP file specified by the <code>Reader</code>.
|
||||||
@ -38,11 +43,11 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
* is calculated from the thrust curve by assuming a constant exhaust velocity.
|
* is calculated from the thrust curve by assuming a constant exhaust velocity.
|
||||||
*
|
*
|
||||||
* @param reader the source of the file.
|
* @param reader the source of the file.
|
||||||
|
* @param removeDelayFromDesignation if true, the motor delay will be left out of the motor designation (e.g. "B6" instead of "B6-0")
|
||||||
* @return a list of the {@link Motor} objects defined in the file.
|
* @return a list of the {@link Motor} objects defined in the file.
|
||||||
* @throws IOException if an I/O error occurs or if the file format is illegal.
|
* @throws IOException if an I/O error occurs or if the file format is illegal.
|
||||||
*/
|
*/
|
||||||
@Override
|
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename, boolean removeDelayFromDesignation) throws IOException {
|
||||||
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename) throws IOException {
|
|
||||||
List<ThrustCurveMotor.Builder> motors = new ArrayList<>();
|
List<ThrustCurveMotor.Builder> motors = new ArrayList<>();
|
||||||
BufferedReader in = new BufferedReader(reader);
|
BufferedReader in = new BufferedReader(reader);
|
||||||
|
|
||||||
@ -153,7 +158,7 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
delayArray[i] = delays.get(i);
|
delayArray[i] = delays.get(i);
|
||||||
}
|
}
|
||||||
motors.add(createRASPMotor(manufacturer, designation, comment,
|
motors.add(createRASPMotor(manufacturer, designation, comment,
|
||||||
length, diameter, delayArray, propW, totalW, time, thrust));
|
length, diameter, delayArray, propW, totalW, time, thrust, removeDelayFromDesignation));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -164,6 +169,11 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
|
|
||||||
return motors;
|
return motors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename) throws IOException {
|
||||||
|
return load(reader, filename, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,7 +182,7 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
*/
|
*/
|
||||||
private static ThrustCurveMotor.Builder createRASPMotor(String manufacturer, String designation,
|
private static ThrustCurveMotor.Builder createRASPMotor(String manufacturer, String designation,
|
||||||
String comment, double length, double diameter, double[] delays,
|
String comment, double length, double diameter, double[] delays,
|
||||||
double propW, double totalW, List<Double> time, List<Double> thrust)
|
double propW, double totalW, List<Double> time, List<Double> thrust, boolean removeDelayFromDesignation)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
// Add zero time/thrust if necessary
|
// Add zero time/thrust if necessary
|
||||||
@ -188,8 +198,10 @@ public class RASPMotorLoader extends AbstractMotorLoader {
|
|||||||
thrustArray[i] = thrust.get(i);
|
thrustArray[i] = thrust.get(i);
|
||||||
cgArray[i] = new Coordinate(length / 2, 0, 0, mass.get(i));
|
cgArray[i] = new Coordinate(length / 2, 0, 0, mass.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
designation = removeDelay(designation);
|
if (removeDelayFromDesignation) {
|
||||||
|
designation = removeDelay(designation);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the motor digest from data available in RASP files
|
// Create the motor digest from data available in RASP files
|
||||||
MotorDigest motorDigest = new MotorDigest();
|
MotorDigest motorDigest = new MotorDigest();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.sf.openrocket.file.rasaero;
|
package net.sf.openrocket.file.rasaero;
|
||||||
|
|
||||||
|
import net.sf.openrocket.file.motor.AbstractMotorLoader;
|
||||||
import net.sf.openrocket.logging.WarningSet;
|
import net.sf.openrocket.logging.WarningSet;
|
||||||
import net.sf.openrocket.motor.Manufacturer;
|
import net.sf.openrocket.motor.Manufacturer;
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
@ -389,27 +390,24 @@ public class RASAeroCommonConstants {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Format an OpenRocket motor as a RASAero motor.
|
* Format an OpenRocket motor as a RASAero motor.
|
||||||
* @param motors list of available RASAero motors
|
* @param RASAeroMotors list of available RASAero motors
|
||||||
* @param ORMotor OpenRocket motor
|
* @param ORMotor OpenRocket motor
|
||||||
* @param motorConfig motor configuration of the selected motor
|
|
||||||
* @return a RASAero String representation of a motor
|
* @return a RASAero String representation of a motor
|
||||||
*/
|
*/
|
||||||
public static String OPENROCKET_TO_RASAERO_MOTOR(List<ThrustCurveMotor> motors, Motor ORMotor, MotorConfiguration motorConfig,
|
public static String OPENROCKET_TO_RASAERO_MOTOR(List<ThrustCurveMotor> RASAeroMotors, Motor ORMotor,
|
||||||
WarningSet warnings) {
|
WarningSet warnings) {
|
||||||
if (!(ORMotor instanceof ThrustCurveMotor) || motorConfig == null) {
|
if (!(ORMotor instanceof ThrustCurveMotor)) {
|
||||||
log.debug("RASAero motor not found: not a thrust curve motor");
|
log.debug("RASAero motor not found: not a thrust curve motor");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ThrustCurveMotor motor : motors) {
|
for (ThrustCurveMotor RASAeroMotor : RASAeroMotors) {
|
||||||
if (ORMotor.getDesignation().equals(motor.getDesignation()) &&
|
String RASAeroDesignation = AbstractMotorLoader.removeDelay(RASAeroMotor.getDesignation());
|
||||||
((ThrustCurveMotor) ORMotor).getManufacturer().matches(motor.getManufacturer().getDisplayName())) {
|
if (ORMotor.getDesignation().equals(RASAeroDesignation) &&
|
||||||
String motorName = motor.getDesignation();
|
((ThrustCurveMotor) ORMotor).getManufacturer().matches(RASAeroMotor.getManufacturer().getDisplayName())) {
|
||||||
if (motorConfig.getEjectionDelay() == 0) {
|
String motorName = RASAeroMotor.getDesignation();
|
||||||
motorName += "-0";
|
log.debug(String.format("RASAero RASAeroMotor found: %s", motorName));
|
||||||
}
|
return motorName + " (" + OPENROCKET_TO_RASAERO_MANUFACTURER(RASAeroMotor.getManufacturer()) + ")";
|
||||||
log.debug(String.format("RASAero motor found: %s", motorName));
|
|
||||||
return motorName + " (" + OPENROCKET_TO_RASAERO_MANUFACTURER(motor.getManufacturer()) + ")";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.sf.openrocket.file.rasaero;
|
package net.sf.openrocket.file.rasaero;
|
||||||
|
|
||||||
import net.sf.openrocket.file.motor.GeneralMotorLoader;
|
import net.sf.openrocket.file.motor.GeneralMotorLoader;
|
||||||
|
import net.sf.openrocket.file.motor.RASPMotorLoader;
|
||||||
import net.sf.openrocket.logging.WarningSet;
|
import net.sf.openrocket.logging.WarningSet;
|
||||||
import net.sf.openrocket.database.motor.ThrustCurveMotorSet;
|
import net.sf.openrocket.database.motor.ThrustCurveMotorSet;
|
||||||
import net.sf.openrocket.file.motor.AbstractMotorLoader;
|
import net.sf.openrocket.file.motor.AbstractMotorLoader;
|
||||||
@ -69,23 +70,23 @@ public abstract class RASAeroMotorsLoader {
|
|||||||
public static List<ThrustCurveMotor> loadAllRASAeroMotors(WarningSet warnings) throws RuntimeException {
|
public static List<ThrustCurveMotor> loadAllRASAeroMotors(WarningSet warnings) throws RuntimeException {
|
||||||
List<ThrustCurveMotor> RASAeroMotors = new ArrayList<>();
|
List<ThrustCurveMotor> RASAeroMotors = new ArrayList<>();
|
||||||
|
|
||||||
GeneralMotorLoader loader = new GeneralMotorLoader();
|
RASPMotorLoader loader = new RASPMotorLoader();
|
||||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||||
String fileName = "RASAero_Motors.eng";
|
String fileName = "RASAero_Motors.eng";
|
||||||
InputStream is = classloader.getResourceAsStream("datafiles/thrustcurves/RASAero/" + fileName);
|
InputStream is = classloader.getResourceAsStream("datafiles/thrustcurves/RASAero/" + fileName);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
throw new RuntimeException("Could not find " + fileName);
|
throw new RuntimeException("Could not find " + fileName);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
List<ThrustCurveMotor.Builder> motors = loader.load(is, fileName);
|
List<ThrustCurveMotor.Builder> motors = loader.load(is, fileName, false);
|
||||||
for (ThrustCurveMotor.Builder builder : motors) {
|
for (ThrustCurveMotor.Builder builder : motors) {
|
||||||
RASAeroMotors.add(builder.build());
|
RASAeroMotors.add(builder.build());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
warnings.add("Error during motor loading: " + e.getMessage());
|
warnings.add("Error during motor loading: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return RASAeroMotors;
|
return RASAeroMotors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,7 +180,7 @@ public class SimulationDTO {
|
|||||||
switch (stageNr) {
|
switch (stageNr) {
|
||||||
// Sustainer
|
// Sustainer
|
||||||
case 0:
|
case 0:
|
||||||
setSustainerEngine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, motorConfig, warnings));
|
setSustainerEngine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, warnings));
|
||||||
|
|
||||||
// Calculate mass & CG of sustainer
|
// Calculate mass & CG of sustainer
|
||||||
CGCalcConfig.setOnlyStage(0);
|
CGCalcConfig.setOnlyStage(0);
|
||||||
@ -202,7 +202,7 @@ public class SimulationDTO {
|
|||||||
break;
|
break;
|
||||||
// Booster 1
|
// Booster 1
|
||||||
case 1:
|
case 1:
|
||||||
setBooster1Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, motorConfig, warnings));
|
setBooster1Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, warnings));
|
||||||
|
|
||||||
// Calculate mass & CG of sustainer + booster 1 combined
|
// Calculate mass & CG of sustainer + booster 1 combined
|
||||||
CGCalcConfig.setOnlyStage(0);
|
CGCalcConfig.setOnlyStage(0);
|
||||||
@ -234,7 +234,7 @@ public class SimulationDTO {
|
|||||||
break;
|
break;
|
||||||
// Booster 2
|
// Booster 2
|
||||||
case 2:
|
case 2:
|
||||||
setBooster2Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, motorConfig, warnings));
|
setBooster2Engine(RASAeroCommonConstants.OPENROCKET_TO_RASAERO_MOTOR(motors, motor, warnings));
|
||||||
|
|
||||||
// Calculate mass & CG of sustainer + booster 1 + booster 2 combined
|
// Calculate mass & CG of sustainer + booster 1 + booster 2 combined
|
||||||
CGCalcConfig.setOnlyStage(0);
|
CGCalcConfig.setOnlyStage(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user