1 /* Copyright 2002-2024 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
19 import org.hipparchus.geometry.euclidean.threed.Vector3D;
20 import org.hipparchus.ode.events.Action;
21 import org.hipparchus.util.FastMath;
22 import org.orekit.geometry.fov.FieldOfView;
23 import org.orekit.propagation.SpacecraftState;
24 import org.orekit.propagation.events.handlers.EventHandler;
25 import org.orekit.propagation.events.handlers.StopOnIncreasing;
26 import org.orekit.utils.PVCoordinatesProvider;
27
28 /** Finder for target entry/exit events with respect to a satellite sensor
29 * {@link FieldOfView Field Of View}.
30 * <p>Beware that this detector is unaware of any bodies occluding line-of-sight to
31 * the target. It can be therefore used for many contexts from Earth Observation to
32 * interplanetary mission design. For instance, in an Earth Observation context,
33 * it can be easily combined to an {@link ElevationDetector} using
34 * {@link BooleanDetector#andCombine(java.util.Collection)} to calculate station
35 * visibility opportunities within the satellite's field of view.
36 * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
37 * propagation at FOV entry and to {@link Action#STOP stop} propagation
38 * at FOV exit. This can be changed by calling
39 * {@link #withHandler(EventHandler)} after construction.</p>
40 * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
41 * @see FootprintOverlapDetector
42 * @see VisibilityTrigger
43 * @author Luc Maisonobe
44 * @since 7.1
45 */
46 public class FieldOfViewDetector extends AbstractDetector<FieldOfViewDetector> {
47
48 /** Position/velocity provider of the considered target. */
49 private final PVCoordinatesProvider targetPVProvider;
50
51 /** Radius of the target, considered to be a spherical body (m). */
52 private final double radiusTarget;
53
54 /** Visibility trigger for spherical bodies. */
55 private final VisibilityTrigger trigger;
56
57 /** Field of view. */
58 private final FieldOfView fov;
59
60 /** Build a new instance.
61 * <p>The maximal interval between distance to FOV boundary checks should
62 * be smaller than the half duration of the minimal pass to handle,
63 * otherwise some short passes could be missed.</p>
64 * @param pvTarget Position/velocity provider of the considered target
65 * @param fov Field Of View
66 * @since 10.1
67 */
68 public FieldOfViewDetector(final PVCoordinatesProvider pvTarget, final FieldOfView fov) {
69 this(pvTarget, 0.0, VisibilityTrigger.VISIBLE_AS_SOON_AS_PARTIALLY_IN_FOV, fov);
70 }
71
72 /** Build a new instance.
73 * <p>The maximal interval between distance to FOV boundary checks should
74 * be smaller than the half duration of the minimal pass to handle,
75 * otherwise some short passes could be missed.</p>
76 * @param pvTarget Position/velocity provider of the considered target
77 * @param radiusTarget radius of the target, considered to be a spherical body (m)
78 * @param trigger visibility trigger for spherical bodies
79 * @param fov Field Of View
80 * @since 10.1
81 */
82 public FieldOfViewDetector(final PVCoordinatesProvider pvTarget, final double radiusTarget,
83 final VisibilityTrigger trigger, final FieldOfView fov) {
84 this(AdaptableInterval.of(DEFAULT_MAXCHECK), DEFAULT_THRESHOLD, DEFAULT_MAX_ITER,
85 new StopOnIncreasing(),
86 pvTarget, radiusTarget, trigger, fov);
87 }
88
89 /** Protected constructor with full parameters.
90 * <p>
91 * This constructor is not public as users are expected to use the builder
92 * API with the various {@code withXxx()} methods to set up the instance
93 * in a readable manner without using a huge amount of parameters.
94 * </p>
95 * @param maxCheck maximum checking interval
96 * @param threshold convergence threshold (s)
97 * @param maxIter maximum number of iterations in the event time search
98 * @param handler event handler to call at event occurrences
99 * @param pvTarget Position/velocity provider of the considered target
100 * @param radiusTarget radius of the target, considered to be a spherical body (m)
101 * @param trigger visibility trigger for spherical bodies
102 * @param fov Field Of View
103 */
104 protected FieldOfViewDetector(final AdaptableInterval maxCheck, final double threshold, final int maxIter,
105 final EventHandler handler,
106 final PVCoordinatesProvider pvTarget, final double radiusTarget,
107 final VisibilityTrigger trigger, final FieldOfView fov) {
108 super(maxCheck, threshold, maxIter, handler);
109 this.targetPVProvider = pvTarget;
110 this.radiusTarget = radiusTarget;
111 this.trigger = trigger;
112 this.fov = fov;
113 }
114
115 /** {@inheritDoc} */
116 @Override
117 protected FieldOfViewDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
118 final int newMaxIter,
119 final EventHandler newHandler) {
120 return new FieldOfViewDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
121 targetPVProvider, radiusTarget, trigger, fov);
122 }
123
124 /** Get the position/velocity provider of the target .
125 * @return the position/velocity provider of the target
126 */
127 public PVCoordinatesProvider getPVTarget() {
128 return targetPVProvider;
129 }
130
131 /** Get the Field Of View.
132 * @return Field Of View
133 * @since 10.1
134 */
135 public FieldOfView getFOV() {
136 return fov;
137 }
138
139 /** {@inheritDoc}
140 * <p>
141 * The g function value is the angular offset between the
142 * target center and the {@link FieldOfView#offsetFromBoundary(Vector3D,
143 * double, VisibilityTrigger) Field Of View boundary}, plus or minus the
144 * target angular radius depending on the {@link VisibilityTrigger}, minus
145 * the {@link FieldOfView#getMargin() Field Of View margin}. It is therefore
146 * negative if the target is visible within the Field Of View and positive
147 * if it is outside of the Field Of View.
148 * </p>
149 * <p>
150 * As per the previous definition, when the target enters the Field Of
151 * View, a decreasing event is generated, and when the target leaves
152 * the Field Of View, an increasing event is generated.
153 * </p>
154 */
155 public double g(final SpacecraftState s) {
156
157 // get line of sight in spacecraft frame
158 final Vector3D targetPosInert =
159 targetPVProvider.getPosition(s.getDate(), s.getFrame());
160 final Vector3D lineOfSightSC = s.toStaticTransform().transformPosition(targetPosInert);
161
162 final double angularRadius = FastMath.asin(radiusTarget / lineOfSightSC.getNorm());
163 return fov.offsetFromBoundary(lineOfSightSC, angularRadius, trigger);
164
165 }
166
167 }