AltitudeDetector.java

  1. /* Copyright 2002-2025 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_MAX_CHECK}) 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(EventDetectionSettings.DEFAULT_MAX_CHECK, 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, final double altitude, final BodyShape bodyShape) {
  61.         this(maxCheck, DEFAULT_THRESHOLD, altitude, bodyShape);
  62.     }

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

  80.     /** Protected constructor with full parameters.
  81.      * <p>
  82.      * This constructor is not public as users are expected to use the builder
  83.      * API with the various {@code withXxx()} methods to set up the instance
  84.      * in a readable manner without using a huge amount of parameters.
  85.      * </p>
  86.      * @param detectionSettings detection settings
  87.      * @param handler event handler to call at event occurrences
  88.      * @param altitude threshold altitude value (m)
  89.      * @param bodyShape body shape with respect to which altitude should be evaluated
  90.      * @since 13.0
  91.      */
  92.     protected AltitudeDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  93.                                final double altitude,
  94.                                final BodyShape bodyShape) {
  95.         super(detectionSettings, handler);
  96.         this.altitude  = altitude;
  97.         this.bodyShape = bodyShape;
  98.     }

  99.     /** {@inheritDoc} */
  100.     @Override
  101.     protected AltitudeDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  102.         return new AltitudeDetector(detectionSettings, newHandler, altitude, bodyShape);
  103.     }

  104.     /** Get the threshold altitude value.
  105.      * @return the threshold altitude value (m)
  106.      */
  107.     public double getAltitude() {
  108.         return altitude;
  109.     }

  110.     /** Get the body shape.
  111.      * @return the body shape
  112.      */
  113.     public BodyShape getBodyShape() {
  114.         return bodyShape;
  115.     }

  116.     /** Compute the value of the switching function.
  117.      * This function measures the difference between the current altitude
  118.      * and the threshold altitude.
  119.      * @param s the current state information: date, kinematics, attitude
  120.      * @return value of the switching function
  121.      */
  122.     public double g(final SpacecraftState s) {
  123.         final Frame bodyFrame      = bodyShape.getBodyFrame();
  124.         final GeodeticPoint point  = bodyShape.transform(s.getPosition(bodyFrame), bodyFrame, s.getDate());
  125.         return point.getAltitude() - altitude;
  126.     }

  127. }