ImpulseManeuver.java

  1. /* Copyright 2002-2013 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.forces.maneuvers;

  18. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  19. import org.apache.commons.math3.util.FastMath;
  20. import org.orekit.attitudes.Attitude;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.orbits.CartesianOrbit;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.propagation.events.AbstractReconfigurableDetector;
  25. import org.orekit.propagation.events.EventDetector;
  26. import org.orekit.propagation.events.handlers.EventHandler;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.Constants;
  29. import org.orekit.utils.PVCoordinates;

  30. /** Impulse maneuver model.
  31.  * <p>This class implements an impulse maneuver as a discrete event
  32.  * that can be provided to any {@link org.orekit.propagation.Propagator
  33.  * Propagator}.</p>
  34.  * <p>The maneuver is triggered when an underlying event generates a
  35.  * {@link org.orekit.propagation.events.EventDetector.Action#STOP STOP} event,
  36.  * in which case this class will generate a {@link
  37.  * org.orekit.propagation.events.EventDetector.Action#RESET_STATE RESET_STATE}
  38.  * event (the stop event from the underlying object is therefore filtered out).
  39.  * In the simple cases, the underlying event detector may be a basic
  40.  * {@link org.orekit.propagation.events.DateDetector date event}, but it
  41.  * can also be a more elaborate {@link
  42.  * org.orekit.propagation.events.ApsideDetector apside event} for apogee
  43.  * maneuvers for example.</p>
  44.  * <p>The maneuver is defined by a single velocity increment in satellite
  45.  * frame. The current attitude of the spacecraft, defined by the current
  46.  * spacecraft state, will be used to compute the velocity direction in
  47.  * inertial frame. A typical case for tangential maneuvers is to use a
  48.  * {@link org.orekit.attitudes.LofOffset LOF aligned} attitude provider for state propagation and a
  49.  * velocity increment along the +X satellite axis.</p>
  50.  * <p>Beware that the triggering event detector must behave properly both
  51.  * before and after maneuver. If for example a node detector is used to trigger
  52.  * an inclination maneuver and the maneuver change the orbit to an equatorial one,
  53.  * the node detector will fail just after the maneuver, being unable to find a
  54.  * node on an equatorial orbit! This is a real case that has been encountered
  55.  * during validation ...</p>
  56.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  57.      * @param <T> class type for the generic version
  58.  * @author Luc Maisonobe
  59.  */
  60. public class ImpulseManeuver<T extends EventDetector> extends AbstractReconfigurableDetector<ImpulseManeuver<T>> {

  61.     /** Serializable UID. */
  62.     private static final long serialVersionUID = 20131118L;

  63.     /** Triggering event. */
  64.     private final T trigger;

  65.     /** Velocity increment in satellite frame. */
  66.     private final Vector3D deltaVSat;

  67.     /** Specific impulse. */
  68.     private final double isp;

  69.     /** Engine exhaust velocity. */
  70.     private final double vExhaust;

  71.     /** Build a new instance.
  72.      * @param trigger triggering event
  73.      * @param deltaVSat velocity increment in satellite frame
  74.      * @param isp engine specific impulse (s)
  75.      */
  76.     public ImpulseManeuver(final T trigger, final Vector3D deltaVSat, final double isp) {
  77.         this(trigger.getMaxCheckInterval(), trigger.getThreshold(),
  78.              trigger.getMaxIterationCount(), new Handler<T>(),
  79.              trigger, deltaVSat, isp);
  80.     }

  81.     /** Private constructor with full parameters.
  82.      * <p>
  83.      * This constructor is private as users are expected to use the builder
  84.      * API with the various {@code withXxx()} methods to set up the instance
  85.      * in a readable manner without using a huge amount of parameters.
  86.      * </p>
  87.      * @param maxCheck maximum checking interval (s)
  88.      * @param threshold convergence threshold (s)
  89.      * @param maxIter maximum number of iterations in the event time search
  90.      * @param handler event handler to call at event occurrences
  91.      * @param trigger triggering event
  92.      * @param deltaVSat velocity increment in satellite frame
  93.      * @param isp engine specific impulse (s)
  94.      * @since 6.1
  95.      */
  96.     private ImpulseManeuver(final double maxCheck, final double threshold,
  97.                             final int maxIter, final EventHandler<ImpulseManeuver<T>> handler,
  98.                             final T trigger, final Vector3D deltaVSat,
  99.                             final double isp) {
  100.         super(maxCheck, threshold, maxIter, handler);
  101.         this.trigger   = trigger;
  102.         this.deltaVSat = deltaVSat;
  103.         this.isp       = isp;
  104.         this.vExhaust  = Constants.G0_STANDARD_GRAVITY * isp;
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     protected ImpulseManeuver<T> create(final double newMaxCheck, final double newThreshold,
  109.                                         final int newMaxIter, final EventHandler<ImpulseManeuver<T>> newHandler) {
  110.         return new ImpulseManeuver<T>(newMaxCheck, newThreshold, newMaxIter, newHandler,
  111.                                       trigger, deltaVSat, isp);
  112.     }

  113.     /** {@inheritDoc} */
  114.     public void init(final SpacecraftState s0, final AbsoluteDate t) {
  115.     }

  116.     /** {@inheritDoc} */
  117.     public double g(final SpacecraftState s) throws OrekitException {
  118.         return trigger.g(s);
  119.     }

  120.     /** Get the triggering event.
  121.      * @return triggering event
  122.      */
  123.     public T getTrigger() {
  124.         return trigger;
  125.     }

  126.     /** Get the velocity increment in satellite frame.
  127.     * @return velocity increment in satellite frame
  128.     */
  129.     public Vector3D getDeltaVSat() {
  130.         return deltaVSat;
  131.     }

  132.     /** Get the specific impulse.
  133.     * @return specific impulse
  134.     */
  135.     public double getIsp() {
  136.         return isp;
  137.     }

  138.     /** Local handler.
  139.      * @param <T> class type for the generic version
  140.      */
  141.     private static class Handler<T extends EventDetector> implements EventHandler<ImpulseManeuver<T>> {

  142.         /** {@inheritDoc} */
  143.         public EventHandler.Action eventOccurred(final SpacecraftState s, final ImpulseManeuver<T> im,
  144.                                                  final boolean increasing)
  145.             throws OrekitException {

  146.             // filter underlying event
  147.             final EventHandler.Action underlyingAction;
  148.             if (im.trigger instanceof AbstractReconfigurableDetector) {
  149.                 @SuppressWarnings("unchecked")
  150.                 final EventHandler<T> handler = ((AbstractReconfigurableDetector<T>) im.trigger).getHandler();
  151.                 underlyingAction = handler.eventOccurred(s, im.trigger, increasing);
  152.             } else {
  153.                 @SuppressWarnings("deprecation")
  154.                 final EventDetector.Action a = im.trigger.eventOccurred(s, increasing);
  155.                 underlyingAction = AbstractReconfigurableDetector.convert(a);
  156.             }

  157.             return (underlyingAction == Action.STOP) ? Action.RESET_STATE : Action.CONTINUE;

  158.         }

  159.         /** {@inheritDoc} */
  160.         @Override
  161.         public SpacecraftState resetState(final ImpulseManeuver<T> im, final SpacecraftState oldState)
  162.             throws OrekitException {

  163.             final AbsoluteDate date = oldState.getDate();
  164.             final Attitude attitude = oldState.getAttitude();

  165.             // convert velocity increment in inertial frame
  166.             final Vector3D deltaV = attitude.getRotation().applyInverseTo(im.deltaVSat);

  167.             // apply increment to position/velocity
  168.             final PVCoordinates oldPV = oldState.getPVCoordinates();
  169.             final PVCoordinates newPV = new PVCoordinates(oldPV.getPosition(),
  170.                                                           oldPV.getVelocity().add(deltaV));
  171.             final CartesianOrbit newOrbit =
  172.                     new CartesianOrbit(newPV, oldState.getFrame(), date, oldState.getMu());

  173.             // compute new mass
  174.             final double newMass = oldState.getMass() * FastMath.exp(-deltaV.getNorm() / im.vExhaust);

  175.             // pack everything in a new state
  176.             return new SpacecraftState(oldState.getOrbit().getType().convertType(newOrbit),
  177.                                        attitude, newMass);

  178.         }

  179.     }

  180. }