ElevationExtremumDetector.java

  1. /* Copyright 2002-2018 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.propagation.events;

  18. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.frames.TopocentricFrame;
  22. import org.orekit.frames.Transform;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.propagation.events.handlers.EventHandler;
  25. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  26. import org.orekit.utils.TimeStampedPVCoordinates;

  27. /** Detector for elevation extremum with respect to a ground point.
  28.  * <p>This detector identifies when a spacecraft reaches its
  29.  * extremum elevation with respect to a ground point.</p>
  30.  * <p>
  31.  * As in most cases only the elevation maximum is needed and the
  32.  * minimum is often irrelevant, this detector is often wrapped into
  33.  * an {@link EventSlopeFilter event slope filter} configured with
  34.  * {@link FilterType#TRIGGER_ONLY_DECREASING_EVENTS} (i.e. when the
  35.  * elevation derivative decreases from positive values to negative values,
  36.  * which correspond to a maximum). Setting up this filter saves some computation
  37.  * time as the elevation minimum occurrences are not even looked at. It is
  38.  * however still often necessary to do an additional filtering
  39.  * </p>
  40.  * @author Luc Maisonobe
  41.  * @since 7.1
  42.  */
  43. public class ElevationExtremumDetector extends AbstractDetector<ElevationExtremumDetector> {

  44.     /** Serializable UID. */
  45.     private static final long serialVersionUID = 20150909L;

  46.     /** Topocentric frame in which elevation should be evaluated. */
  47.     private final TopocentricFrame topo;

  48.     /** Build a new detector.
  49.      * <p>The new instance uses default values for maximal checking interval
  50.      * ({@link #DEFAULT_MAXCHECK}) and convergence threshold ({@link
  51.      * #DEFAULT_THRESHOLD}).</p>
  52.      * @param topo topocentric frame centered on ground point
  53.      */
  54.     public ElevationExtremumDetector(final TopocentricFrame topo) {
  55.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, topo);
  56.     }

  57.     /** Build a detector.
  58.      * @param maxCheck maximal checking interval (s)
  59.      * @param threshold convergence threshold (s)
  60.      * @param topo topocentric frame centered on ground point
  61.      */
  62.     public ElevationExtremumDetector(final double maxCheck, final double threshold,
  63.                                      final TopocentricFrame topo) {
  64.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing<ElevationExtremumDetector>(),
  65.              topo);
  66.     }

  67.     /** Private constructor with full parameters.
  68.      * <p>
  69.      * This constructor is private as users are expected to use the builder
  70.      * API with the various {@code withXxx()} methods to set up the instance
  71.      * in a readable manner without using a huge amount of parameters.
  72.      * </p>
  73.      * @param maxCheck maximum checking interval (s)
  74.      * @param threshold convergence threshold (s)
  75.      * @param maxIter maximum number of iterations in the event time search
  76.      * @param handler event handler to call at event occurrences
  77.      * @param topo topocentric frame centered on ground point
  78.      */
  79.     private ElevationExtremumDetector(final double maxCheck, final double threshold,
  80.                                       final int maxIter, final EventHandler<? super ElevationExtremumDetector> handler,
  81.                                       final TopocentricFrame topo) {
  82.         super(maxCheck, threshold, maxIter, handler);
  83.         this.topo = topo;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     protected ElevationExtremumDetector create(final double newMaxCheck, final double newThreshold,
  88.                                               final int newMaxIter,
  89.                                               final EventHandler<? super ElevationExtremumDetector> newHandler) {
  90.         return new ElevationExtremumDetector(newMaxCheck, newThreshold, newMaxIter, newHandler, topo);
  91.     }

  92.     /**
  93.      * Returns the topocentric frame centered on ground point.
  94.      * @return topocentric frame centered on ground point
  95.      */
  96.     public TopocentricFrame getTopocentricFrame() {
  97.         return this.topo;
  98.     }

  99.     /** Get the elevation value.
  100.      * @param s the current state information: date, kinematics, attitude
  101.      * @return spacecraft elevation
  102.      * @exception OrekitException if some specific error occurs
  103.      */
  104.     public double getElevation(final SpacecraftState s) throws OrekitException {
  105.         return topo.getElevation(s.getPVCoordinates().getPosition(), s.getFrame(), s.getDate());
  106.     }

  107.     /** Compute the value of the detection function.
  108.      * <p>
  109.      * The value is the spacecraft elevation first time derivative.
  110.      * </p>
  111.      * @param s the current state information: date, kinematics, attitude
  112.      * @return spacecraft elevation first time derivative
  113.      * @exception OrekitException if some specific error occurs
  114.      */
  115.     public double g(final SpacecraftState s) throws OrekitException {

  116.         // get position, velocity acceleration of spacecraft in topocentric frame
  117.         final Transform inertToTopo = s.getFrame().getTransformTo(topo, s.getDate());
  118.         final TimeStampedPVCoordinates pvTopo = inertToTopo.transformPVCoordinates(s.getPVCoordinates());

  119.         // convert the coordinates to DerivativeStructure based vector
  120.         // instead of having vector position, then vector velocity then vector acceleration
  121.         // we get one vector and each coordinate is a DerivativeStructure containing
  122.         // value, first time derivative (we don't need second time derivative here)
  123.         final FieldVector3D<DerivativeStructure> pvDS = pvTopo.toDerivativeStructureVector(1);

  124.         // compute elevation and its first time derivative
  125.         final DerivativeStructure elevation = pvDS.getZ().divide(pvDS.getNorm()).asin();

  126.         // return elevation first time derivative
  127.         return elevation.getPartialDerivative(1);

  128.     }

  129. }