AngularSeparationDetector.java

  1. /* Copyright 2002-2022 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.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.ode.events.Action;
  20. import org.orekit.bodies.CelestialBodies;
  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.PVCoordinates;
  25. import org.orekit.utils.PVCoordinatesProvider;

  26. /** Detects when spacecraft comes close to a moving beacon, as seen from a moving observer.
  27.  * <p>The main use case for this detector is when the observer is in fact a ground
  28.  * station, modeled as a {@link org.orekit.frames.TopocentricFrame} and when the beacon
  29.  * is the {@link CelestialBodies#getSun() Sun}, for computing
  30.  * interferences for the telemetry link. Another similar case is when the beacon is
  31.  * another spacecraft, for interferences computation.</p>
  32.  * <p>The default handler behavior is to {@link 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.     /** Beacon at the center of the proximity zone. */
  41.     private final PVCoordinatesProvider beacon;

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

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

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

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

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

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

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

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

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

  134. }