OPMFile.java

  1. /* Copyright 2002-2020 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.files.ccsds;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.orekit.frames.Frame;
  23. import org.orekit.frames.LOFType;
  24. import org.orekit.orbits.CartesianOrbit;
  25. import org.orekit.orbits.KeplerianOrbit;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.PVCoordinates;

  29. /** This class gathers the informations present in the Orbital Parameter Message (OPM), and contains
  30.  * methods to generate {@link CartesianOrbit}, {@link KeplerianOrbit} or {@link SpacecraftState}.
  31.  * @author sports
  32.  * @since 6.1
  33.  */
  34. public class OPMFile extends OGMFile {

  35.     /** Meta-data. */
  36.     private final ODMMetaData metaData;

  37.     /** Position vector (m). */
  38.     private Vector3D position;

  39.     /** Velocity vector (m/s. */
  40.     private Vector3D velocity;

  41.     /** Maneuvers. */
  42.     private List<Maneuver> maneuvers;

  43.     /** Create a new OPM file object. */
  44.     OPMFile() {
  45.         metaData  = new ODMMetaData(this);
  46.         maneuvers = new ArrayList<Maneuver>();
  47.     }

  48.     /** Get the meta data.
  49.      * @return meta data
  50.      */
  51.     @Override
  52.     public ODMMetaData getMetaData() {
  53.         return metaData;
  54.     }

  55.     /** Get position vector.
  56.      * @return the position vector
  57.      */
  58.     public Vector3D getPosition() {
  59.         return position;
  60.     }

  61.     /** Set position vector.
  62.      * @param position the position vector to be set
  63.      */
  64.     void setPosition(final Vector3D position) {
  65.         this.position = position;
  66.     }

  67.     /** Get velocity vector.
  68.      * @return the velocity vector
  69.      */
  70.     public Vector3D getVelocity() {
  71.         return velocity;
  72.     }

  73.     /** Set velocity vector.
  74.      * @param velocity the velocity vector to be set
  75.      */
  76.     void setVelocity(final Vector3D velocity) {
  77.         this.velocity = velocity;
  78.     }

  79.     /** Get the number of maneuvers present in the OPM.
  80.      * @return the number of maneuvers
  81.      */
  82.     public int getNbManeuvers() {
  83.         return maneuvers.size();
  84.     }

  85.     /** Get a list of all maneuvers.
  86.      * @return unmodifiable list of all maneuvers.
  87.      */
  88.     public List<Maneuver> getManeuvers() {
  89.         return Collections.unmodifiableList(maneuvers);
  90.     }

  91.     /** Get a maneuver.
  92.      * @param index maneuver index, counting from 0
  93.      * @return maneuver
  94.      */
  95.     public Maneuver getManeuver(final int index) {
  96.         return maneuvers.get(index);
  97.     }

  98.     /** Add a maneuver.
  99.      * @param maneuver maneuver to be set
  100.      */
  101.     void addManeuver(final Maneuver maneuver) {
  102.         maneuvers.add(maneuver);
  103.     }

  104.     /** Get boolean testing whether the OPM contains at least one maneuver.
  105.      * @return true if OPM contains at least one maneuver
  106.      *         false otherwise */
  107.     public boolean getHasManeuver() {
  108.         return !maneuvers.isEmpty();
  109.     }

  110.     /** Get the comment for meta-data.
  111.      * @return comment for meta-data
  112.      */
  113.     public List<String> getMetaDataComment() {
  114.         return metaData.getComment();
  115.     }

  116.     /** Get the position/velocity coordinates contained in the OPM.
  117.      * @return the position/velocity coordinates contained in the OPM
  118.      */
  119.     public PVCoordinates getPVCoordinates() {
  120.         return new PVCoordinates(getPosition(), getVelocity());
  121.     }

  122.     /**
  123.      * Generate a {@link CartesianOrbit} from the OPM state vector data. If the reference frame is not
  124.      * pseudo-inertial, an exception is raised.
  125.      * @return the {@link CartesianOrbit} generated from the OPM information
  126.      */
  127.     public CartesianOrbit generateCartesianOrbit() {
  128.         setMuUsed();
  129.         return new CartesianOrbit(getPVCoordinates(), metaData.getFrame(), getEpoch(), getMuUsed());
  130.     }

  131.     /** Generate a {@link KeplerianOrbit} from the OPM Keplerian elements if hasKeplerianElements is true,
  132.      * or from the state vector data otherwise.
  133.      * If the reference frame is not pseudo-inertial, an exception is raised.
  134.      * @return the {@link KeplerianOrbit} generated from the OPM information
  135.      */
  136.     public KeplerianOrbit generateKeplerianOrbit() {
  137.         setMuUsed();
  138.         if (hasKeplerianElements()) {
  139.             return new KeplerianOrbit(getA(), getE(), getI(), getPa(), getRaan(), getAnomaly(),
  140.                                       getAnomalyType(), metaData.getFrame(), getEpoch(), getMuUsed());
  141.         } else {
  142.             return new KeplerianOrbit(getPVCoordinates(), metaData.getFrame(), getEpoch(), getMuUsed());
  143.         }
  144.     }

  145.     /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
  146.      *  Raises an exception if OPM doesn't contain spacecraft mass information.
  147.      * @return the spacecraft state of the OPM
  148.      */
  149.     public SpacecraftState generateSpacecraftState() {
  150.         return new SpacecraftState(generateCartesianOrbit(), getMass());
  151.     }

  152.     /** Maneuver in an OPM file.
  153.      */
  154.     public static class Maneuver {

  155.         /** Epoch ignition. */
  156.         private AbsoluteDate epochIgnition;

  157.         /** Coordinate system for velocity increment vector, for Local Orbital Frames. */
  158.         private LOFType refLofType;

  159.         /** Coordinate system for velocity increment vector, for absolute frames. */
  160.         private Frame refFrame;

  161.         /** Duration (value is 0 for impulsive maneuver). */
  162.         private double duration;

  163.         /** Mass change during maneuver (value is < 0). */
  164.         private double deltaMass;

  165.         /** Velocity increment. */
  166.         private Vector3D dV;

  167.         /** Maneuvers data comment, each string in the list corresponds to one line of comment. */
  168.         private List<String> comment;

  169.         /** Simple constructor.
  170.          */
  171.         public Maneuver() {
  172.             this.dV      = Vector3D.ZERO;
  173.             this.comment = Collections.emptyList();
  174.         }

  175.         /** Get epoch ignition.
  176.          * @return epoch ignition
  177.          */
  178.         public AbsoluteDate getEpochIgnition() {
  179.             return epochIgnition;
  180.         }

  181.         /** Set epoch ignition.
  182.          * @param epochIgnition epoch ignition
  183.          */
  184.         void setEpochIgnition(final AbsoluteDate epochIgnition) {
  185.             this.epochIgnition = epochIgnition;
  186.         }

  187.         /** Get coordinate system for velocity increment vector, for Local Orbital Frames.
  188.          * @return coordinate system for velocity increment vector, for Local Orbital Frames
  189.          */
  190.         public LOFType getRefLofType() {
  191.             return refLofType;
  192.         }

  193.         /** Set coordinate system for velocity increment vector, for Local Orbital Frames.
  194.          * @param refLofType coordinate system for velocity increment vector, for Local Orbital Frames
  195.          */
  196.         public void setRefLofType(final LOFType refLofType) {
  197.             this.refLofType = refLofType;
  198.             this.refFrame   = null;
  199.         }

  200.         /** Get Coordinate system for velocity increment vector, for absolute frames.
  201.          * @return coordinate system for velocity increment vector, for absolute frames
  202.          */
  203.         public Frame getRefFrame() {
  204.             return refFrame;
  205.         }

  206.         /** Set Coordinate system for velocity increment vector, for absolute frames.
  207.          * @param refFrame coordinate system for velocity increment vector, for absolute frames
  208.          */
  209.         public void setRefFrame(final Frame refFrame) {
  210.             this.refLofType = null;
  211.             this.refFrame   = refFrame;
  212.         }

  213.         /** Get duration (value is 0 for impulsive maneuver).
  214.          * @return duration (value is 0 for impulsive maneuver)
  215.          */
  216.         public double getDuration() {
  217.             return duration;
  218.         }

  219.         /** Set duration (value is 0 for impulsive maneuver).
  220.          * @param duration duration (value is 0 for impulsive maneuver)
  221.          */
  222.         public void setDuration(final double duration) {
  223.             this.duration = duration;
  224.         }

  225.         /** Get mass change during maneuver (value is &lt; 0).
  226.          * @return mass change during maneuver (value is &lt; 0)
  227.          */
  228.         public double getDeltaMass() {
  229.             return deltaMass;
  230.         }

  231.         /** Set mass change during maneuver (value is &lt; 0).
  232.          * @param deltaMass mass change during maneuver (value is &lt; 0)
  233.          */
  234.         public void setDeltaMass(final double deltaMass) {
  235.             this.deltaMass = deltaMass;
  236.         }

  237.         /** Get velocity increment.
  238.          * @return velocity increment
  239.          */
  240.         public Vector3D getDV() {
  241.             return dV;
  242.         }

  243.         /** Set velocity increment.
  244.          * @param dV velocity increment
  245.          */
  246.         public void setdV(final Vector3D dV) {
  247.             this.dV = dV;
  248.         }

  249.         /** Get the maneuvers data comment, each string in the list corresponds to one line of comment.
  250.          * @return maneuvers data comment, each string in the list corresponds to one line of comment
  251.          */
  252.         public List<String> getComment() {
  253.             return Collections.unmodifiableList(comment);
  254.         }

  255.         /** Set the maneuvers data comment, each string in the list corresponds to one line of comment.
  256.          * @param comment maneuvers data comment, each string in the list corresponds to one line of comment
  257.          */
  258.         public void setComment(final List<String> comment) {
  259.             this.comment = new ArrayList<String>(comment);
  260.         }

  261.     }

  262. }