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.attitudes;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldRotation;
21  import org.hipparchus.geometry.euclidean.threed.Rotation;
22  import org.orekit.annotation.DefaultDataContext;
23  import org.orekit.data.DataContext;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.Transform;
26  import org.orekit.frames.FieldTransform;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.time.FieldAbsoluteDate;
29  import org.orekit.utils.FieldPVCoordinatesProvider;
30  import org.orekit.utils.PVCoordinatesProvider;
31  
32  
33  /**
34   * This class handles an attitude provider aligned with a frame or a fixed offset to it.
35   * <p>Instances of this class are guaranteed to be immutable.</p>
36   * @author Luc Maisonobe
37   */
38  public class FrameAlignedProvider 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 #FrameAlignedProvider(Rotation, Frame)
49       */
50      @DefaultDataContext
51      public FrameAlignedProvider(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 FrameAlignedProvider(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 FrameAlignedProvider(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.
82       *
83       * <p>This attitude provider returned by this method is designed to be as fast as
84       * possible for when attitude is irrelevant while still being a valid implementation
85       * of {@link AttitudeProvider}. To ensure good performance the specified attitude
86       * reference frame should be the same frame used for propagation so that computing the
87       * frame transformation is trivial.
88       *
89       * @param satelliteFrame with which the satellite is aligned.
90       * @return new attitude provider aligned with the given frame.
91       * @since 11.0
92       */
93      public static AttitudeProvider of(final Frame satelliteFrame) {
94          return new FrameAlignedProvider(satelliteFrame);
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public Attitude getAttitude(final PVCoordinatesProvider pvProv,
100                                 final AbsoluteDate date,
101                                 final Frame frame) {
102         final Transform t = frame.getTransformTo(satelliteFrame, date);
103         return new Attitude(date, frame, t.getRotation(), t.getRotationRate(), t.getRotationAcceleration());
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public <T extends CalculusFieldElement<T>>FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
109                                                                            final FieldAbsoluteDate<T> date,
110                                                                            final Frame frame) {
111         final FieldTransform<T> t = frame.getTransformTo(satelliteFrame, date);
112         return new FieldAttitude<>(date, frame, t.getRotation(), t.getRotationRate(), t.getRotationAcceleration());
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     public Rotation getAttitudeRotation(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) {
118         return frame.getStaticTransformTo(satelliteFrame, date).getRotation();
119     }
120 
121     /** {@inheritDoc} */
122     @Override
123     public <T extends CalculusFieldElement<T>> FieldRotation<T> getAttitudeRotation(final FieldPVCoordinatesProvider<T> pvProv,
124                                                                                     final FieldAbsoluteDate<T> date,
125                                                                                     final Frame frame) {
126         return frame.getStaticTransformTo(satelliteFrame, date).getRotation();
127     }
128 
129 }