AltitudeDetector.java

  1. /* Copyright 2002-2024 CS GROUP
  2.  * Licensed to CS GROUP (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.ode.events.Action;
  19. import org.orekit.bodies.BodyShape;
  20. import org.orekit.bodies.GeodeticPoint;
  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. /** Finder for satellite altitude crossing events.
  26.  * <p>This class finds altitude events (i.e. satellite crossing
  27.  * a predefined altitude level above ground).</p>
  28.  * <p>The default implementation behavior is to {@link Action#CONTINUE
  29.  * continue} propagation when ascending and to {@link Action#STOP stop}
  30.  * propagation when descending. This can be changed by calling
  31.  * {@link #withHandler(EventHandler)} after construction.</p>
  32.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  33.  * @author Luc Maisonobe
  34.  */
  35. public class AltitudeDetector extends AbstractDetector<AltitudeDetector> {

  36.     /** Threshold altitude value (m). */
  37.     private final double altitude;

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

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

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

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

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

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     protected AltitudeDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
  109.                                       final int newMaxIter, final EventHandler newHandler) {
  110.         return new AltitudeDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  111.                                     altitude, bodyShape);
  112.     }

  113.     /** Get the threshold altitude value.
  114.      * @return the threshold altitude value (m)
  115.      */
  116.     public double getAltitude() {
  117.         return altitude;
  118.     }

  119.     /** Get the body shape.
  120.      * @return the body shape
  121.      */
  122.     public BodyShape getBodyShape() {
  123.         return bodyShape;
  124.     }

  125.     /** Compute the value of the switching function.
  126.      * This function measures the difference between the current altitude
  127.      * and the threshold altitude.
  128.      * @param s the current state information: date, kinematics, attitude
  129.      * @return value of the switching function
  130.      */
  131.     public double g(final SpacecraftState s) {
  132.         final Frame bodyFrame      = bodyShape.getBodyFrame();
  133.         final GeodeticPoint point  = bodyShape.transform(s.getPosition(bodyFrame), bodyFrame, s.getDate());
  134.         return point.getAltitude() - altitude;
  135.     }

  136. }