ElevationDetector.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.frames.TopocentricFrame;
  20. import org.orekit.models.AtmosphericRefractionModel;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  24. import org.orekit.propagation.events.intervals.AdaptableInterval;
  25. import org.orekit.utils.ElevationMask;
  26. import org.orekit.utils.TrackingCoordinates;


  27. /**
  28.  * Finder for satellite raising/setting events that allows for the
  29.  * setting of azimuth and/or elevation bounds or a ground azimuth/elevation
  30.  * mask input. Each calculation be configured to use atmospheric refraction
  31.  * as well.
  32.  * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
  33.  * propagation at raising and to {@link Action#STOP stop} propagation
  34.  * at setting. This can be changed by calling
  35.  * {@link #withHandler(EventHandler)} after construction.</p>
  36.  * @author Hank Grabowski
  37.  * @since 6.1
  38.  */
  39. public class ElevationDetector extends AbstractTopocentricDetector<ElevationDetector> {

  40.     /** Elevation mask used for calculations, if defined. */
  41.     private final ElevationMask elevationMask;

  42.     /** Minimum elevation value used if mask is not defined. */
  43.     private final double minElevation;

  44.     /** Atmospheric Model used for calculations, if defined. */
  45.     private final AtmosphericRefractionModel refractionModel;

  46.     /**
  47.      * Creates an instance of Elevation detector based on passed in topocentric frame
  48.      * and the minimum elevation angle.
  49.      * <p>
  50.      * uses default values for maximal checking interval ({@link #DEFAULT_MAX_CHECK})
  51.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  52.      * @param topo reference to a topocentric model
  53.      * @see #withConstantElevation(double)
  54.      * @see #withElevationMask(ElevationMask)
  55.      * @see #withRefraction(AtmosphericRefractionModel)
  56.      */
  57.     public ElevationDetector(final TopocentricFrame topo) {
  58.         this(DEFAULT_MAX_CHECK, DEFAULT_THRESHOLD, topo);
  59.     }

  60.     /**
  61.      * Creates an instance of Elevation detector based on passed in topocentric frame
  62.      * and overrides of default maximal checking interval and convergence threshold values.
  63.      * @param maxCheck maximum checking interval (s)
  64.      * @param threshold maximum convergence threshold (s)
  65.      * @param topo reference to a topocentric model
  66.      * @see #withConstantElevation(double)
  67.      * @see #withElevationMask(ElevationMask)
  68.      * @see #withRefraction(AtmosphericRefractionModel)
  69.      */
  70.     public ElevationDetector(final double maxCheck, final double threshold,
  71.                              final TopocentricFrame topo) {
  72.         this(AdaptableInterval.of(maxCheck), threshold, topo);
  73.     }

  74.     /**
  75.      * Creates an instance of Elevation detector based on passed in topocentric frame
  76.      * and overrides of default maximal checking interval and convergence threshold values.
  77.      * @param maxCheck maximum checking adaptable interval
  78.      * @param threshold maximum convergence threshold (s)
  79.      * @param topo reference to a topocentric model
  80.      * @see org.orekit.propagation.events.intervals.ElevationDetectionAdaptableIntervalFactory
  81.      * @see #withConstantElevation(double)
  82.      * @see #withElevationMask(ElevationMask)
  83.      * @see #withRefraction(AtmosphericRefractionModel)
  84.      * @since 12.1
  85.      */
  86.     public ElevationDetector(final AdaptableInterval maxCheck, final double threshold,
  87.                              final TopocentricFrame topo) {
  88.         this(new EventDetectionSettings(maxCheck, threshold, DEFAULT_MAX_ITER), new StopOnDecreasing(),
  89.              0.0, null, null, topo);
  90.     }

  91.     /** Protected constructor with full parameters.
  92.      * <p>
  93.      * This constructor is not public as users are expected to use the builder
  94.      * API with the various {@code withXxx()} methods to set up the instance
  95.      * in a readable manner without using a huge amount of parameters.
  96.      * </p>
  97.      * @param detectionSettings event detection settings
  98.      * @param handler event handler to call at event occurrences
  99.      * @param minElevation minimum elevation in radians (rad)
  100.      * @param mask reference to elevation mask
  101.      * @param refractionModel reference to refraction model
  102.      * @param topo reference to a topocentric model
  103.      * @since 13.0
  104.      */
  105.     protected ElevationDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  106.                                 final double minElevation, final ElevationMask mask,
  107.                                 final AtmosphericRefractionModel refractionModel,
  108.                                 final TopocentricFrame topo) {
  109.         super(detectionSettings, handler, topo);
  110.         this.minElevation    = minElevation;
  111.         this.elevationMask   = mask;
  112.         this.refractionModel = refractionModel;
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     protected ElevationDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  117.         return new ElevationDetector(detectionSettings, newHandler,
  118.                                      minElevation, elevationMask, refractionModel, getTopocentricFrame());
  119.     }

  120.     /**
  121.      * Returns the currently configured elevation mask.
  122.      * @return elevation mask
  123.      * (null if instance has been configured with {@link #withConstantElevation(double)}
  124.      * @see #withElevationMask(ElevationMask)
  125.      */
  126.     public ElevationMask getElevationMask() {
  127.         return this.elevationMask;
  128.     }

  129.     /**
  130.      * Returns the currently configured minimum valid elevation value.
  131.      * @return minimum elevation value
  132.      * ({@code Double.NaN} if instance has been configured with {@link #withElevationMask(ElevationMask)}
  133.      * @see #withConstantElevation(double)
  134.      */
  135.     public double getMinElevation() {
  136.         return this.minElevation;
  137.     }

  138.     /**
  139.      * Returns the currently configured refraction model.
  140.      * @return refraction model
  141.      * @see #withRefraction(AtmosphericRefractionModel)
  142.      */
  143.     public AtmosphericRefractionModel getRefractionModel() {
  144.         return this.refractionModel;
  145.     }

  146.     /** Compute the value of the switching function.
  147.      * This function measures the difference between the current elevation
  148.      * (and azimuth if necessary) and the reference mask or minimum value.
  149.      * @param s the current state information: date, kinematics, attitude
  150.      * @return value of the switching function
  151.      */
  152.     @Override
  153.     public double g(final SpacecraftState s) {

  154.         final TrackingCoordinates tc = getTopocentricFrame().getTrackingCoordinates(s.getPosition(), s.getFrame(), s.getDate());

  155.         final double calculatedElevation;
  156.         if (refractionModel != null) {
  157.             calculatedElevation = tc.getElevation() + refractionModel.getRefraction(tc.getElevation());
  158.         } else {
  159.             calculatedElevation = tc.getElevation();
  160.         }

  161.         if (elevationMask != null) {
  162.             return calculatedElevation - elevationMask.getElevation(tc.getAzimuth());
  163.         } else {
  164.             return calculatedElevation - minElevation;
  165.         }

  166.     }

  167.     /**
  168.      * Setup the minimum elevation for detection.
  169.      * <p>
  170.      * This will override an elevation mask if it has been configured as such previously.
  171.      * </p>
  172.      * @param newMinElevation minimum elevation for visibility in radians (rad)
  173.      * @return a new detector with updated configuration (the instance is not changed)
  174.      * @see #getMinElevation()
  175.      * @since 6.1
  176.      */
  177.     public ElevationDetector withConstantElevation(final double newMinElevation) {
  178.         return new ElevationDetector(getDetectionSettings(), getHandler(),
  179.                                      newMinElevation, null, refractionModel, getTopocentricFrame());
  180.     }

  181.     /**
  182.      * Setup the elevation mask for detection using the passed in mask object.
  183.      * @param newElevationMask elevation mask to use for the computation
  184.      * @return a new detector with updated configuration (the instance is not changed)
  185.      * @since 6.1
  186.      * @see #getElevationMask()
  187.      */
  188.     public ElevationDetector withElevationMask(final ElevationMask newElevationMask) {
  189.         return new ElevationDetector(getDetectionSettings(), getHandler(),
  190.                                      Double.NaN, newElevationMask, refractionModel, getTopocentricFrame());
  191.     }

  192.     /**
  193.      * Setup the elevation detector to use an atmospheric refraction model in its
  194.      * calculations.
  195.      * <p>
  196.      * To disable the refraction when copying an existing elevation
  197.      * detector, call this method with a null argument.
  198.      * </p>
  199.      * @param newRefractionModel refraction model to use for the computation
  200.      * @return a new detector with updated configuration (the instance is not changed)
  201.      * @since 6.1
  202.      * @see #getRefractionModel()
  203.      */
  204.     public ElevationDetector withRefraction(final AtmosphericRefractionModel newRefractionModel) {
  205.         return new ElevationDetector(getDetectionSettings(), getHandler(),
  206.                                      minElevation, elevationMask, newRefractionModel, getTopocentricFrame());
  207.     }

  208. }