OPMFile.java

  1. /* Copyright 2002-2013 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.Arrays;
  20. import java.util.Collections;
  21. import java.util.List;

  22. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.files.general.OrbitFile;
  25. import org.orekit.files.general.SatelliteTimeCoordinate;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.frames.LOFType;
  28. import org.orekit.orbits.CartesianOrbit;
  29. import org.orekit.orbits.KeplerianOrbit;
  30. import org.orekit.propagation.SpacecraftState;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.utils.PVCoordinates;

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

  39.     /** Meta-data. */
  40.     private final ODMMetaData metaData;

  41.     /** Position vector (m). */
  42.     private Vector3D position;

  43.     /** Velocity vector (m/s. */
  44.     private Vector3D velocity;

  45.     /** Maneuvers. */
  46.     private List<Maneuver> maneuvers;

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

  52.     /** Get the meta data.
  53.      * @return meta data
  54.      */
  55.     @Override
  56.     public ODMMetaData getMetaData() {
  57.         return metaData;
  58.     }

  59.     /** Get position vector.
  60.      * @return the position vector
  61.      */
  62.     public Vector3D getPosition() {
  63.         return position;
  64.     }

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

  71.     /** Get velocity vector.
  72.      * @return the velocity vector
  73.      */
  74.     public Vector3D getVelocity() {
  75.         return velocity;
  76.     }

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

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

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

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

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

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

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

  120.     /** {@inheritDoc} */
  121.     @Override
  122.     public List<SatelliteTimeCoordinate> getSatelliteCoordinates(final String satId) {
  123.         if (getMetaData().getObjectID().equals(satId)) {
  124.             return Arrays.asList(new SatelliteTimeCoordinate(getEpoch(), getPVCoordinates()));
  125.         } else {
  126.             return Collections.emptyList();
  127.         }
  128.     }

  129.     /** Get the {@link SatelliteTimeCoordinate} of the OPM.
  130.      * @return the {@link SatelliteTimeCoordinate}
  131.      */
  132.     public SatelliteTimeCoordinate getSatelliteCoordinatesOPM() {
  133.         return new SatelliteTimeCoordinate(getEpoch(), getPVCoordinates());
  134.     }

  135.     /** Get the position/velocity coordinates contained in the OPM.
  136.      * @return the position/velocity coordinates contained in the OPM
  137.      */
  138.     public PVCoordinates getPVCoordinates() {
  139.         return new PVCoordinates(getPosition(), getVelocity());
  140.     }

  141.     /** {@inheritDoc} */
  142.     @Override
  143.     public String getCoordinateSystem() {
  144.         return metaData.getFrame().toString();
  145.     }

  146.     /** {@inheritDoc} */
  147.     @Override
  148.     public OrbitFile.TimeSystem getTimeSystem() {
  149.         return metaData.getTimeSystem();
  150.     }

  151.     /**
  152.      * Generate a {@link CartesianOrbit} from the OPM state vector data. If the reference frame is not
  153.      * pseudo-inertial, an exception is raised.
  154.      * @return the {@link CartesianOrbit} generated from the OPM information
  155.      * @exception OrekitException if the reference frame is not pseudo-inertial or if the central body
  156.      * gravitational coefficient cannot be retrieved from the OPM
  157.      */
  158.     public CartesianOrbit generateCartesianOrbit()
  159.         throws OrekitException {
  160.         setMuUsed();
  161.         return new CartesianOrbit(getPVCoordinates(), metaData.getFrame(), getEpoch(), getMuUsed());
  162.     }

  163.     /** Generate a {@link KeplerianOrbit} from the OPM keplerian elements if hasKeplerianElements is true,
  164.      * or from the state vector data otherwise.
  165.      * If the reference frame is not pseudo-inertial, an exception is raised.
  166.      * @return the {@link KeplerianOrbit} generated from the OPM information
  167.      * @exception OrekitException if the reference frame is not pseudo-inertial or if the central body
  168.      * gravitational coefficient cannot be retrieved from the OPM
  169.      */
  170.     public KeplerianOrbit generateKeplerianOrbit() throws OrekitException {
  171.         setMuUsed();
  172.         if (hasKeplerianElements()) {
  173.             return new KeplerianOrbit(getA(), getE(), getI(), getPa(), getRaan(), getAnomaly(),
  174.                                       getAnomalyType(), metaData.getFrame(), getEpoch(), getMuUsed());
  175.         } else {
  176.             return new KeplerianOrbit(getPVCoordinates(), metaData.getFrame(), getEpoch(), getMuUsed());
  177.         }
  178.     }

  179.     /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
  180.      *  Raises an exception if OPM doesn't contain spacecraft mass information.
  181.      * @return the spacecraft state of the OPM
  182.      * @exception OrekitException if there is no spacecraft mass associated with the OPM
  183.      */
  184.     public SpacecraftState generateSpacecraftState()
  185.         throws OrekitException {
  186.         return new SpacecraftState(generateCartesianOrbit(), getMass());
  187.     }

  188.     /** Maneuver in an OPM file.
  189.      */
  190.     public static class Maneuver {

  191.         /** Epoch ignition. */
  192.         private AbsoluteDate epochIgnition;

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

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

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

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

  201.         /** Velocity increment. */
  202.         private Vector3D dV;

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

  205.         /** Simple constructor.
  206.          */
  207.         public Maneuver() {
  208.             this.dV      = Vector3D.ZERO;
  209.             this.comment = Collections.emptyList();
  210.         }

  211.         /** Get epoch ignition.
  212.          * @return epoch ignition
  213.          */
  214.         public AbsoluteDate getEpochIgnition() {
  215.             return epochIgnition;
  216.         }

  217.         /** Set epoch ignition.
  218.          * @param epochIgnition epoch ignition
  219.          */
  220.         void setEpochIgnition(final AbsoluteDate epochIgnition) {
  221.             this.epochIgnition = epochIgnition;
  222.         }

  223.         /** Get coordinate system for velocity increment vector, for Local Orbital Frames.
  224.          * @return coordinate system for velocity increment vector, for Local Orbital Frames
  225.          */
  226.         public LOFType getRefLofType() {
  227.             return refLofType;
  228.         }

  229.         /** Set coordinate system for velocity increment vector, for Local Orbital Frames.
  230.          * @param refLofType coordinate system for velocity increment vector, for Local Orbital Frames
  231.          */
  232.         public void setRefLofType(final LOFType refLofType) {
  233.             this.refLofType = refLofType;
  234.             this.refFrame   = null;
  235.         }

  236.         /** Get Coordinate system for velocity increment vector, for absolute frames.
  237.          * @return coordinate system for velocity increment vector, for absolute frames
  238.          */
  239.         public Frame getRefFrame() {
  240.             return refFrame;
  241.         }

  242.         /** Set Coordinate system for velocity increment vector, for absolute frames.
  243.          * @param refFrame coordinate system for velocity increment vector, for absolute frames
  244.          */
  245.         public void setRefFrame(final Frame refFrame) {
  246.             this.refLofType = null;
  247.             this.refFrame   = refFrame;
  248.         }

  249.         /** Get duration (value is 0 for impulsive maneuver).
  250.          * @return duration (value is 0 for impulsive maneuver)
  251.          */
  252.         public double getDuration() {
  253.             return duration;
  254.         }

  255.         /** Set duration (value is 0 for impulsive maneuver).
  256.          * @param duration duration (value is 0 for impulsive maneuver)
  257.          */
  258.         public void setDuration(final double duration) {
  259.             this.duration = duration;
  260.         }

  261.         /** Get mass change during maneuver (value is < 0).
  262.          * @return mass change during maneuver (value is < 0)
  263.          */
  264.         public double getDeltaMass() {
  265.             return deltaMass;
  266.         }

  267.         /** Set mass change during maneuver (value is < 0).
  268.          * @param deltaMass mass change during maneuver (value is < 0)
  269.          */
  270.         public void setDeltaMass(final double deltaMass) {
  271.             this.deltaMass = deltaMass;
  272.         }

  273.         /** Get velocity increment.
  274.          * @return velocity increment
  275.          */
  276.         public Vector3D getDV() {
  277.             return dV;
  278.         }

  279.         /** Set velocity increment.
  280.          * @param dV velocity increment
  281.          */
  282.         public void setdV(final Vector3D dV) {
  283.             this.dV = dV;
  284.         }

  285.         /** Get the maneuvers data comment, each string in the list corresponds to one line of comment.
  286.          * @return maneuvers data comment, each string in the list corresponds to one line of comment
  287.          */
  288.         public List<String> getComment() {
  289.             return Collections.unmodifiableList(comment);
  290.         }

  291.         /** Set the maneuvers data comment, each string in the list corresponds to one line of comment.
  292.          * @param comment maneuvers data comment, each string in the list corresponds to one line of comment
  293.          */
  294.         public void setComment(final List<String> comment) {
  295.             this.comment = new ArrayList<String>(comment);
  296.         }

  297.     }

  298. }