OPMFile.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.frames.LOFType;
  25. import org.orekit.orbits.CartesianOrbit;
  26. import org.orekit.orbits.KeplerianOrbit;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.utils.PVCoordinates;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  123.     /**
  124.      * Generate a {@link CartesianOrbit} from the OPM state vector data. If the reference frame is not
  125.      * pseudo-inertial, an exception is raised.
  126.      * @return the {@link CartesianOrbit} generated from the OPM information
  127.      * @exception OrekitException if the reference frame is not pseudo-inertial or if the central body
  128.      * gravitational coefficient cannot be retrieved from the OPM
  129.      */
  130.     public CartesianOrbit generateCartesianOrbit()
  131.         throws OrekitException {
  132.         setMuUsed();
  133.         return new CartesianOrbit(getPVCoordinates(), metaData.getFrame(), getEpoch(), getMuUsed());
  134.     }

  135.     /** Generate a {@link KeplerianOrbit} from the OPM Keplerian elements if hasKeplerianElements is true,
  136.      * or from the state vector data otherwise.
  137.      * If the reference frame is not pseudo-inertial, an exception is raised.
  138.      * @return the {@link KeplerianOrbit} generated from the OPM information
  139.      * @exception OrekitException if the reference frame is not pseudo-inertial or if the central body
  140.      * gravitational coefficient cannot be retrieved from the OPM
  141.      */
  142.     public KeplerianOrbit generateKeplerianOrbit() throws OrekitException {
  143.         setMuUsed();
  144.         if (hasKeplerianElements()) {
  145.             return new KeplerianOrbit(getA(), getE(), getI(), getPa(), getRaan(), getAnomaly(),
  146.                                       getAnomalyType(), metaData.getFrame(), getEpoch(), getMuUsed());
  147.         } else {
  148.             return new KeplerianOrbit(getPVCoordinates(), metaData.getFrame(), getEpoch(), getMuUsed());
  149.         }
  150.     }

  151.     /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
  152.      *  Raises an exception if OPM doesn't contain spacecraft mass information.
  153.      * @return the spacecraft state of the OPM
  154.      * @exception OrekitException if there is no spacecraft mass associated with the OPM
  155.      */
  156.     public SpacecraftState generateSpacecraftState()
  157.         throws OrekitException {
  158.         return new SpacecraftState(generateCartesianOrbit(), getMass());
  159.     }

  160.     /** Maneuver in an OPM file.
  161.      */
  162.     public static class Maneuver {

  163.         /** Epoch ignition. */
  164.         private AbsoluteDate epochIgnition;

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

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

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

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

  173.         /** Velocity increment. */
  174.         private Vector3D dV;

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

  177.         /** Simple constructor.
  178.          */
  179.         public Maneuver() {
  180.             this.dV      = Vector3D.ZERO;
  181.             this.comment = Collections.emptyList();
  182.         }

  183.         /** Get epoch ignition.
  184.          * @return epoch ignition
  185.          */
  186.         public AbsoluteDate getEpochIgnition() {
  187.             return epochIgnition;
  188.         }

  189.         /** Set epoch ignition.
  190.          * @param epochIgnition epoch ignition
  191.          */
  192.         void setEpochIgnition(final AbsoluteDate epochIgnition) {
  193.             this.epochIgnition = epochIgnition;
  194.         }

  195.         /** Get coordinate system for velocity increment vector, for Local Orbital Frames.
  196.          * @return coordinate system for velocity increment vector, for Local Orbital Frames
  197.          */
  198.         public LOFType getRefLofType() {
  199.             return refLofType;
  200.         }

  201.         /** Set coordinate system for velocity increment vector, for Local Orbital Frames.
  202.          * @param refLofType coordinate system for velocity increment vector, for Local Orbital Frames
  203.          */
  204.         public void setRefLofType(final LOFType refLofType) {
  205.             this.refLofType = refLofType;
  206.             this.refFrame   = null;
  207.         }

  208.         /** Get Coordinate system for velocity increment vector, for absolute frames.
  209.          * @return coordinate system for velocity increment vector, for absolute frames
  210.          */
  211.         public Frame getRefFrame() {
  212.             return refFrame;
  213.         }

  214.         /** Set Coordinate system for velocity increment vector, for absolute frames.
  215.          * @param refFrame coordinate system for velocity increment vector, for absolute frames
  216.          */
  217.         public void setRefFrame(final Frame refFrame) {
  218.             this.refLofType = null;
  219.             this.refFrame   = refFrame;
  220.         }

  221.         /** Get duration (value is 0 for impulsive maneuver).
  222.          * @return duration (value is 0 for impulsive maneuver)
  223.          */
  224.         public double getDuration() {
  225.             return duration;
  226.         }

  227.         /** Set duration (value is 0 for impulsive maneuver).
  228.          * @param duration duration (value is 0 for impulsive maneuver)
  229.          */
  230.         public void setDuration(final double duration) {
  231.             this.duration = duration;
  232.         }

  233.         /** Get mass change during maneuver (value is &lt; 0).
  234.          * @return mass change during maneuver (value is &lt; 0)
  235.          */
  236.         public double getDeltaMass() {
  237.             return deltaMass;
  238.         }

  239.         /** Set mass change during maneuver (value is &lt; 0).
  240.          * @param deltaMass mass change during maneuver (value is &lt; 0)
  241.          */
  242.         public void setDeltaMass(final double deltaMass) {
  243.             this.deltaMass = deltaMass;
  244.         }

  245.         /** Get velocity increment.
  246.          * @return velocity increment
  247.          */
  248.         public Vector3D getDV() {
  249.             return dV;
  250.         }

  251.         /** Set velocity increment.
  252.          * @param dV velocity increment
  253.          */
  254.         public void setdV(final Vector3D dV) {
  255.             this.dV = dV;
  256.         }

  257.         /** Get the maneuvers data comment, each string in the list corresponds to one line of comment.
  258.          * @return maneuvers data comment, each string in the list corresponds to one line of comment
  259.          */
  260.         public List<String> getComment() {
  261.             return Collections.unmodifiableList(comment);
  262.         }

  263.         /** Set the maneuvers data comment, each string in the list corresponds to one line of comment.
  264.          * @param comment maneuvers data comment, each string in the list corresponds to one line of comment
  265.          */
  266.         public void setComment(final List<String> comment) {
  267.             this.comment = new ArrayList<String>(comment);
  268.         }

  269.     }

  270. }