AngularSeparationDetector.java

  1. /* Copyright 2002-2019 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.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.orekit.propagation.SpacecraftState;
  20. import org.orekit.propagation.events.handlers.EventHandler;
  21. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  22. import org.orekit.utils.PVCoordinates;
  23. import org.orekit.utils.PVCoordinatesProvider;

  24. /** Detects when spacecraft comes close to a moving beacon, as seen from a moving observer.
  25.  * <p>The main use case for this detector is when the observer is in fact a ground
  26.  * station, modeled as a {@link org.orekit.frames.TopocentricFrame} and when the beacon
  27.  * is the {@link org.orekit.bodies.CelestialBodyFactory#getSun() Sun}, for computing
  28.  * interferences for the telemetry link. Another similar case is when the beacon is
  29.  * another spacecraft, for interferences computation.</p>
  30.  * <p>The default handler behavior is to {@link
  31.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop}
  32.  * propagation when spacecraft enters the proximity zone. This can be changed by calling
  33.  * {@link #withHandler(EventHandler)} after construction.</p>
  34.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  35.  * @author Luc Maisonobe
  36.  * @since 8.0
  37.  */
  38. public class AngularSeparationDetector extends AbstractDetector<AngularSeparationDetector> {

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

  41.     /** Beacon at the center of the proximity zone. */
  42.     private final PVCoordinatesProvider beacon;

  43.     /** Observer for the spacecraft, that may also see the beacon at the same time if they are too close. */
  44.     private final PVCoordinatesProvider observer;

  45.     /** Proximity angle (rad). */
  46.     private final double proximityAngle;

  47.     /** Build a new angular separation detector.
  48.      * @param beacon beacon at the center of the proximity zone
  49.      * @param observer observer for the spacecraft, that may also see
  50.      * the beacon at the same time if they are too close to each other
  51.      * @param proximityAngle proximity angle as seen from observer, at which events are triggered (rad)
  52.      */
  53.     public AngularSeparationDetector(final PVCoordinatesProvider beacon,
  54.                                      final PVCoordinatesProvider observer,
  55.                                      final double proximityAngle) {
  56.         this(60.0, 1.0e-3, 100, new StopOnDecreasing<AngularSeparationDetector>(),
  57.              beacon, observer, proximityAngle);
  58.     }

  59.     /** Private constructor with full parameters.
  60.      * <p>
  61.      * This constructor is private as users are expected to use the builder
  62.      * API with the various {@code withXxx()} methods to set up the instance
  63.      * in a readable manner without using a huge amount of parameters.
  64.      * </p>
  65.      * @param maxCheck maximum checking interval (s)
  66.      * @param threshold convergence threshold (s)
  67.      * @param maxIter maximum number of iterations in the event time search
  68.      * @param handler event handler to call at event occurrences
  69.      * @param beacon beacon at the center of the proximity zone
  70.      * @param observer observer for the spacecraft, that may also see
  71.      * the beacon at the same time if they are too close to each other
  72.      * @param proximityAngle proximity angle as seen from observer, at which events are triggered (rad)
  73.      */
  74.     private AngularSeparationDetector(final double maxCheck, final double threshold,
  75.                                       final int maxIter,
  76.                                       final EventHandler<? super AngularSeparationDetector> handler,
  77.                                       final PVCoordinatesProvider beacon,
  78.                                       final PVCoordinatesProvider observer,
  79.                                       final double proximityAngle) {
  80.         super(maxCheck, threshold, maxIter, handler);
  81.         this.beacon         = beacon;
  82.         this.observer       = observer;
  83.         this.proximityAngle = proximityAngle;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     protected AngularSeparationDetector create(final double newMaxCheck, final double newThreshold,
  88.                                        final int newMaxIter, final EventHandler<? super AngularSeparationDetector> newHandler) {
  89.         return new AngularSeparationDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  90.                                              beacon, observer, proximityAngle);
  91.     }

  92.     /** Get the beacon at the center of the proximity zone.
  93.      * @return beacon at the center of the proximity zone
  94.      */
  95.     public PVCoordinatesProvider getBeacon() {
  96.         return beacon;
  97.     }

  98.     /** Get the observer for the spacecraft.
  99.      * @return observer for the spacecraft
  100.      */
  101.     public PVCoordinatesProvider getObserver() {
  102.         return observer;
  103.     }

  104.     /** Get the proximity angle (rad).
  105.      * @return the proximity angle
  106.      */
  107.     public double getProximityAngle() {
  108.         return proximityAngle;
  109.     }

  110.     /** Compute the value of the switching function.
  111.      * <p>
  112.      * This function measures the angular separation between beacon and spacecraft
  113.      * as seen from the observer minus the proximity angle. It therefore triggers
  114.      * decreasing events when the spacecraft enters the proximity zone and increasing
  115.      * events when it leaves the proximity zone.
  116.      * </p>
  117.      * <p>
  118.      * No shadowing effect is taken into account, so this method is computed and
  119.      * may trigger events even when the spacecraft is below horizon for an observer
  120.      * which is a ground station. If such effects must be taken into account the
  121.      * detector must be associated with a {@link EventEnablingPredicateFilter predicate
  122.      * filter} where the {@link EnablingPredicate predicate function} is based on elevation.
  123.      * </p>
  124.      * @param s the current state information: date, kinematics, attitude
  125.      * @return value of the switching function
  126.      */
  127.     public double g(final SpacecraftState s) {
  128.         final PVCoordinates sPV = s.getPVCoordinates();
  129.         final PVCoordinates bPV = beacon.getPVCoordinates(s.getDate(), s.getFrame());
  130.         final PVCoordinates oPV = observer.getPVCoordinates(s.getDate(), s.getFrame());
  131.         final double separation = Vector3D.angle(sPV.getPosition().subtract(oPV.getPosition()),
  132.                                                  bPV.getPosition().subtract(oPV.getPosition()));
  133.         return separation - proximityAngle;
  134.     }

  135. }