/** * Return the next flight event to handle, or null if no more events should be handled. This * method jumps the simulation time forward in case no motors have been ignited. The flight event * is removed from the event queue. * * @return the flight event to handle, or null */ private FlightEvent nextEvent() { EventQueue queue = currentStatus.getEventQueue(); FlightEvent event = queue.peek(); if (event == null) return null; // Jump to event if no motors have been ignited if (!currentStatus.isMotorIgnited() && event.getTime() > currentStatus.getSimulationTime()) { currentStatus.setSimulationTime(event.getTime()); } if (event.getTime() <= currentStatus.getSimulationTime()) { return queue.poll(); } else { return null; } }
private SimulationStatus initialStatus( Configuration configuration, MotorInstanceConfiguration motorConfiguration, SimulationConditions simulationConditions, FlightData flightData) { SimulationStatus init = new SimulationStatus(); init.setSimulationConditions(simulationConditions); init.setConfiguration(configuration); init.setMotorConfiguration(motorConfiguration); init.setSimulationTime(0); init.setPreviousTimeStep(simulationConditions.getTimeStep()); init.setRocketPosition(Coordinate.NUL); init.setRocketVelocity(Coordinate.NUL); init.setRocketWorldPosition(simulationConditions.getLaunchSite()); // Initialize to roll angle with least stability w.r.t. the wind Quaternion o; FlightConditions cond = new FlightConditions(configuration); simulationConditions.getAerodynamicCalculator().getWorstCP(configuration, cond, null); double angle = -cond.getTheta() - simulationConditions.getLaunchRodDirection(); o = Quaternion.rotation(new Coordinate(0, 0, angle)); // Launch rod angle and direction o = o.multiplyLeft( Quaternion.rotation(new Coordinate(0, simulationConditions.getLaunchRodAngle(), 0))); o = o.multiplyLeft( Quaternion.rotation( new Coordinate(0, 0, simulationConditions.getLaunchRodDirection()))); init.setRocketOrientationQuaternion(o); init.setRocketRotationVelocity(Coordinate.NUL); /* * Calculate the effective launch rod length taking into account launch lugs. * If no lugs are found, assume a tower launcher of full length. */ double length = simulationConditions.getLaunchRodLength(); double lugPosition = Double.NaN; for (RocketComponent c : configuration) { if (c instanceof LaunchLug) { double pos = c.toAbsolute(new Coordinate(c.getLength()))[0].x; if (Double.isNaN(lugPosition) || pos > lugPosition) { lugPosition = pos; } } } if (!Double.isNaN(lugPosition)) { double maxX = 0; for (Coordinate c : configuration.getBounds()) { if (c.x > maxX) maxX = c.x; } if (maxX >= lugPosition) { length = Math.max(0, length - (maxX - lugPosition)); } } init.setEffectiveLaunchRodLength(length); init.setSimulationStartWallTime(System.nanoTime()); init.setMotorIgnited(false); init.setLiftoff(false); init.setLaunchRodCleared(false); init.setApogeeReached(false); init.getEventQueue() .add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket())); init.setFlightData(new FlightDataBranch("MAIN", FlightDataType.TYPE_TIME)); init.setWarnings(flightData.getWarningSet()); return init; }