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.attitudes;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.Rotation;
21  import org.orekit.annotation.DefaultDataContext;
22  import org.orekit.data.DataContext;
23  import org.orekit.frames.FieldTransform;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.Transform;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.time.FieldAbsoluteDate;
28  import org.orekit.utils.FieldPVCoordinatesProvider;
29  import org.orekit.utils.PVCoordinatesProvider;
30  
31  
32  /**
33   * This class handles an attitude provider aligned with a frame or a fixed offset to it.
34   * Contrary to the name the frame need not be an inertial frame.
35   * <p>Instances of this class are guaranteed to be immutable.</p>
36   * @author Luc Maisonobe
37   */
38  public class InertialProvider implements AttitudeProvider {
39  
40      /** Fixed satellite frame. */
41      private final Frame satelliteFrame;
42  
43      /** Creates new instance.
44       *
45       * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
46       *
47       * @param rotation rotation from EME2000 to the desired satellite frame
48       * @see #InertialProvider(Rotation, Frame)
49       */
50      @DefaultDataContext
51      public InertialProvider(final Rotation rotation) {
52          this(rotation, DataContext.getDefault().getFrames().getEME2000());
53      }
54  
55      /**
56       * Creates new instance aligned with the given frame.
57       *
58       * @param frame the reference frame for the attitude.
59       */
60      public InertialProvider(final Frame frame) {
61          // it is faster to use the frame directly here rather than call the other
62          // constructor because of the == shortcut in frame.getTransformTo
63          this.satelliteFrame = frame;
64      }
65  
66      /**
67       * Creates new instance with a fixed attitude in the given frame.
68       *
69       * @param rotation  rotation from {@code reference} to the desired satellite frame
70       * @param reference frame for {@code rotation}.
71       * @since 10.1
72       */
73      public InertialProvider(final Rotation rotation,
74                              final Frame reference) {
75          satelliteFrame =
76              new Frame(reference,
77                      new Transform(AbsoluteDate.ARBITRARY_EPOCH, rotation), null, false);
78      }
79  
80      /**
81       * Creates an attitude provider aligned with the given frame. The frame does not need
82       * to be inertial.
83       *
84       * <p>This attitude provider returned by this method is designed to be as fast as
85       * possible for when attitude is irrelevant while still being a valid implementation
86       * of {@link AttitudeProvider}. To ensure good performance the specified attitude
87       * reference frame should be the same frame used for propagation so that computing the
88       * frame transformation is trivial.
89       *
90       * @param satelliteFrame with which the satellite is aligned.
91       * @return new attitude provider aligned with the given frame.
92       * @since 11.0
93       */
94      public static AttitudeProvider of(final Frame satelliteFrame) {
95          return new InertialProvider(satelliteFrame);
96      }
97  
98      /** {@inheritDoc} */
99      public Attitude getAttitude(final PVCoordinatesProvider pvProv,
100                                 final AbsoluteDate date, final Frame frame) {
101         final Transform t = frame.getTransformTo(satelliteFrame, date);
102         return new Attitude(date, frame, t.getRotation(), t.getRotationRate(), t.getRotationAcceleration());
103     }
104 
105     /** {@inheritDoc} */
106     public <T extends CalculusFieldElement<T>>FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
107                                                                        final FieldAbsoluteDate<T> date, final Frame frame) {
108         final FieldTransform<T> t = frame.getTransformTo(satelliteFrame, date);
109         return new FieldAttitude<>(date, frame, t.getRotation(), t.getRotationRate(), t.getRotationAcceleration());
110     }
111 
112 }