import java.util.Arrays;
import java.util.Locale;
+import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
+import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Inertia;
public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
+ private static final LogHelper log = Application.getLogger();
public static final double MAX_THRUST = 10e6;
}
-
+ /**
+ * {@inheritDoc}
+ * <p>
+ * NOTE: In most cases you want to examine the motor type of the ThrustCurveMotorSet,
+ * not the ThrustCurveMotor itself.
+ */
@Override
public Type getMotorType() {
return type;
throw new BugException("Could not compute burn start time, maxThrust=" + maxThrust +
" limit=" + thrustLimit + " thrust=" + Arrays.toString(thrust));
}
- if (MathUtil.equals(thrust[pos], thrust[pos + 1])) {
+ if (MathUtil.equals(thrust[pos - 1], thrust[pos])) {
// For safety
- burnStart = (time[pos] + time[pos + 1]) / 2;
+ burnStart = (time[pos - 1] + time[pos]) / 2;
} else {
- burnStart = MathUtil.map(thrustLimit, thrust[pos], thrust[pos + 1],
- time[pos], time[pos + 1]);
+ burnStart = MathUtil.map(thrustLimit, thrust[pos - 1], thrust[pos], time[pos - 1], time[pos]);
}
double t0 = time[pos];
double t1 = time[pos + 1];
double f0 = thrust[pos];
- double f1 = thrust[pos];
+ double f1 = thrust[pos + 1];
- totalImpulse += (f0 + f1) / 2 * (t1 - t0);
+ totalImpulse += (t1 - t0) * (f0 + f1) / 2;
if (t0 < burnStart && t1 > burnStart) {
double fStart = MathUtil.map(burnStart, t0, t1, f0, f1);
private Coordinate instCG;
private final double unitRotationalInertia;
- private final double unitLongitudalInertia;
+ private final double unitLongitudinalInertia;
private int modID = 0;
public ThrustCurveMotorInstance() {
+ log.debug("ThrustCurveMotor: Creating motor instance of " + ThrustCurveMotor.this);
position = 0;
prevTime = 0;
instThrust = 0;
instCG = cg[0];
stepCG = cg[0];
unitRotationalInertia = Inertia.filledCylinderRotational(getDiameter() / 2);
- unitLongitudalInertia = Inertia.filledCylinderLongitudal(getDiameter() / 2, getLength());
+ unitLongitudinalInertia = Inertia.filledCylinderLongitudinal(getDiameter() / 2, getLength());
}
@Override
}
@Override
- public double getLongitudalInertia() {
- return unitLongitudalInertia * stepCG.weight;
+ public double getLongitudinalInertia() {
+ return unitLongitudinalInertia * stepCG.weight;
}
@Override
@Override
public void step(double nextTime, double acceleration, AtmosphericConditions cond) {
- System.out.println("MOTOR: Stepping instance " + this + " to time " + nextTime);
-
if (!(nextTime >= prevTime)) {
// Also catches NaN
throw new IllegalArgumentException("Stepping backwards in time, current=" +
prevTime + " new=" + nextTime);
}
if (MathUtil.equals(prevTime, nextTime)) {
- System.out.println("Same time as earlier");
return;
}
modID++;
if (position >= time.length - 1) {
- System.out.println("Thrust has ended");
// Thrust has ended
prevTime = nextTime;
stepThrust = 0;
if (position < time.length - 1) {
nextCG = MathUtil.map(nextTime, time[position], time[position + 1],
cg[position], cg[position + 1]);
-
- System.out.println("nextTime=" + nextTime +
- " time[position]=" + time[position] +
- " time[position+1]=" + time[position + 1] +
- " mass[position]=" + cg[position].weight * 1000 +
- " mass[position+1]=" + cg[position + 1].weight * 1000 +
- " result=" + nextCG.weight * 1000 +
- " position=" + position);
} else {
nextCG = cg[cg.length - 1];
}
stepCG = instCG.add(nextCG).multiply(0.5);
- System.out.println("instMass=" + instCG.weight + " nextMass=" + nextCG.weight + " stepMass=" + stepCG.weight);
instCG = nextCG;
// Update time