OMMFile.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.Collections;
  20. import java.util.List;

  21. import org.apache.commons.math3.util.FastMath;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.files.general.OrbitFile;
  24. import org.orekit.orbits.CartesianOrbit;
  25. import org.orekit.orbits.KeplerianOrbit;
  26. import org.orekit.orbits.PositionAngle;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.analytical.tle.TLE;

  29. /**
  30.  * This class gathers the informations present in the Orbital Mean-Elements Message (OMM),
  31.  * and contains methods to generate a {@link CartesianOrbit}, a {@link KeplerianOrbit},
  32.  * a {@link SpacecraftState} and, eventually, a {@link TLE}.
  33.  * @author sports
  34.  * @since 6.1
  35.  */
  36. public class OMMFile extends OGMFile {

  37.     /** Meta-data. */
  38.     private final OMMMetaData metaData;

  39.     /** Mean motion (the Keplerian Mean motion in revolutions per day). To be used instead of semi-major
  40.      * axis if MEAN_ELEMENT_THEORY = SGP/SGP4. */
  41.     private double meanMotion;

  42.     /** Ephemeris Type, only required if MEAN_ELEMENT_THEORY = SGP/SGP4. Some sources suggest the coding for
  43.      * the EPHEMERIS_TYPE keyword: 1 = SGP, 2 = SGP4, 3 = SDP4, 4 = SGP8, 5 = SDP8. Default value = 0.
  44.      */
  45.     private int ephemerisType;

  46.     /** Classification Type, only required if MEAN_ELEMENT_THEORY = SGP/SGP4. Some sources suggest the
  47.      *  following coding for the CLASSIFICATION_TYPE keyword: U = unclassified, S = secret. Default value = U.
  48.      */
  49.     private char classificationType;

  50.     /** NORAD Catalog Number ("Satellite Number"), an integer of up to nine digits. */
  51.     private Integer noradID;

  52.     /** Element set number for this satellite, only required if MEAN_ELEMENT_THEORY = SGP/SGP4.
  53.      * Normally incremented sequentially, but may be out of sync if it is generated from a backup source.
  54.      * Used to distinguish different TLEs, and therefore only meaningful if TLE based data is being exchanged. */
  55.     private String elementSetNo;

  56.     /** Revolution Number, only required if MEAN_ELEMENT_THEORY = SGP/SGP4. */
  57.     private int revAtEpoch;

  58.     /** SGP/SGP4 drag-like coefficient (in units 1/[Earth radii]), only required if MEAN_ELEMENT_THEORY = SGP/SGP4. */
  59.     private Double bStar;

  60.     /** First Time Derivative of the Mean Motion, only required if MEAN_ELEMENT_THEORY = SGP. */
  61.     private Double meanMotionDot;

  62.     /** Second Time Derivative of Mean Motion, only required if MEAN_ELEMENT_THEORY = SGP. */
  63.     private Double meanMotionDotDot;

  64.     /** TLE related parameters comments. The list contains a string for each line of comment. */
  65.     private List<String> dataTleRelatedParametersComment;

  66.     /** Create a new OMM file object. */
  67.     OMMFile() {
  68.         metaData = new OMMMetaData(this);
  69.     };

  70.     /** Get the meta data.
  71.      * @return meta data
  72.      */
  73.     @Override
  74.     public OMMMetaData getMetaData() {
  75.         return metaData;
  76.     }

  77.     /** Get the orbit mean motion.
  78.      * @return the orbit mean motion
  79.      */
  80.     public double getMeanMotion() {
  81.         return meanMotion;
  82.     }

  83.     /** Set the orbit mean motion.
  84.      * @param motion the mean motion to be set
  85.      */
  86.     void setMeanMotion(final double motion) {
  87.         this.meanMotion = motion;
  88.     }

  89.     /** Get the ephemeris type.
  90.      * @return the ephemerisType
  91.      */
  92.     public int getEphemerisType() {
  93.         return ephemerisType;
  94.     }

  95.     /** Set the ephemeris type.
  96.      * @param ephemerisType the ephemeris type to be set
  97.      */
  98.     void setEphemerisType(final int ephemerisType) {
  99.         this.ephemerisType = ephemerisType;
  100.     }

  101.     /** Get the classification type.
  102.      * @return the classificationType
  103.      */
  104.     public char getClassificationType() {
  105.         return classificationType;
  106.     }

  107.     /** Set the classification type.
  108.      * @param classificationType the classification type to be set
  109.      */
  110.     void setClassificationType(final char classificationType) {
  111.         this.classificationType = classificationType;
  112.     }

  113.     /** Get the NORAD Catalog Number ("Satellite Number").
  114.      * @return the NORAD Catalog Number
  115.      */
  116.     public Integer getNoradID() {
  117.         return noradID;
  118.     }

  119.     /** Set the NORAD Catalog Number ("Satellite Number").
  120.      * @param noradID the element set number to be set
  121.      */
  122.     void setNoradID(final Integer noradID) {
  123.         this.noradID = noradID;
  124.     }

  125.     /** Get the element set number for this satellite.
  126.      * @return the element set number for this satellite
  127.      */
  128.     public String getElementSetNumber() {
  129.         return elementSetNo;
  130.     }

  131.     /** Set the element set number for this satellite.
  132.      * @param elementSetNo the element set number to be set
  133.      */
  134.     void setElementSetNo(final String elementSetNo) {
  135.         this.elementSetNo = elementSetNo;
  136.     }

  137.     /** Get the revolution rumber.
  138.      * @return the revolution rumber
  139.      */
  140.     public int getRevAtEpoch() {
  141.         return revAtEpoch;
  142.     }

  143.     /** Set the revolution rumber.
  144.      * @param revAtEpoch the Revolution Number to be set
  145.      */
  146.     void setRevAtEpoch(final int revAtEpoch) {
  147.         this.revAtEpoch = revAtEpoch;
  148.     }

  149.     /** Get the SGP/SGP4 drag-like coefficient.
  150.      * @return the SGP/SGP4 drag-like coefficient
  151.      */
  152.     public double getBStar() {
  153.         return bStar;
  154.     }

  155.     /** Set the SGP/SGP4 drag-like coefficient.
  156.      * @param bStar the SGP/SGP4 drag-like coefficient to be set
  157.      */
  158.     void setbStar(final double bStar) {
  159.         this.bStar = bStar;
  160.     }

  161.     /** Get the first time derivative of the mean motion.
  162.      * @return the first time derivative of the mean motion
  163.      */
  164.     public double getMeanMotionDot() {
  165.         return meanMotionDot;
  166.     }

  167.     /** Set the first time derivative of the mean motion.
  168.      * @param meanMotionDot the first time derivative of the mean motion to be set
  169.      */
  170.     void setMeanMotionDot(final double meanMotionDot) {
  171.         this.meanMotionDot = meanMotionDot;
  172.     }

  173.     /** Get the second time derivative of the mean motion.
  174.      * @return the second time derivative of the mean motion
  175.      */
  176.     public double getMeanMotionDotDot() {
  177.         return meanMotionDotDot;
  178.     }

  179.     /** Set the second time derivative of the mean motion.
  180.      * @param meanMotionDotDot the second time derivative of the mean motion to be set
  181.      */
  182.     void setMeanMotionDotDot(final double meanMotionDotDot) {
  183.         this.meanMotionDotDot = meanMotionDotDot;
  184.     }

  185.     /** Get the comment for TLE related parameters.
  186.      * @return comment for TLE related parameters
  187.      */
  188.     public List<String> getTLERelatedParametersComment() {
  189.         return Collections.unmodifiableList(dataTleRelatedParametersComment);
  190.     }

  191.     /** Set the comment for TLE related parameters.
  192.      * @param comment comment to set
  193.      */
  194.     void setTLERelatedParametersComment(final List<String> comment) {
  195.         dataTleRelatedParametersComment = new ArrayList<String>(comment);
  196.     }

  197.     /** {@inheritDoc} */
  198.     @Override
  199.     public String getCoordinateSystem() {
  200.         return metaData.getFrame().toString();
  201.     }

  202.     /** {@inheritDoc} */
  203.     @Override
  204.     public OrbitFile.TimeSystem getTimeSystem() {
  205.         return metaData.getTimeSystem();
  206.     }

  207.     /** Generate a {@link KeplerianOrbit} based on the OMM mean keplerian elements.
  208.      * If the reference frame is not pseudo-inertial, an exception is raised.
  209.      * @return the {@link KeplerianOrbit} generated from the OMM information
  210.      * @exception OrekitException if the reference frame is not pseudo-inertial or if the central body
  211.      * gravitational coefficient cannot be retrieved from the OMM
  212.      */
  213.     public KeplerianOrbit generateKeplerianOrbit() throws OrekitException {
  214.         setMuUsed();
  215.         final double a;
  216.         if (Double.isNaN(getA())) {
  217.             a = FastMath.cbrt(getMuUsed() / (meanMotion * meanMotion));
  218.         } else {
  219.             a = getA();
  220.         }
  221.         return new KeplerianOrbit(a, getE(), getI(), getPa(), getRaan(), getAnomaly(),
  222.                                   PositionAngle.MEAN, metaData.getFrame(), getEpoch(), getMuUsed());
  223.     }

  224.     /** Generate a {@link CartesianOrbit} from the {@link KeplerianOrbit}.
  225.      * @return the {@link CartesianOrbit} generated from the OPM information
  226.      * @throws OrekitException if the Keplerian Orbit cannot be generated
  227.      */
  228.     public CartesianOrbit generateCartesianOrbit() throws OrekitException {
  229.         return new CartesianOrbit(generateKeplerianOrbit());
  230.     }

  231.     /** Generate spacecraft state from the {@link KeplerianOrbit} generated by generateKeplerianOrbit.
  232.      *  Raises an exception if OMM doesn't contain spacecraft mass information.
  233.      * @return the spacecraft state of the OMM
  234.      * @exception OrekitException if there is no spacecraft mass associated with the OMM
  235.      */
  236.     public SpacecraftState generateSpacecraftState()
  237.         throws OrekitException {
  238.         return new SpacecraftState(generateKeplerianOrbit(), getMass());
  239.     }

  240.     /** Generate TLE from OMM file. Launch Year, Launch Day and Launch Piece are not present in the
  241.      * OMM file, they have to be set manually by the user with the AdditionalData static class.
  242.      * @return the tle
  243.      */
  244.     public TLE generateTLE() {
  245.         return new TLE(noradID, classificationType,
  246.                        metaData.getLaunchYear(), metaData.getLaunchNumber(), metaData.getLaunchPiece(),
  247.                        ephemerisType, Integer.parseInt(elementSetNo), getEpoch(),
  248.                        meanMotion, meanMotionDot, meanMotionDotDot,
  249.                        getE(), getI(), getPa(), getRaan(), getAnomaly(), revAtEpoch, bStar);
  250.     }

  251.     public static class OMMMetaData extends ODMMetaData {

  252.         /** Description of the Mean Element Theory. Indicates the proper method to employ
  253.          * to propagate the state. */
  254.         private String meanElementTheory;

  255.         /** Create a new meta-data.
  256.          * @param ommFile OMM file to which these meta-data belongs
  257.          */
  258.         OMMMetaData(final OMMFile ommFile) {
  259.             super(ommFile);
  260.         }

  261.         /** Get the description of the Mean Element Theory.
  262.          * @return the mean element theory
  263.          */
  264.         public String getMeanElementTheory() {
  265.             return meanElementTheory;
  266.         }

  267.         /** Set the description of the Mean Element Theory.
  268.          * @param meanElementTheory the mean element theory to be set
  269.          */
  270.         void setMeanElementTheory(final String meanElementTheory) {
  271.             this.meanElementTheory = meanElementTheory;
  272.         }

  273.     }

  274. }