AngularSeparationDetector.java

  1. /* Copyright 2002-2018 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.errors.OrekitException;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.events.handlers.EventHandler;
  22. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  23. import org.orekit.utils.PVCoordinates;
  24. import org.orekit.utils.PVCoordinatesProvider;

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

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

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

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

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

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

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

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

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

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

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

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

  137. }