Merge pull request #1749 from JoePfeiffer/fix-jerk

Use absolute value of jerk in calculating time step in BasicLandingStepper, set minimum time step
This commit is contained in:
Sibo Van Gool 2022-10-17 11:05:55 +02:00 committed by GitHub
commit 4162e1d451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -13,6 +13,8 @@ import net.sf.openrocket.util.Quaternion;
public abstract class AbstractSimulationStepper implements SimulationStepper { public abstract class AbstractSimulationStepper implements SimulationStepper {
protected static final double MIN_TIME_STEP = 0.001;
/** /**
* Compute the atmospheric conditions, allowing listeners to override. * Compute the atmospheric conditions, allowing listeners to override.
* *

View File

@ -73,10 +73,12 @@ public class BasicLandingStepper extends AbstractSimulationStepper {
double timeStep = RECOVERY_TIME_STEP; double timeStep = RECOVERY_TIME_STEP;
// adjust based on change in acceleration (ie jerk) // adjust based on change in acceleration (ie jerk)
final double jerk = linearAcceleration.sub(status.getRocketAcceleration()).multiply(1.0/status.getPreviousTimeStep()).length(); final double jerk = Math.abs(linearAcceleration.sub(status.getRocketAcceleration()).multiply(1.0/status.getPreviousTimeStep()).length());
if (jerk > MathUtil.EPSILON) { if (jerk > MathUtil.EPSILON) {
timeStep = Math.min(timeStep, 1.0/jerk); timeStep = Math.min(timeStep, 1.0/jerk);
} }
// but don't let it get *too* small
timeStep = Math.max(timeStep, MIN_TIME_STEP);
// Perform Euler integration // Perform Euler integration
Coordinate newPosition = status.getRocketPosition().add(status.getRocketVelocity().multiply(timeStep)). Coordinate newPosition = status.getRocketPosition().add(status.getRocketVelocity().multiply(timeStep)).

View File

@ -58,9 +58,6 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
private static final double MAX_ROLL_RATE_CHANGE = 2 * Math.PI / 180; private static final double MAX_ROLL_RATE_CHANGE = 2 * Math.PI / 180;
private static final double MAX_PITCH_CHANGE = 4 * Math.PI / 180; private static final double MAX_PITCH_CHANGE = 4 * Math.PI / 180;
private static final double MIN_TIME_STEP = 0.001;
private Random random; private Random random;