AttitudeStateHistory.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  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.files.ccsds.ndm.adm.acm;

  18. import java.util.Collections;
  19. import java.util.List;
  20. import java.util.stream.Collectors;

  21. import org.orekit.attitudes.BoundedAttitudeProvider;
  22. import org.orekit.attitudes.TabulatedProvider;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.files.general.AttitudeEphemerisFile;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.AngularDerivativesFilter;
  29. import org.orekit.utils.TimeStampedAngularCoordinates;

  30. /** Attitude state history.
  31.  * @author Luc Maisonobe
  32.  * @since 12.0
  33.  */
  34. public class AttitudeStateHistory implements AttitudeEphemerisFile.AttitudeEphemerisSegment<TimeStampedAngularCoordinates> {

  35.     /** Metadata. */
  36.     private final AttitudeStateHistoryMetadata metadata;

  37.     /** Trajectory states. */
  38.     private final List<AttitudeState> states;

  39.     /** Simple constructor.
  40.      * @param metadata metadata
  41.      * @param states attitude states
  42.      */
  43.     public AttitudeStateHistory(final AttitudeStateHistoryMetadata metadata,
  44.                                 final List<AttitudeState> states) {
  45.         this.metadata = metadata;
  46.         this.states   = states;
  47.     }

  48.     /** Get metadata.
  49.      * @return metadata
  50.      */
  51.     public AttitudeStateHistoryMetadata getMetadata() {
  52.         return metadata;
  53.     }

  54.     /** Get the attitude states.
  55.      * @return attitude states
  56.      */
  57.     public List<AttitudeState> getAttitudeStates() {
  58.         return Collections.unmodifiableList(states);
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public Frame getReferenceFrame() {
  63.         final Frame frame = metadata.getEndpoints().getFrameA().asFrame();
  64.         if (frame == null) {
  65.             throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME,
  66.                                       metadata.getEndpoints().getFrameA().getName());
  67.         }
  68.         return frame;
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public int getInterpolationSamples() {
  73.         return 1;
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public String getInterpolationMethod() {
  78.         return "linear";
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public AngularDerivativesFilter getAvailableDerivatives() {
  83.         return states.get(0).getAvailableDerivatives();
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public BoundedAttitudeProvider getAttitudeProvider() {
  88.         return new TabulatedProvider(getAngularCoordinates(), getInterpolationSamples(),
  89.                                      getAvailableDerivatives(), getStart(), getStop(),
  90.                                      getMetadata().getEndpoints());
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public AbsoluteDate getStart() {
  95.         return states.get(0).getDate();
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public AbsoluteDate getStop() {
  100.         return states.get(states.size() - 1).getDate();
  101.     }

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     public List<TimeStampedAngularCoordinates> getAngularCoordinates() {
  105.         return states.stream().map(os -> os.toAngular(metadata.getEulerRotSeq())).collect(Collectors.toList());
  106.     }

  107. }