Fixes to make simulations finally work again.

This commit is contained in:
Kevin Ruland 2016-01-16 22:14:09 -06:00
parent dbde8a5a40
commit e174e4f0f6
5 changed files with 21 additions and 5 deletions

View File

@ -43,15 +43,14 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
public MotorState getSimulationState() { public MotorState getSimulationState() {
MotorState state = motor.getNewInstance(); MotorState state = motor.getNewInstance();
state.setEjectionDelay( this.ejectionDelay );
if( ignitionOveride ) { if( ignitionOveride ) {
state.setIgnitionEvent( this.ignitionEvent ); state.setIgnitionEvent( this.ignitionEvent );
state.setIgnitionDelay( this.ignitionDelay ); state.setIgnitionDelay( this.ignitionDelay );
state.setEjectionDelay( this.ejectionDelay );
} else { } else {
MotorConfiguration defInstance = mount.getDefaultMotorInstance(); MotorConfiguration defInstance = mount.getDefaultMotorInstance();
state.setIgnitionEvent( defInstance.ignitionEvent ); state.setIgnitionEvent( defInstance.ignitionEvent );
state.setIgnitionDelay( defInstance.ignitionDelay ); state.setIgnitionDelay( defInstance.ignitionDelay );
state.setEjectionDelay( defInstance.ejectionDelay );
} }
state.setMount( mount ); state.setMount( mount );
state.setId( id ); state.setId( id );
@ -70,7 +69,7 @@ public class MotorConfiguration implements FlightConfigurableParameter<MotorConf
if( motor == null ){ if( motor == null ){
return EMPTY_DESCRIPTION; return EMPTY_DESCRIPTION;
}else{ }else{
return this.motor.getDesignation() + " - " + this.getEjectionDelay(); return this.motor.getDesignation() + "-" + (int)this.getEjectionDelay();
} }
} }

View File

@ -4,6 +4,7 @@ import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.simulation.MotorState; import net.sf.openrocket.simulation.MotorState;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Inertia; import net.sf.openrocket.util.Inertia;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
@ -15,7 +16,7 @@ public class ThrustCurveMotorState implements MotorState {
protected MotorMount mount = null; protected MotorMount mount = null;
protected MotorInstanceId id = null; protected MotorInstanceId id = null;
private double ignitionTime; private double ignitionTime = -1;
private double ignitionDelay; private double ignitionDelay;
private IgnitionEvent ignitionEvent; private IgnitionEvent ignitionEvent;
private double ejectionDelay; private double ejectionDelay;
@ -56,6 +57,15 @@ public class ThrustCurveMotorState implements MotorState {
} }
@Override
public ThrustCurveMotorState clone() {
try {
return (ThrustCurveMotorState) super.clone();
} catch (CloneNotSupportedException e) {
throw new BugException("CloneNotSupportedException", e);
}
}
@Override @Override
public double getIgnitionTime() { public double getIgnitionTime() {
return ignitionTime; return ignitionTime;

View File

@ -174,6 +174,9 @@ public abstract class AbstractSimulationStepper implements SimulationStepper {
final double currentTime = status.getSimulationTime() + timestep; final double currentTime = status.getSimulationTime() + timestep;
Collection<MotorState> activeMotorList = status.getActiveMotors(); Collection<MotorState> activeMotorList = status.getActiveMotors();
for (MotorState currentMotorInstance : activeMotorList ) { for (MotorState currentMotorInstance : activeMotorList ) {
if ( !stepMotors ) {
currentMotorInstance = currentMotorInstance.clone();
}
// old: transplanted from MotorInstanceConfiguration // old: transplanted from MotorInstanceConfiguration
double instanceTime = currentTime - currentMotorInstance.getIgnitionTime(); double instanceTime = currentTime - currentMotorInstance.getIgnitionTime();
if (instanceTime >= 0) { if (instanceTime >= 0) {

View File

@ -5,7 +5,7 @@ import net.sf.openrocket.motor.MotorInstanceId;
import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
public interface MotorState { public interface MotorState extends Cloneable {
public void step(double nextTime, double acceleration, AtmosphericConditions cond); public void step(double nextTime, double acceleration, AtmosphericConditions cond);
public double getThrust(); public double getThrust();
@ -28,4 +28,7 @@ public interface MotorState {
public double getEjectionDelay(); public double getEjectionDelay();
public void setEjectionDelay( double delay); public void setEjectionDelay( double delay);
public MotorState clone();
} }

View File

@ -182,6 +182,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
double thrustEstimate = store.thrustForce; double thrustEstimate = store.thrustForce;
store.thrustForce = calculateThrust(status, store.timestep, store.longitudinalAcceleration, store.thrustForce = calculateThrust(status, store.timestep, store.longitudinalAcceleration,
store.atmosphericConditions, true); store.atmosphericConditions, true);
log.trace("Thrust at time " + store.timestep + " thrustForce = " + store.thrustForce);
double thrustDiff = Math.abs(store.thrustForce - thrustEstimate); double thrustDiff = Math.abs(store.thrustForce - thrustEstimate);
// Log if difference over 1%, recompute if over 10% // Log if difference over 1%, recompute if over 10%
if (thrustDiff > 0.01 * thrustEstimate) { if (thrustDiff > 0.01 * thrustEstimate) {