ElevationDetector.java

  1. /* Copyright 2002-2023 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.utils.ElevationMask;
  25. import org.orekit.utils.TrackingCoordinates;


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

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

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

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

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

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

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

  77.     /** Protected constructor with full parameters.
  78.      * <p>
  79.      * This constructor is not public as users are expected to use the builder
  80.      * API with the various {@code withXxx()} methods to set up the instance
  81.      * in a readable manner without using a huge amount of parameters.
  82.      * </p>
  83.      * @param maxCheck maximum checking interval
  84.      * @param threshold convergence threshold (s)
  85.      * @param maxIter maximum number of iterations in the event time search
  86.      * @param handler event handler to call at event occurrences
  87.      * @param minElevation minimum elevation in radians (rad)
  88.      * @param mask reference to elevation mask
  89.      * @param refractionModel reference to refraction model
  90.      * @param topo reference to a topocentric model
  91.      */
  92.     protected ElevationDetector(final AdaptableInterval maxCheck, final double threshold,
  93.                                 final int maxIter, final EventHandler handler,
  94.                                 final double minElevation, final ElevationMask mask,
  95.                                 final AtmosphericRefractionModel refractionModel,
  96.                                 final TopocentricFrame topo) {
  97.         super(maxCheck, threshold, maxIter, handler);
  98.         this.minElevation    = minElevation;
  99.         this.elevationMask   = mask;
  100.         this.refractionModel = refractionModel;
  101.         this.topo            = topo;
  102.     }

  103.     /** {@inheritDoc} */
  104.     @Override
  105.     protected ElevationDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
  106.                                        final int newMaxIter, final EventHandler newHandler) {
  107.         return new ElevationDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  108.                                      minElevation, elevationMask, refractionModel, topo);
  109.     }

  110.     /**
  111.      * Returns the currently configured elevation mask.
  112.      * @return elevation mask
  113.      * (null if instance has been configured with {@link #withConstantElevation(double)}
  114.      * @see #withElevationMask(ElevationMask)
  115.      */
  116.     public ElevationMask getElevationMask() {
  117.         return this.elevationMask;
  118.     }

  119.     /**
  120.      * Returns the currently configured minimum valid elevation value.
  121.      * @return minimum elevation value
  122.      * ({@code Double.NaN} if instance has been configured with {@link #withElevationMask(ElevationMask)}
  123.      * @see #withConstantElevation(double)
  124.      */
  125.     public double getMinElevation() {
  126.         return this.minElevation;
  127.     }

  128.     /**
  129.      * Returns the currently configured refraction model.
  130.      * @return refraction model
  131.      * @see #withRefraction(AtmosphericRefractionModel)
  132.      */
  133.     public AtmosphericRefractionModel getRefractionModel() {
  134.         return this.refractionModel;
  135.     }

  136.     /**
  137.      * Returns the currently configured topocentric frame definitions.
  138.      * @return topocentric frame definition
  139.      */
  140.     public TopocentricFrame getTopocentricFrame() {
  141.         return this.topo;
  142.     }

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

  151.         final TrackingCoordinates tc = topo.getTrackingCoordinates(s.getPosition(), s.getFrame(), s.getDate());

  152.         final double calculatedElevation;
  153.         if (refractionModel != null) {
  154.             calculatedElevation = tc.getElevation() + refractionModel.getRefraction(tc.getElevation());
  155.         } else {
  156.             calculatedElevation = tc.getElevation();
  157.         }

  158.         if (elevationMask != null) {
  159.             return calculatedElevation - elevationMask.getElevation(tc.getAzimuth());
  160.         } else {
  161.             return calculatedElevation - minElevation;
  162.         }

  163.     }

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

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

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

  205. }