TabulatedLofOffset.java

  1. /* Copyright 2002-2023 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. import java.util.List;
  19. import java.util.stream.Collectors;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.frames.FieldTransform;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.frames.LOF;
  26. import org.orekit.frames.Transform;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.time.FieldTimeInterpolator;
  30. import org.orekit.time.TimeInterpolator;
  31. import org.orekit.utils.AngularDerivativesFilter;
  32. import org.orekit.utils.FieldPVCoordinates;
  33. import org.orekit.utils.FieldPVCoordinatesProvider;
  34. import org.orekit.utils.ImmutableTimeStampedCache;
  35. import org.orekit.utils.PVCoordinates;
  36. import org.orekit.utils.PVCoordinatesProvider;
  37. import org.orekit.utils.TimeStampedAngularCoordinates;
  38. import org.orekit.utils.TimeStampedAngularCoordinatesHermiteInterpolator;
  39. import org.orekit.utils.TimeStampedFieldAngularCoordinates;
  40. import org.orekit.utils.TimeStampedFieldAngularCoordinatesHermiteInterpolator;

  41. /**
  42.  * This class handles an attitude provider interpolating from a predefined table
  43.  * containing offsets from a Local Orbital Frame.
  44.  * <p>Instances of this class are guaranteed to be immutable.</p>
  45.  * @see LofOffset
  46.  * @see TabulatedProvider
  47.  * @author Luc Maisonobe
  48.  * @since 7.1
  49.  */
  50. public class TabulatedLofOffset implements BoundedAttitudeProvider {

  51.     /** Inertial frame with respect to which orbit should be computed. */
  52.     private final Frame inertialFrame;

  53.     /** Local Orbital Frame. */
  54.     private final LOF type;

  55.     /** Cached attitude table. */
  56.     private final transient ImmutableTimeStampedCache<? extends TimeStampedAngularCoordinates> table;

  57.     /** Filter for derivatives from the sample to use in interpolation. */
  58.     private final AngularDerivativesFilter filter;

  59.     /** First date of the range. */
  60.     private final AbsoluteDate minDate;

  61.     /** Last date of the range. */
  62.     private final AbsoluteDate maxDate;

  63.     /** Creates new instance.
  64.      * <p>
  65.      * This constructor uses the first and last point samples as the min and max dates.
  66.      * </p>
  67.      * @param inertialFrame inertial frame with respect to which orbit should be computed
  68.      * @param lof local orbital frame
  69.      * @param table tabulated attitudes
  70.      * @param n number of attitude to use for interpolation
  71.      * @param filter filter for derivatives from the sample to use in interpolation
  72.      */
  73.     public TabulatedLofOffset(final Frame inertialFrame, final LOF lof,
  74.                               final List<? extends TimeStampedAngularCoordinates> table,
  75.                               final int n, final AngularDerivativesFilter filter) {
  76.         this(inertialFrame, lof, table, n, filter, table.get(0).getDate(), table.get(table.size() - 1).getDate());
  77.     }

  78.     /** Creates new instance.
  79.      * @param inertialFrame inertial frame with respect to which orbit should be computed
  80.      * @param lof local orbital frame
  81.      * @param table tabulated attitudes
  82.      * @param n number of attitude to use for interpolation
  83.      * @param minDate min date to use
  84.      * @param maxDate max date to use
  85.      * @param filter filter for derivatives from the sample to use in interpolation
  86.      * @since 11.0
  87.      */
  88.     public TabulatedLofOffset(final Frame inertialFrame, final LOF lof,
  89.                               final List<? extends TimeStampedAngularCoordinates> table,
  90.                               final int n, final AngularDerivativesFilter filter,
  91.                               final AbsoluteDate minDate, final AbsoluteDate maxDate) {
  92.         if (!inertialFrame.isPseudoInertial()) {
  93.             throw new OrekitException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME,
  94.                                       inertialFrame.getName());
  95.         }
  96.         this.inertialFrame = inertialFrame;
  97.         this.type          = lof;
  98.         this.table         = new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(n, table);
  99.         this.filter        = filter;
  100.         this.minDate       = minDate;
  101.         this.maxDate       = maxDate;
  102.     }

  103.     /** Get an unmodifiable view of the tabulated attitudes.
  104.      * @return unmodifiable view of the tabulated attitudes
  105.      */
  106.     public List<? extends TimeStampedAngularCoordinates> getTable() {
  107.         return table.getAll();
  108.     }

  109.     /** {@inheritDoc} */
  110.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  111.                                 final AbsoluteDate date, final Frame frame) {

  112.         // get attitudes sample on which interpolation will be performed
  113.         final List<TimeStampedAngularCoordinates> sample = table.getNeighbors(date).collect(Collectors.toList());

  114.         // create interpolator
  115.         final TimeInterpolator<TimeStampedAngularCoordinates> interpolator =
  116.                 new TimeStampedAngularCoordinatesHermiteInterpolator(sample.size(), filter);

  117.         // interpolate
  118.         final TimeStampedAngularCoordinates interpolated = interpolator.interpolate(date, sample);

  119.         // construction of the local orbital frame, using PV from inertial frame
  120.         final PVCoordinates pv = pvProv.getPVCoordinates(date, inertialFrame);
  121.         final Transform inertialToLof = type.transformFromInertial(date, pv);

  122.         // take into account the specified start frame (which may not be an inertial one)
  123.         final Transform frameToInertial = frame.getTransformTo(inertialFrame, date);
  124.         final Transform frameToLof      = new Transform(date, frameToInertial, inertialToLof);

  125.         // compose with interpolated rotation
  126.         return new Attitude(date, frame,
  127.                             interpolated.addOffset(frameToLof.getAngular()));
  128.     }

  129.     /** {@inheritDoc} */
  130.     public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  131.                                                                         final FieldAbsoluteDate<T> date,
  132.                                                                         final Frame frame) {

  133.         // get attitudes sample on which interpolation will be performed
  134.         final List<TimeStampedFieldAngularCoordinates<T>> sample =
  135.                         table.
  136.                         getNeighbors(date.toAbsoluteDate()).
  137.                         map(ac -> new TimeStampedFieldAngularCoordinates<>(date.getField(), ac)).
  138.                         collect(Collectors.toList());

  139.         // create interpolator
  140.         final FieldTimeInterpolator<TimeStampedFieldAngularCoordinates<T>, T> interpolator =
  141.                 new TimeStampedFieldAngularCoordinatesHermiteInterpolator<>(sample.size(), filter);

  142.         // interpolate
  143.         final TimeStampedFieldAngularCoordinates<T> interpolated = interpolator.interpolate(date, sample);

  144.         // construction of the local orbital frame, using PV from inertial frame
  145.         final FieldPVCoordinates<T> pv = pvProv.getPVCoordinates(date, inertialFrame);
  146.         final FieldTransform<T> inertialToLof = type.transformFromInertial(date, pv);

  147.         // take into account the specified start frame (which may not be an inertial one)
  148.         final FieldTransform<T> frameToInertial = frame.getTransformTo(inertialFrame, date);
  149.         final FieldTransform<T> frameToLof      = new FieldTransform<>(date, frameToInertial, inertialToLof);

  150.         // compose with interpolated rotation
  151.         return new FieldAttitude<>(date, frame,
  152.                                    interpolated.addOffset(frameToLof.getAngular()));
  153.     }

  154.     /** {@inheritDoc} */
  155.     public AbsoluteDate getMinDate() {
  156.         return minDate;
  157.     }

  158.     /** {@inheritDoc} */
  159.     public AbsoluteDate getMaxDate() {
  160.         return maxDate;
  161.     }

  162. }