AltitudeDetector.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.orekit.bodies.BodyShape;
  19. import org.orekit.bodies.GeodeticPoint;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.propagation.SpacecraftState;
  23. import org.orekit.propagation.events.handlers.EventHandler;
  24. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  25. import org.orekit.utils.PVCoordinates;

  26. /** Finder for satellite altitude crossing events.
  27.  * <p>This class finds altitude events (i.e. satellite crossing
  28.  * a predefined altitude level above ground).</p>
  29.  * <p>The default implementation behavior is to {@link
  30.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE
  31.  * continue} propagation when ascending and to {@link
  32.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop}
  33.  * propagation when descending. This can be changed by calling
  34.  * {@link #withHandler(EventHandler)} after construction.</p>
  35.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  36.  * @author Luc Maisonobe
  37.  */
  38. public class AltitudeDetector extends AbstractDetector<AltitudeDetector> {

  39.     /** Serializable UID. */
  40.     private static final long serialVersionUID = 20131118L;

  41.     /** Threshold altitude value (m). */
  42.     private final double altitude;

  43.     /** Body shape with respect to which altitude should be evaluated. */
  44.     private final BodyShape bodyShape;

  45.     /** Build a new altitude detector.
  46.      * <p>This simple constructor takes default values for maximal checking
  47.      *  interval ({@link #DEFAULT_MAXCHECK}) and convergence threshold
  48.      * ({@link #DEFAULT_THRESHOLD}).</p>
  49.      * @param altitude threshold altitude value
  50.      * @param bodyShape body shape with respect to which altitude should be evaluated
  51.      */
  52.     public AltitudeDetector(final double altitude, final BodyShape bodyShape) {
  53.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, altitude, bodyShape);
  54.     }

  55.     /** Build a new altitude detector.
  56.      * <p>This simple constructor takes default value for convergence threshold
  57.      * ({@link #DEFAULT_THRESHOLD}).</p>
  58.      * <p>The maximal interval between altitude checks should
  59.      * be smaller than the half duration of the minimal pass to handle,
  60.      * otherwise some short passes could be missed.</p>
  61.      * @param maxCheck maximal checking interval (s)
  62.      * @param altitude threshold altitude value (m)
  63.      * @param bodyShape body shape with respect to which altitude should be evaluated
  64.      */
  65.     public AltitudeDetector(final double maxCheck,
  66.                             final double altitude,
  67.                             final BodyShape bodyShape) {
  68.         this(maxCheck, DEFAULT_THRESHOLD, altitude, bodyShape);
  69.     }

  70.     /** Build a new altitude detector.
  71.      * <p>The maximal interval between altitude checks should
  72.      * be smaller than the half duration of the minimal pass to handle,
  73.      * otherwise some short passes could be missed.</p>
  74.      * <p>The maximal interval between altitude checks should
  75.      * be smaller than the half duration of the minimal pass to handle,
  76.      * otherwise some short passes could be missed.</p>
  77.      * @param maxCheck maximal checking interval (s)
  78.      * @param threshold convergence threshold (s)
  79.      * @param altitude threshold altitude value (m)
  80.      * @param bodyShape body shape with respect to which altitude should be evaluated
  81.      */
  82.     public AltitudeDetector(final double maxCheck,
  83.                             final double threshold,
  84.                             final double altitude,
  85.                             final BodyShape bodyShape) {
  86.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnDecreasing<AltitudeDetector>(),
  87.              altitude, bodyShape);
  88.     }

  89.     /** Private constructor with full parameters.
  90.      * <p>
  91.      * This constructor is private as users are expected to use the builder
  92.      * API with the various {@code withXxx()} methods to set up the instance
  93.      * in a readable manner without using a huge amount of parameters.
  94.      * </p>
  95.      * @param maxCheck maximum checking interval (s)
  96.      * @param threshold convergence threshold (s)
  97.      * @param maxIter maximum number of iterations in the event time search
  98.      * @param handler event handler to call at event occurrences
  99.      * @param altitude threshold altitude value (m)
  100.      * @param bodyShape body shape with respect to which altitude should be evaluated
  101.      * @since 6.1
  102.      */
  103.     private AltitudeDetector(final double maxCheck, final double threshold,
  104.                              final int maxIter, final EventHandler<? super AltitudeDetector> handler,
  105.                              final double altitude,
  106.                              final BodyShape bodyShape) {
  107.         super(maxCheck, threshold, maxIter, handler);
  108.         this.altitude  = altitude;
  109.         this.bodyShape = bodyShape;
  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     protected AltitudeDetector create(final double newMaxCheck, final double newThreshold,
  114.                                       final int newMaxIter, final EventHandler<? super AltitudeDetector> newHandler) {
  115.         return new AltitudeDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  116.                                     altitude, bodyShape);
  117.     }

  118.     /** Get the threshold altitude value.
  119.      * @return the threshold altitude value (m)
  120.      */
  121.     public double getAltitude() {
  122.         return altitude;
  123.     }

  124.     /** Get the body shape.
  125.      * @return the body shape
  126.      */
  127.     public BodyShape getBodyShape() {
  128.         return bodyShape;
  129.     }

  130.     /** Compute the value of the switching function.
  131.      * This function measures the difference between the current altitude
  132.      * and the threshold altitude.
  133.      * @param s the current state information: date, kinematics, attitude
  134.      * @return value of the switching function
  135.      * @exception OrekitException if some specific error occurs
  136.      */
  137.     public double g(final SpacecraftState s) throws OrekitException {
  138.         final Frame bodyFrame      = bodyShape.getBodyFrame();
  139.         final PVCoordinates pvBody = s.getPVCoordinates(bodyFrame);
  140.         final GeodeticPoint point  = bodyShape.transform(pvBody.getPosition(),
  141.                                                          bodyFrame, s.getDate());
  142.         return point.getAltitude() - altitude;
  143.     }

  144. }