FieldAngularSeparationDetector.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.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.ode.events.Action;
  21. import org.orekit.bodies.CelestialBodies;
  22. import org.orekit.propagation.FieldSpacecraftState;
  23. import org.orekit.propagation.events.handlers.FieldEventHandler;
  24. import org.orekit.propagation.events.handlers.FieldStopOnEvent;
  25. import org.orekit.utils.ExtendedPositionProvider;

  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.  * {@code #withHandler(EventHandler)} after construction.</p>
  35.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  36.  * @author Luc Maisonobe
  37.  * @author Romain Serra
  38.  * @see AngularSeparationDetector
  39.  * @since 13.1
  40.  */
  41. public class FieldAngularSeparationDetector<T extends CalculusFieldElement<T>>
  42.         extends FieldAbstractDetector<FieldAngularSeparationDetector<T>, T> {

  43.     /** Beacon at the center of the proximity zone. */
  44.     private final ExtendedPositionProvider beacon;

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

  47.     /** Proximity angle (rad). */
  48.     private final T proximityAngle;

  49.     /** Build a new angular separation detector.
  50.      * @param beacon beacon at the center of the proximity zone
  51.      * @param observer observer for the spacecraft, that may also see
  52.      * the beacon at the same time if they are too close to each other
  53.      * @param proximityAngle proximity angle as seen from observer, at which events are triggered (rad)
  54.      */
  55.     public FieldAngularSeparationDetector(final ExtendedPositionProvider beacon,
  56.                                           final ExtendedPositionProvider observer,
  57.                                           final T proximityAngle) {
  58.         this(new FieldEventDetectionSettings<>(proximityAngle.getField(), AngularSeparationDetector.DEFAULT_SETTINGS),
  59.                 new FieldStopOnEvent<>(), beacon, observer, proximityAngle);
  60.     }

  61.     /** Protected constructor with full parameters.
  62.      * <p>
  63.      * This constructor is not public as users are expected to use the builder
  64.      * API with the various {@code withXxx()} methods to set up the instance
  65.      * in a readable manner without using a huge amount of parameters.
  66.      * </p>
  67.      * @param detectionSettings detection settings
  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.      * @since 13.0
  74.      */
  75.     protected FieldAngularSeparationDetector(final FieldEventDetectionSettings<T> detectionSettings,
  76.                                              final FieldEventHandler<T> handler,
  77.                                              final ExtendedPositionProvider beacon,
  78.                                              final ExtendedPositionProvider observer,
  79.                                              final T proximityAngle) {
  80.         super(detectionSettings, handler);
  81.         this.beacon         = beacon;
  82.         this.observer       = observer;
  83.         this.proximityAngle = proximityAngle;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     protected FieldAngularSeparationDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  88.                                                        final FieldEventHandler<T> newHandler) {
  89.         return new FieldAngularSeparationDetector<>(detectionSettings, newHandler, 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 ExtendedPositionProvider getBeacon() {
  95.         return beacon;
  96.     }

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

  103.     /** Get the proximity angle (rad).
  104.      * @return the proximity angle
  105.      */
  106.     public T 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 T g(final FieldSpacecraftState<T> s) {
  127.         final FieldVector3D<T> sPos = s.getPosition();
  128.         final FieldVector3D<T> bP = beacon.getPosition(s.getDate(), s.getFrame());
  129.         final FieldVector3D<T> oP = observer.getPosition(s.getDate(), s.getFrame());
  130.         final T separation = FieldVector3D.angle(sPos.subtract(oP), bP.subtract(oP));
  131.         return separation.subtract(proximityAngle);
  132.     }

  133. }